version 1.1.1.1, 2012/05/29 12:26:49
|
version 1.1.1.3, 2014/06/15 16:12:54
|
Line 32
|
Line 32
|
|
|
#include <config.h> |
#include <config.h> |
|
|
|
#ifndef HAVE_GETADDRINFO |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
|
|
Line 50
|
Line 52
|
#ifdef HAVE_STRINGS_H |
#ifdef HAVE_STRINGS_H |
# include <strings.h> |
# include <strings.h> |
#endif /* HAVE_STRINGS_H */ |
#endif /* HAVE_STRINGS_H */ |
|
#include <limits.h> |
#include <netdb.h> |
#include <netdb.h> |
#include <errno.h> |
#include <errno.h> |
|
|
|
#include <arpa/inet.h> |
#include <netinet/in.h> |
#include <netinet/in.h> |
|
|
#include "compat/getaddrinfo.h" |
#include "compat/getaddrinfo.h" |
#include "missing.h" |
#include "missing.h" |
|
|
/* We need access to h_errno to map errors from gethostbyname. */ |
/* We need access to h_errno to map errors from gethostbyname. */ |
#if !HAVE_DECL_H_ERRNO | #ifndef HAVE_DECL_H_ERRNO |
extern int h_errno; |
extern int h_errno; |
#endif |
#endif |
|
|
Line 83 extern int h_errno;
|
Line 87 extern int h_errno;
|
* with the system version. Note that we don't rename the structures and |
* with the system version. Note that we don't rename the structures and |
* constants, but that should be okay (except possibly for gai_strerror). |
* constants, but that should be okay (except possibly for gai_strerror). |
*/ |
*/ |
#if TESTING | #ifdef TESTING |
# define gai_strerror test_gai_strerror |
# define gai_strerror test_gai_strerror |
# define freeaddrinfo test_freeaddrinfo |
# define freeaddrinfo test_freeaddrinfo |
# define getaddrinfo test_getaddrinfo |
# define getaddrinfo test_getaddrinfo |
Line 97 int test_getaddrinfo(const char *, const char *, const
|
Line 101 int test_getaddrinfo(const char *, const char *, const
|
* If the native platform doesn't support AI_NUMERICSERV or AI_NUMERICHOST, |
* If the native platform doesn't support AI_NUMERICSERV or AI_NUMERICHOST, |
* pick some other values for them. |
* pick some other values for them. |
*/ |
*/ |
#if TESTING | #ifdef TESTING |
# if AI_NUMERICSERV == 0 |
# if AI_NUMERICSERV == 0 |
# undef AI_NUMERICSERV |
# undef AI_NUMERICSERV |
# define AI_NUMERICSERV 0x0080 |
# define AI_NUMERICSERV 0x0080 |
Line 112 int test_getaddrinfo(const char *, const char *, const
|
Line 116 int test_getaddrinfo(const char *, const char *, const
|
* Value representing all of the hint flags set. Linux uses flags up to |
* Value representing all of the hint flags set. Linux uses flags up to |
* 0x0400, so be sure not to break when testing on that platform. |
* 0x0400, so be sure not to break when testing on that platform. |
*/ |
*/ |
#if TESTING | #ifdef TESTING |
# ifdef HAVE_GETADDRINFO |
# ifdef HAVE_GETADDRINFO |
# define AI_INTERNAL_ALL 0x04ff |
# define AI_INTERNAL_ALL 0x04ff |
# else |
# else |
Line 137 static const char * const gai_errors[] = {
|
Line 141 static const char * const gai_errors[] = {
|
}; |
}; |
|
|
/* Macro to set the len attribute of sockaddr_in. */ |
/* Macro to set the len attribute of sockaddr_in. */ |
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN | #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN |
# define sin_set_length(s) ((s)->sin_len = sizeof(struct sockaddr_in)) |
# define sin_set_length(s) ((s)->sin_len = sizeof(struct sockaddr_in)) |
#else |
#else |
# define sin_set_length(s) /* empty */ |
# define sin_set_length(s) /* empty */ |
Line 185 freeaddrinfo(struct addrinfo *ai)
|
Line 189 freeaddrinfo(struct addrinfo *ai)
|
|
|
|
|
/* |
/* |
* Convert a numeric service string to a number with error checking, returning |
|
* true if the number was parsed correctly and false otherwise. Stores the |
|
* converted number in the second argument. Equivalent to calling strtol, but |
|
* with the base always fixed at 10, with checking of errno, ensuring that all |
|
* of the string is consumed, and checking that the resulting number is |
|
* positive. |
|
*/ |
|
static int |
|
convert_service(const char *string, long *result) |
|
{ |
|
char *end; |
|
|
|
if (*string == '\0') |
|
return 0; |
|
errno = 0; |
|
*result = strtol(string, &end, 10); |
|
if (errno != 0 || *end != '\0' || *result < 0) |
|
return 0; |
|
return 1; |
|
} |
|
|
|
|
|
/* |
|
* Allocate a new addrinfo struct, setting some defaults given that this |
* Allocate a new addrinfo struct, setting some defaults given that this |
* implementation is IPv4 only. Also allocates an attached sockaddr_in and |
* implementation is IPv4 only. Also allocates an attached sockaddr_in and |
* zeroes it, per the requirement for getaddrinfo. Takes the socktype, |
* zeroes it, per the requirement for getaddrinfo. Takes the socktype, |
Line 265 gai_service(const char *servname, int flags, int *type
|
Line 246 gai_service(const char *servname, int flags, int *type
|
{ |
{ |
struct servent *servent; |
struct servent *servent; |
const char *protocol; |
const char *protocol; |
long value; | const char *errstr; |
| unsigned short value; |
|
|
if (convert_service(servname, &value)) { | value = strtonum(servname, 0, USHRT_MAX, &errstr); |
if (value > (1L << 16) - 1) | if (errstr == NULL) { |
return EAI_SERVICE; | |
*port = value; |
*port = value; |
|
} else if (errno == ERANGE) { |
|
return EAI_SERVICE; |
} else { |
} else { |
if (flags & AI_NUMERICSERV) |
if (flags & AI_NUMERICSERV) |
return EAI_NONAME; |
return EAI_NONAME; |
Line 317 gai_lookup(const char *nodename, int flags, int sockty
|
Line 300 gai_lookup(const char *nodename, int flags, int sockty
|
const char *canonical; |
const char *canonical; |
int i; |
int i; |
|
|
if (inet_aton(nodename, &addr)) { | if (inet_pton(AF_INET, nodename, &addr)) { |
canonical = (flags & AI_CANONNAME) ? nodename : NULL; |
canonical = (flags & AI_CANONNAME) ? nodename : NULL; |
ai = gai_addrinfo_new(socktype, canonical, addr, port); |
ai = gai_addrinfo_new(socktype, canonical, addr, port); |
if (ai == NULL) |
if (ai == NULL) |
Line 436 getaddrinfo(const char *nodename, const char *servname
|
Line 419 getaddrinfo(const char *nodename, const char *servname
|
return 0; |
return 0; |
} |
} |
} |
} |
|
#endif /* HAVE_GETADDRINFO */ |