Mercurial > hg > octave-lyh > gnulib-hg
changeset 6892:5c4cc6c7a8c0
Various small tweaks.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 29 Jun 2006 15:16:56 +0000 |
parents | fda12264b6e2 |
children | b56d9038d586 |
files | lib/ChangeLog lib/getaddrinfo.c lib/getaddrinfo.h |
diffstat | 3 files changed, 24 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,12 @@ +2006-06-28 Bruno Haible <bruno@clisp.org> + + * getaddrinfo.h: Fix POSIX URL. + * getaddrinfo.c (WIN32_NATIVE): New macro. Use it instead of _WIN32. + (use_win32_p): Make static. + (getaddrinfo): Reject service name if it is empty or does not consist + solely of decimal digits, or if its value is > 65535. + (getnameinfo): Remove useless casts. + 2006-06-28 Derek R. Price <derek@ximbiot.com> * savedir.c (CLOSEDIR): Remove. All uses changed to closedir.
--- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -40,11 +40,15 @@ #include "strdup.h" -#ifdef _WIN32 -typedef void WSAAPI (*freeaddrinfo_func) (struct addrinfo*); +#if defined _WIN32 || defined __WIN32__ +# define WIN32_NATIVE +#endif + +#ifdef WIN32_NATIVE typedef int WSAAPI (*getaddrinfo_func) (const char*, const char*, 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); @@ -53,7 +57,8 @@ static freeaddrinfo_func freeaddrinfo_ptr = NULL; static getnameinfo_func getnameinfo_ptr = NULL; -int use_win32_p (void) +static int +use_win32_p (void) { static int done = 0; HMODULE h; @@ -128,7 +133,7 @@ }; #endif -#ifdef _WIN32 +#ifdef WIN32_NATIVE if (use_win32_p ()) return getaddrinfo_ptr (nodename, servname, hints, res); #endif @@ -162,8 +167,10 @@ if (!se) { char *c; + if (!(*servname >= '0' && *servname <= '9)) + return EAI_NONAME; port = strtoul (servname, &c, 10); - if (*c) + if (*c || port > 0xffff) return EAI_NONAME; port = htons (port); } @@ -285,7 +292,7 @@ void freeaddrinfo (struct addrinfo *ai) { -#ifdef _WIN32 +#ifdef WIN32_NATIVE if (use_win32_p ()) return freeaddrinfo_ptr (ai); #endif @@ -307,7 +314,7 @@ char *restrict service, socklen_t servicelen, int flags) { -#if _WIN32 +#if WIN32_NATIVE if (use_win32_p ()) return getnameinfo_ptr (sa, salen, node, nodelen, service, servicelen, flags); @@ -347,7 +354,6 @@ #if HAVE_IPV4 case AF_INET: if (!inet_ntop (AF_INET, - (const void *) &(((const struct sockaddr_in *) sa)->sin_addr), node, nodelen)) return EAI_SYSTEM; @@ -357,7 +363,6 @@ #if HAVE_IPV6 case AF_INET6: if (!inet_ntop (AF_INET6, - (const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr), node, nodelen)) return EAI_SYSTEM;
--- a/lib/getaddrinfo.h +++ b/lib/getaddrinfo.h @@ -134,7 +134,7 @@ # if !HAVE_DECL_GETNAMEINFO /* Convert socket address to printable node and service names. For more details, see the POSIX:2001 specification - <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */ + <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */ extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen,