From eea6490accf79d163fc46a25d869da2271014180 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Sat, 1 Oct 2005 10:27:20 +0000 Subject: [PATCH] 2005-10-01 Simon Josefsson * getaddrinfo.h: Protect #include's of sys/socket.h and netdb.h. Only define struct addrinfo if !HAVE_STRUCT_ADDRINFO. Protect AI_* and EAI_* definitions. Protect function declarations. --- lib/ChangeLog | 6 ++++ lib/getaddrinfo.h | 84 +++++++++++++++++++++++++++++------------------ 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 322f22849f..b2fd7a381c 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2005-10-01 Simon Josefsson + + * getaddrinfo.h: Protect #include's of sys/socket.h and netdb.h. + Only define struct addrinfo if !HAVE_STRUCT_ADDRINFO. Protect + AI_* and EAI_* definitions. Protect function declarations. + 2005-09-29 Paul Eggert * xtime.h (XTIME_PRECISION): Now of type int, not long long int, diff --git a/lib/getaddrinfo.h b/lib/getaddrinfo.h index 5d14562c24..8b2d9bcc10 100644 --- a/lib/getaddrinfo.h +++ b/lib/getaddrinfo.h @@ -19,13 +19,21 @@ #ifndef GETADDRINFO_H # define GETADDRINFO_H -/* Get getaddrinfo declarations, if available. Also get 'socklen_t', - and 'struct sockaddr' via sys/types.h which are used below. */ -# include -# include -# include +/* Get all getaddrinfo related declarations, if available. */ +# ifdef HAVE_SYS_SOCKET_H +# include +# endif +# ifdef HAVE_NETDB_H +# include +# endif + +# ifndef HAVE_STRUCT_ADDRINFO -# if !HAVE_GETADDRINFO +/* Get 'socklen_t', and 'struct sockaddr' via sys/types.h which are + used below. */ +# ifdef HAVE_SYS_TYPES_H +# include +# endif /* Structure to contain information about address of a service provider. */ struct addrinfo @@ -39,38 +47,47 @@ struct addrinfo char *ai_canonname; /* Canonical name for service location. */ struct addrinfo *ai_next; /* Pointer to next in list. */ }; +# endif /* Possible values for `ai_flags' field in `addrinfo' structure. */ -# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ -# define AI_CANONNAME 0x0002 /* Request for canonical name. */ -# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ -# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ -# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ -# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose +# ifndef AI_PASSIVE +# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ +# define AI_CANONNAME 0x0002 /* Request for canonical name. */ +# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ +# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ +# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ +# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose returned address type.. */ +# endif /* Error values for `getaddrinfo' function. */ -# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ -# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ -# define EAI_AGAIN -3 /* Temporary failure in name resolution. */ -# define EAI_FAIL -4 /* Non-recoverable failure in name res. */ -# define EAI_NODATA -5 /* No address associated with NAME. */ -# define EAI_FAMILY -6 /* `ai_family' not supported. */ -# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ -# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ -# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ -# define EAI_MEMORY -10 /* Memory allocation failure. */ -# define EAI_SYSTEM -11 /* System error returned in `errno'. */ -# define EAI_OVERFLOW -12 /* Argument buffer overflow. */ +# ifndef EAI_BADFLAGS +# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ +# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ +# define EAI_AGAIN -3 /* Temporary failure in name resolution. */ +# define EAI_FAIL -4 /* Non-recoverable failure in name res. */ +# define EAI_NODATA -5 /* No address associated with NAME. */ +# define EAI_FAMILY -6 /* `ai_family' not supported. */ +# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ +# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ +# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ +# define EAI_MEMORY -10 /* Memory allocation failure. */ +# define EAI_SYSTEM -11 /* System error returned in `errno'. */ +# define EAI_OVERFLOW -12 /* Argument buffer overflow. */ +# endif + # ifdef __USE_GNU -# define EAI_INPROGRESS -100 /* Processing request in progress. */ -# define EAI_CANCELED -101 /* Request canceled. */ -# define EAI_NOTCANCELED -102 /* Request not canceled. */ -# define EAI_ALLDONE -103 /* All requests done. */ -# define EAI_INTR -104 /* Interrupted by a signal. */ -# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ +# ifndef EAI_INPROGRESS +# define EAI_INPROGRESS -100 /* Processing request in progress. */ +# define EAI_CANCELED -101 /* Request canceled. */ +# define EAI_NOTCANCELED -102 /* Request not canceled. */ +# define EAI_ALLDONE -103 /* All requests done. */ +# define EAI_INTR -104 /* Interrupted by a signal. */ +# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ +# endif # endif +# ifndef HAVE_DECL_GETADDRINFO /* Translate name of a service location and/or a service name to set of socket addresses. For more details, see the POSIX:2001 specification @@ -79,17 +96,20 @@ extern int getaddrinfo (const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints, struct addrinfo **restrict res); +# endif +# ifndef HAVE_DECL_FREEADDRINFO /* Free `addrinfo' structure AI including associated storage. For more details, see the POSIX:2001 specification . */ extern void freeaddrinfo (struct addrinfo *ai); +# endif +# ifndef HAVE_DECL_GAI_STRERROR /* Convert error return from getaddrinfo() to a string. For more details, see the POSIX:2001 specification . */ extern const char *gai_strerror (int ecode); - -# endif /* !HAVE_GETADDRINFO */ +# endif #endif /* GETADDRINFO_H */ -- 2.30.2