X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fgetaddrinfo.c;h=aa07903445683ad40d73f87741e33cd1c393f314;hb=dd6ceef65e424d30db8706273f88c20b015012ce;hp=333ad3b3d24cd6069f27c0d0fcab068d3a8dd4a6;hpb=1d8f627a4e74800e2d2e9ec0a46f7988bd2c7257;p=gnulib.git diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 333ad3b3d..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,9 +41,6 @@ #define N_(String) String #include "inet_ntop.h" -#include "intprops.h" -#include "inttostr.h" -#include "strdup.h" /* BeOS has AF_INET, but not PF_INET. */ #ifndef PF_INET @@ -180,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); @@ -409,11 +408,8 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, { unsigned short int port = ntohs (((const struct sockaddr_in *) sa)->sin_port); - char buf[INT_BUFSIZE_BOUND (port)]; - char const *s = uinttostr (port, buf); - if (strlen (s) + 1 > servicelen) + if (servicelen <= snprintf (service, servicelen, "%u", port)) return EAI_OVERFLOW; - memcpy (service, s, strlen (s) + 1); } break; }