X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetaddrinfo.c;h=aa07903445683ad40d73f87741e33cd1c393f314;hb=3f443c986bb76f2197ea3cc64c094c5d8af609b3;hp=9003abf60ac7e145ac755153de2897df22e7837c;hpb=361c5154c63de94ec3571612225de4a6933189b7;p=gnulib.git diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 9003abf60..aa0790344 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -1,5 +1,6 @@ /* Get address information (partial implementation). - Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007 Free Software + Foundation, Inc. Contributed by Simon Josefsson . This program is free software; you can redistribute it and/or modify @@ -16,9 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "getaddrinfo.h" @@ -29,9 +28,12 @@ /* Get calloc. */ #include -/* Get memcpy. */ +/* Get memcpy, strdup. */ #include +/* Get snprintf. */ +#include + #include #include "gettext.h" @@ -39,8 +41,15 @@ #define N_(String) String #include "inet_ntop.h" -#include "snprintf.h" -#include "strdup.h" + +/* BeOS has AF_INET, but not PF_INET. */ +#ifndef PF_INET +# define PF_INET AF_INET +#endif +/* BeOS also lacks PF_UNSPEC. */ +#ifndef PF_UNSPEC +# define PF_UNSPEC 0 +#endif #if defined _WIN32 || defined __WIN32__ # define WIN32_NATIVE @@ -158,7 +167,7 @@ getaddrinfo (const char *restrict nodename, return EAI_NONAME; #ifdef HAVE_IPV6 - nodename = (hint->ai_family == AF_INET6) ? "::" : "0.0.0.0"; + nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; #else nodename = "0.0.0.0"; #endif @@ -170,7 +179,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); @@ -396,10 +405,12 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, #if HAVE_IPV6 case AF_INET6: #endif - if (snprintf (service, servicelen, "%d", - ntohs (((const struct sockaddr_in *) sa)->sin_port)) - + 1 > servicelen) - return EAI_OVERFLOW; + { + unsigned short int port + = ntohs (((const struct sockaddr_in *) sa)->sin_port); + if (servicelen <= snprintf (service, servicelen, "%u", port)) + return EAI_OVERFLOW; + } break; }