diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-04-07 21:11:46 -0400 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-04-12 21:26:35 -0400 |
commit | 74da141e618ef99959d509cb2e7be35a348a39db (patch) | |
tree | 88ebc38b381a1021fc2d74864a71e230ae591c3d /gl/getaddrinfo.c | |
parent | c63a4f726a0b6ad8cf6040f947754a81fd4683bb (diff) | |
download | monitoring-plugins-74da141e618ef99959d509cb2e7be35a348a39db.tar.gz |
Sync with the latest Gnulib code (177f525)
Signed-off-by: Thomas Guyot-Sionnest <dermoth@aei.ca>
Diffstat (limited to 'gl/getaddrinfo.c')
-rw-r--r-- | gl/getaddrinfo.c | 174 |
1 files changed, 89 insertions, 85 deletions
diff --git a/gl/getaddrinfo.c b/gl/getaddrinfo.c index f09cf9ee..6aa676c8 100644 --- a/gl/getaddrinfo.c +++ b/gl/getaddrinfo.c @@ -1,6 +1,5 @@ /* Get address information (partial implementation). - Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software - Foundation, Inc. + Copyright (C) 1997, 2001-2002, 2004-2010 Free Software Foundation, Inc. Contributed by Simon Josefsson <simon@josefsson.org>. This program is free software; you can redistribute it and/or modify @@ -19,6 +18,10 @@ #include <config.h> +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the sa == NULL test below. */ +#define _GL_ARG_NONNULL(params) + #include <netdb.h> #if HAVE_NETINET_IN_H @@ -58,12 +61,12 @@ #ifdef WIN32_NATIVE typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, - const struct addrinfo*, - struct addrinfo**); + const struct addrinfo*, + struct addrinfo**); typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*); typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*, - socklen_t, char*, DWORD, - char*, DWORD, int); + socklen_t, char*, DWORD, + char*, DWORD, int); static getaddrinfo_func getaddrinfo_ptr = NULL; static freeaddrinfo_func freeaddrinfo_ptr = NULL; @@ -123,9 +126,9 @@ validate_family (int family) socket addresses. */ int getaddrinfo (const char *restrict nodename, - const char *restrict servname, - const struct addrinfo *restrict hints, - struct addrinfo **restrict res) + const char *restrict servname, + const struct addrinfo *restrict hints, + struct addrinfo **restrict res) { struct addrinfo *tmp; int port = 0; @@ -165,7 +168,7 @@ getaddrinfo (const char *restrict nodename, if (!nodename) { if (!(hints->ai_flags & AI_PASSIVE)) - return EAI_NONAME; + return EAI_NONAME; #ifdef HAVE_IPV6 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; @@ -178,24 +181,24 @@ getaddrinfo (const char *restrict nodename, { struct servent *se = NULL; const char *proto = - (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; + (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV)) - /* FIXME: Use getservbyname_r if available. */ - se = getservbyname (servname, proto); + /* FIXME: Use getservbyname_r if available. */ + se = getservbyname (servname, proto); if (!se) - { - char *c; - if (!(*servname >= '0' && *servname <= '9')) - return EAI_NONAME; - port = strtoul (servname, &c, 10); - if (*c || port > 0xffff) - return EAI_NONAME; - port = htons (port); - } + { + char *c; + if (!(*servname >= '0' && *servname <= '9')) + return EAI_NONAME; + port = strtoul (servname, &c, 10); + if (*c || port > 0xffff) + return EAI_NONAME; + port = htons (port); + } else - port = se->s_port; + port = se->s_port; } /* FIXME: Use gethostbyname_r if available. */ @@ -230,23 +233,23 @@ getaddrinfo (const char *restrict nodename, #if HAVE_IPV6 case PF_INET6: { - struct v6_pair *p = storage; - struct sockaddr_in6 *sinp = &p->sockaddr_in6; - tmp = &p->addrinfo; + struct v6_pair *p = storage; + struct sockaddr_in6 *sinp = &p->sockaddr_in6; + tmp = &p->addrinfo; - if (port) - sinp->sin6_port = port; + if (port) + sinp->sin6_port = port; - if (he->h_length != sizeof (sinp->sin6_addr)) - { - free (storage); - return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ - } + if (he->h_length != sizeof (sinp->sin6_addr)) + { + free (storage); + return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ + } - memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); + memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); - tmp->ai_addr = (struct sockaddr *) sinp; - tmp->ai_addrlen = sizeof *sinp; + tmp->ai_addr = (struct sockaddr *) sinp; + tmp->ai_addrlen = sizeof *sinp; } break; #endif @@ -254,23 +257,23 @@ getaddrinfo (const char *restrict nodename, #if HAVE_IPV4 case PF_INET: { - struct v4_pair *p = storage; - struct sockaddr_in *sinp = &p->sockaddr_in; - tmp = &p->addrinfo; + struct v4_pair *p = storage; + struct sockaddr_in *sinp = &p->sockaddr_in; + tmp = &p->addrinfo; - if (port) - sinp->sin_port = port; + if (port) + sinp->sin_port = port; - if (he->h_length != sizeof (sinp->sin_addr)) - { - free (storage); - return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ - } + if (he->h_length != sizeof (sinp->sin_addr)) + { + free (storage); + return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ + } - memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); + memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); - tmp->ai_addr = (struct sockaddr *) sinp; - tmp->ai_addrlen = sizeof *sinp; + tmp->ai_addr = (struct sockaddr *) sinp; + tmp->ai_addrlen = sizeof *sinp; } break; #endif @@ -284,16 +287,16 @@ getaddrinfo (const char *restrict nodename, { const char *cn; if (he->h_name) - cn = he->h_name; + cn = he->h_name; else - cn = nodename; + cn = nodename; tmp->ai_canonname = strdup (cn); if (!tmp->ai_canonname) - { - free (storage); - return EAI_MEMORY; - } + { + free (storage); + return EAI_MEMORY; + } } tmp->ai_protocol = (hints) ? hints->ai_protocol : 0; @@ -348,15 +351,16 @@ freeaddrinfo (struct addrinfo *ai) } } -int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, - char *restrict node, socklen_t nodelen, - char *restrict service, socklen_t servicelen, - int flags) +int +getnameinfo (const struct sockaddr *restrict sa, socklen_t salen, + char *restrict node, socklen_t nodelen, + char *restrict service, socklen_t servicelen, + int flags) { #ifdef WIN32_NATIVE if (use_win32_p ()) return getnameinfo_ptr (sa, salen, node, nodelen, - service, servicelen, flags); + service, servicelen, flags); #endif /* FIXME: Support other flags. */ @@ -373,13 +377,13 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, #if HAVE_IPV4 case AF_INET: if (salen < sizeof (struct sockaddr_in)) - return EAI_FAMILY; + return EAI_FAMILY; break; #endif #if HAVE_IPV6 case AF_INET6: if (salen < sizeof (struct sockaddr_in6)) - return EAI_FAMILY; + return EAI_FAMILY; break; #endif default: @@ -389,28 +393,28 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, if (node && nodelen > 0 && flags & NI_NUMERICHOST) { switch (sa->sa_family) - { + { #if HAVE_IPV4 - case AF_INET: - if (!inet_ntop (AF_INET, - &(((const struct sockaddr_in *) sa)->sin_addr), - node, nodelen)) - return EAI_SYSTEM; - break; + case AF_INET: + if (!inet_ntop (AF_INET, + &(((const struct sockaddr_in *) sa)->sin_addr), + node, nodelen)) + return EAI_SYSTEM; + break; #endif #if HAVE_IPV6 - case AF_INET6: - if (!inet_ntop (AF_INET6, - &(((const struct sockaddr_in6 *) sa)->sin6_addr), - node, nodelen)) - return EAI_SYSTEM; - break; + case AF_INET6: + if (!inet_ntop (AF_INET6, + &(((const struct sockaddr_in6 *) sa)->sin6_addr), + node, nodelen)) + return EAI_SYSTEM; + break; #endif - default: - return EAI_FAMILY; - } + default: + return EAI_FAMILY; + } } if (service && servicelen > 0 && flags & NI_NUMERICSERV) @@ -422,13 +426,13 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, #if HAVE_IPV6 case AF_INET6: #endif - { - unsigned short int port - = ntohs (((const struct sockaddr_in *) sa)->sin_port); - if (servicelen <= snprintf (service, servicelen, "%u", port)) - return EAI_OVERFLOW; - } - break; + { + unsigned short int port + = ntohs (((const struct sockaddr_in *) sa)->sin_port); + if (servicelen <= snprintf (service, servicelen, "%u", port)) + return EAI_OVERFLOW; + } + break; } return 0; |