Commit 4b97a8d6 authored by Pekka Pessi's avatar Pekka Pessi

Improving getaddrinfo replacements.

Testing functions getaddrinfo()/freeaddrinfo(), getnameinfo() and
gai_strerror() separately.
There is no gai_strerror() in windows, I think.

darcs-hash:20060209152438-65a35-1b47dc1ab6a2a024ce390652b65a90d2cf4d20ef.gz
parent 1e8a716d
......@@ -27,10 +27,12 @@
* SUCH DAMAGE.
*/
#include "config.h"
#include <su_addrinfo.h>
#include <su.h>
#if !SU_HAVE_GETADDRINFO
#if !HAVE_GETADDRINFO
#include <string.h>
#include <stddef.h>
......@@ -130,24 +132,6 @@ static int get_addr(const char *, int, struct addrinfo **,
struct addrinfo *, int);
static int str_isnumber(const char *);
static char *ai_errlist[] = {
"success.",
"address family for hostname not supported.", /* EAI_ADDRFAMILY */
"temporary failure in name resolution.", /* EAI_AGAIN */
"invalid value for ai_flags.", /* EAI_BADFLAGS */
"non-recoverable failure in name resolution.", /* EAI_FAIL */
"ai_family not supported.", /* EAI_FAMILY */
"memory allocation failure.", /* EAI_MEMORY */
"no address associated with hostname.", /* EAI_NODATA */
"hostname nor servname provided, or not known.",/* EAI_NONAME */
"servname not supported for ai_socktype.", /* EAI_SERVICE */
"ai_socktype not supported.", /* EAI_SOCKTYPE */
"system error returned in errno.", /* EAI_SYSTEM */
"invalid value for hints.", /* EAI_BADHINTS */
"resolved protocol is unknown.", /* EAI_PROTOCOL */
"unknown error.", /* EAI_MAX */
};
#define GET_CANONNAME(ai, str) \
if (pai->ai_flags & AI_CANONNAME) {\
if (((ai)->ai_canonname = (char *)malloc(strlen(str) + 1)) != NULL) {\
......@@ -192,32 +176,6 @@ if (pai->ai_flags & AI_CANONNAME) {\
#define ERR(err) { error = (err); goto bad; }
static
char *
gai_strerror(ecode)
int ecode;
{
if (ecode < 0 || ecode > EAI_MAX)
ecode = EAI_MAX;
return ai_errlist[ecode];
}
static
void
freeaddrinfo(ai)
struct addrinfo *ai;
{
struct addrinfo *next;
do {
next = ai->ai_next;
if (ai->ai_canonname)
free(ai->ai_canonname);
/* no need to free(ai->ai_addr) */
free(ai);
} while ((ai = next) != NULL);
}
static int
str_isnumber(p)
const char *p;
......@@ -659,6 +617,10 @@ get_addr(hostname, af, res, pai, port0)
return error;
}
#endif /* !HAVE_GETADDRINFO */
#if !HAVE_GETNAMEINFO
/*
* Issues to be discussed:
* - Thread safe-ness must be checked
......@@ -691,13 +653,13 @@ struct gni_sockinet {
u_short si_port;
};
#define ENI_NOSOCKET 0
#define ENI_NOSERVNAME 1
#define ENI_NOHOSTNAME 2
#define ENI_MEMORY 3
#define ENI_SYSTEM 4
#define ENI_FAMILY 5
#define ENI_SALEN 6
#define ENI_NOSOCKET EAI_FAIL
#define ENI_NOSERVNAME EAI_NONAME
#define ENI_NOHOSTNAME EAI_NONAME
#define ENI_MEMORY EAI_MEMORY
#define ENI_SYSTEM EAI_SYSTEM
#define ENI_FAMILY EAI_FAMILY
#define ENI_SALEN EAI_MEMORY
static
int
......@@ -826,7 +788,92 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
return SUCCESS;
}
#endif /* !SU_HAVE_GETADDRINFO */
#endif /* !HAVE_GETNAMEINFO */
#if !HAVE_FREEADDRINFO
static
void
freeaddrinfo(ai)
struct addrinfo *ai;
{
struct addrinfo *next;
do {
next = ai->ai_next;
if (ai->ai_canonname)
free(ai->ai_canonname);
/* no need to free(ai->ai_addr) */
free(ai);
} while ((ai = next) != NULL);
}
#endif
#if !HAVE_GAI_STRERROR
static
char *
gai_strerror(ecode)
int ecode;
{
switch (ecode) {
case 0:
return "success.";
#if defined(EAI_ADDRFAMILY)
case EAI_ADDRFAMILY:
return "address family for hostname not supported.";
#endif
#if defined(EAI_AGAIN)
case EAI_AGAIN:
return "temporary failure in name resolution.";
#endif
#if defined(EAI_BADFLAGS)
case EAI_BADFLAGS:
return "invalid value for ai_flags.";
#endif
#if defined(EAI_FAIL)
case EAI_FAIL:
return "non-recoverable failure in name resolution.";
#endif
#if defined(EAI_FAMILY)
case EAI_FAMILY:
return "ai_family not supported.";
#endif
#if defined(EAI_MEMORY)
case EAI_MEMORY:
return "memory allocation failure.";
#endif
#if defined(EAI_NODATA)
case EAI_NODATA:
return "no address associated with hostname.";
#endif
#if defined(EAI_NONAME)
case EAI_NONAME:
return "hostname nor servname provided, or not known.";
#endif
#if defined(EAI_SERVICE)
case EAI_SERVICE:
return "servname not supported for ai_socktype.";
#endif
#if defined(EAI_SOCKTYPE)
case EAI_SOCKTYPE:
return "ai_socktype not supported.";
#endif
#if defined(EAI_SYSTEM)
case EAI_SYSTEM:
return "system error returned in errno.";
#endif
#if defined(EAI_BADHINTS)
case EAI_BADHINTS:
return "invalid value for hints.";
#endif
#if defined(EAI_PROTOCOL)
case EAI_PROTOCOL:
return "resolved protocol is unknown.";
#endif
default:
return "unknown error.";
}
#endif
/** Translate address and service.
*
......@@ -836,7 +883,7 @@ int su_getaddrinfo(char const *node, char const *service,
su_addrinfo_t const *hints,
su_addrinfo_t **res)
{
#if HAVE_SCTP && SU_HAVE_GETADDRINFO
#if HAVE_SCTP
if (res && hints && hints->ai_protocol == IPPROTO_SCTP) {
su_addrinfo_t *ai, system_hints[1];
int retval, socktype;
......
......@@ -36,7 +36,7 @@
SOFIA_BEGIN_DECLS
#if !SU_HAVE_GETADDRINFO
#if !SU_HAVE_ADDRINFO
/*
* Error return codes from getaddrinfo()
*/
......@@ -104,17 +104,11 @@ struct addrinfo {
struct sockaddr *ai_addr; /* binary address */
struct addrinfo *ai_next; /* next structure in linked list */
};
#endif /* SU_WITH_GETADDRINFO */
/** RFC 1576 address info structure. */
typedef struct addrinfo su_addrinfo_t;
#else
/** RFC 1576 address info structure. */
typedef struct addrinfo su_addrinfo_t;
#endif /* SU_WITH_GETADDRINFO */
/** Translate address and service. */
int su_getaddrinfo(char const *node, char const *service,
su_addrinfo_t const *hints,
......
......@@ -64,11 +64,12 @@
/** Define as 1 if you have struct sockaddr_storage */
#undef SU_HAVE_SOCKADDR_STORAGE
/** Define as 1 if you have getaddrinfo() function. */
#undef SU_HAVE_GETADDRINFO
/** Define as 1 if you have struct addrinfo. */
#undef SU_HAVE_ADDRINFO
/** Define as 1 if you have Winsock interface */
#undef SU_HAVE_WINSOCK
/** Define as 1 if you have Winsock2 interface */
#undef SU_HAVE_WINSOCK2
......
......@@ -113,6 +113,21 @@ AC_CHECK_HEADERS([unistd.h sys/time.h])
AC_CHECK_HEADERS([sys/socket.h sys/ioctl.h sys/filio.h sys/sockio.h])
AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h net/if.h net/if_types.h])
AC_CACHE_CHECK([for struct addrinfo],
[ac_cv_struct_addrinfo],[
ac_cv_struct_addrinfo=no
if test "$ac_cv_header_sys_socket_h" = yes; then
AC_EGREP_HEADER([struct.+addrinfo], [netdb.h], [
ac_cv_struct_addrinfo=yes])
else
ac_cv_struct_addrinfo='sys/socket.h missing'
fi])
if test "$ac_cv_struct_addrinfo" = yes; then
SAC_SU_DEFINE(SU_HAVE_ADDRINFO, 1,
[Define as 1 if you have struct addrinfo.])
fi
AC_CACHE_CHECK([for struct sockaddr_storage],
[ac_cv_struct_sockaddr_storage],[
ac_cv_struct_sockaddr_storage=no
......@@ -245,6 +260,7 @@ AC_SUBST(GLIB_VERSION)
AC_CHECK_FUNCS(gettimeofday strerror random initstate tcsetattr flock alarm)
AC_CHECK_FUNCS(socketpair gethostname getipnodebyname poll)
AC_CHECK_FUNCS(getaddrinfo getnameinfo freeaddrinfo gai_strerror)
if false; then
# not yet
......@@ -262,12 +278,6 @@ fi
SAC_REPLACE_FUNCS(memmem memccpy memspn memcspn strcasestr strtoull)
# Test for getaddrinfo(), getnameinfo(), freeaddrinfo() and gai_strerror()
AC_CHECK_FUNC([getaddrinfo],[
SAC_SU_DEFINE([SU_HAVE_GETADDRINFO], 1, [
Define this as 1 if you have getaddrinfo() function.
])])
AC_CHECK_FUNC([poll],
SAC_SU_DEFINE([SU_HAVE_POLL], 1, [
Define this as 1 if you have poll() function.
......
......@@ -22,7 +22,7 @@
*
*/
/**@file win32/config.h
/**@file win32/config.h.in
* @brief <config.h> used by Windows.
*
* Use this on WIN32.
......@@ -54,14 +54,20 @@
/* Define to 1 if you have the `flock' function. */
#undef HAVE_FLOCK
/* Define to 1 if you have the `freeaddrinfo' function. */
#define HAVE_FREEADDRINFO 1
/* Define as 1 if the C compiler supports __func__ */
#undef HAVE_FUNC
/* Define as 1 if the C compiler supports __FUNCTION__ */
#undef HAVE_FUNCTION
/* Define to 1 if you have the `gai_strerror' function. */
#undef HAVE_GAI_STRERROR
/* Define to 1 if you have the `getaddrinfo' function. */
#undef HAVE_GETADDRINFO
#define HAVE_GETADDRINFO 1
/* Define to 1 if you have the `getdelim' function. */
#undef HAVE_GETDELIM
......@@ -75,6 +81,9 @@
/* Define to 1 if you have the `getline' function. */
#undef HAVE_GETLINE
/* Define to 1 if you have the `getnameinfo' function. */
#define HAVE_GETNAMEINFO 1
/* Define to 1 if you have the `getpass' function. */
#undef HAVE_GETPASS
......
......@@ -22,8 +22,6 @@
*
*/
/** Defined when su_configure_win32.h has been included. */
#define SU_CONFIGURE_WIN32_H
/**@file su_configure_win32.h
*
* @b su library configuration for WIN32 (VC6/VC98)
......@@ -58,8 +56,8 @@
/* Define this as 1 if you have if_nameindex() */
#undef SU_HAVE_IF_NAMEINDEX
/* Define this as 1 if you have getaddrinfo() */
#define SU_HAVE_GETADDRINFO 1
/* Define as 1 if you have struct getaddrinfo. */
#define SU_HAVE_ADDRINFO 1
#define SU_INLINE __inline
#define su_inline static __inline
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment