X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=70d3ec0f2d1ad297a8249acb3bd0f1a1a0815eb9;hp=c18e7a0a19cfa1ff741fee6b8f3e0232a4813b7d;hb=7d2c2777c3cc16ef50f580f5ff548d8ad6bb0c9b;hpb=8536a1d8de423ab7d021c1f1364bb12fab8ce575 diff --git a/net.c b/net.c index c18e7a0a..70d3ec0f 100644 --- a/net.c +++ b/net.c @@ -142,9 +142,9 @@ static bool host_string_ok(const char *host) * \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 */ @@ -168,16 +168,16 @@ char *parse_url(const char *url, 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: @@ -264,6 +264,12 @@ struct flowopts { 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)); @@ -371,7 +377,6 @@ int makesock(unsigned l4type, bool passive, { 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 */ @@ -379,7 +384,7 @@ int makesock(unsigned l4type, bool passive, 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 @@ -390,9 +395,6 @@ int makesock(unsigned l4type, bool passive, /* 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; @@ -666,19 +668,19 @@ char *remote_name(int sockfd) /** * 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; } /**