X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetaddrinfo.c;h=6a36bf0fc0a923af6ce68905e4aeaf7017a2cff1;hb=1a2869593e115e4a6c74aaa0b23ca612357403ce;hp=add56ba1bd85be25d639db7021edd369860f7eeb;hpb=1e4ece4ab9850fbfa88c9ec43ea518c7bc266792;p=gnulib.git diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index add56ba1b..6a36bf0fc 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -1,5 +1,5 @@ /* Get address information (partial implementation). - Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007 Free Software + Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Contributed by Simon Josefsson . @@ -19,27 +19,30 @@ #include -#include "getaddrinfo.h" +#include #if HAVE_NETINET_IN_H # include #endif +/* Get inet_ntop. */ +#include + /* Get calloc. */ #include /* Get memcpy, strdup. */ #include +/* Get snprintf. */ +#include + #include #include "gettext.h" #define _(String) gettext (String) #define N_(String) String -#include "inet_ntop.h" -#include "snprintf.h" - /* BeOS has AF_INET, but not PF_INET. */ #ifndef PF_INET # define PF_INET AF_INET @@ -177,7 +180,7 @@ getaddrinfo (const char *restrict nodename, const char *proto = (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; - if (!(hints->ai_flags & AI_NUMERICSERV)) + if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV)) /* FIXME: Use getservbyname_r if available. */ se = getservbyname (servname, proto); @@ -298,6 +301,22 @@ getaddrinfo (const char *restrict nodename, tmp->ai_addr->sa_family = he->h_addrtype; tmp->ai_family = he->h_addrtype; +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN + switch (he->h_addrtype) + { +#if HAVE_IPV4 + case AF_INET: + tmp->ai_addr->sa_len = sizeof (struct sockaddr_in); + break; +#endif +#if HAVE_IPV6 + case AF_INET6: + tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6); + break; +#endif + } +#endif + /* FIXME: If more than one address, create linked list of addrinfo's. */ *res = tmp; @@ -324,7 +343,7 @@ freeaddrinfo (struct addrinfo *ai) cur = ai; ai = ai->ai_next; - if (cur->ai_canonname) free (cur->ai_canonname); + free (cur->ai_canonname); free (cur); } }