* \param hostlen The maximum length of \a host.
* \param port To return the port number (if any) of \a url.
*
- * \return Pointer to \a host, or NULL if failed.
- * If NULL is returned, \a host and \a portnum are undefined. If no
- * port number was present in \a url, \a portnum is set to -1.
+ * \return Pointer to \a host, or \p NULL if failed. If \p NULL is returned,
+ * \a host and \a port are undefined. If no port number was present in \a url,
+ * \a port is set to -1.
*
* \sa RFC 3986, 3.2.2/3.2.3
*/
if (*o++ != ']' || (*o != '\0' && *o != ':'))
goto failed;
} else {
- for (; (*c = *o == ':'? '\0' : *o); c++, o++)
- if (c == end)
+ for (; (*c = *o == ':'? '\0' : *o); c++, o++) {
+ if (c == end && o[1])
goto failed;
+ }
}
if (*o == ':')
if (para_atoi32(++o, port) < 0 ||
*port < 0 || *port > 0xffff)
goto failed;
-
if (host_string_ok(host))
return host;
failed:
struct list_head sockopts;
};
+/**
+ * Allocate and initialize a flowopt queue.
+ *
+ * \return A new structure to be passed to \ref flowopt_add(). It is
+ * automatically deallocated in \ref makesock().
+ */
struct flowopts *flowopt_new(void)
{
struct flowopts *new = para_malloc(sizeof(*new));
{
struct addrinfo *local = NULL, *src = NULL, *remote = NULL,
*dst = NULL, hints;
- unsigned int l3type = AF_UNSPEC;
int rc, on = 1, sockfd = -1,
socktype = sock_type(l4type);
char port[6]; /* port number has at most 5 digits */
sprintf(port, "%u", port_number);
/* Set up address hint structure */
memset(&hints, 0, sizeof(hints));
- hints.ai_family = l3type;
+ hints.ai_family = AF_UNSPEC;
hints.ai_socktype = socktype;
/*
* getaddrinfo does not support SOCK_DCCP, so for the sake of lookup
/* only use addresses available on the host */
hints.ai_flags = AI_ADDRCONFIG;
- if (l3type == AF_INET6)
- /* use v4-mapped-v6 if no v6 addresses found */
- hints.ai_flags |= AI_V4MAPPED | AI_ALL;
if (passive && host == NULL)
hints.ai_flags |= AI_PASSIVE;
/**
* Extract IPv4 or IPv6-mapped-IPv4 address from sockaddr_storage.
- * \param ss Container of IPv4/6 address
- * \return Extracted IPv4 address (different from 0) or 0 if unsuccessful.
*
- * \sa RFC 3493
+ * \param ss Container of IPv4/6 address.
+ * \param ia Extracted IPv4 address (different from 0) or 0 if unsuccessful.
+ *
+ * \sa RFC 3493.
*/
-struct in_addr extract_v4_addr(const struct sockaddr_storage *ss)
+void extract_v4_addr(const struct sockaddr_storage *ss, struct in_addr *ia)
{
- struct in_addr ia = {.s_addr = 0};
const struct sockaddr *sa = normalize_ip_address(ss);
+ memset(ia, 0, sizeof(*ia));
if (sa->sa_family == AF_INET)
- ia = ((struct sockaddr_in *)sa)->sin_addr;
- return ia;
+ *ia = ((struct sockaddr_in *)sa)->sin_addr;
}
/**