Commit 2b7a5fc5 authored by Pekka Pessi's avatar Pekka Pessi

Added su_getaddrinfo() and su_getnameinfo() replacement functions.

darcs-hash:20051130150704-65a35-38eb89719580bd41b737a8112fc18f86e1e89d89.gz
parent a9842a68
......@@ -41,7 +41,8 @@ endif
BUILT_SOURCES = su_tag_ref.c
include_sofia_HEADERS = su_types.h su.h su_localinfo.h \
include_sofia_HEADERS = \
su_types.h su.h su_addrinfo.h su_localinfo.h \
su_wait.h $(GHEADERS) \
su_alloc.h su_alloc_stat.h su_strlst.h su_vector.h \
su_time.h \
......@@ -55,7 +56,7 @@ include_sofia_HEADERS = su_types.h su.h su_localinfo.h \
nodist_include_sofia_HEADERS = su_configure.h
libsu_la_SOURCES = \
su.c $(GSOURCES) \
su.c su_addrinfo.c $(GSOURCES) \
su_alloc.c su_alloc_lock.c su_strdup.c su_sprintf.c \
su_strlst.c su_vector.c \
su_time.c su_time0.c \
......
......@@ -370,64 +370,6 @@ int su_vrecv(su_socket_t s, su_iovec_t iov[], int iovlen, int flags,
#endif
/** Translate address and service.
*
* This is a getaddrinfo() supporting SCTP and other exotic protocols.
*/
int su_getaddrinfo(char const *node, char const *service,
su_addrinfo_t const *hints,
su_addrinfo_t **res)
{
#if HAVE_SCTP
if (res && hints && hints->ai_protocol == IPPROTO_SCTP) {
su_addrinfo_t *ai, system_hints[1];
int retval, socktype;
socktype = hints->ai_socktype;
if (!(socktype == 0 ||
socktype == SOCK_SEQPACKET ||
socktype == SOCK_STREAM ||
socktype == SOCK_DGRAM))
return EAI_SOCKTYPE;
*system_hints = *hints;
system_hints->ai_protocol = IPPROTO_TCP;
system_hints->ai_socktype = SOCK_STREAM;
retval = getaddrinfo(node, service, system_hints, res);
if (retval)
return retval;
if (socktype == 0)
socktype = SOCK_STREAM;
for (ai = *res; ai; ai = ai->ai_next) {
ai->ai_protocol = IPPROTO_SCTP;
ai->ai_socktype = socktype;
}
return 0;
}
#endif
return getaddrinfo(node, service, hints, res);
}
#if SU_HAVE_WINSOCK
/** Free su_addrinfo_t structure allocated by su_getaddrinfo(). */
void su_freeaddrinfo(su_addrinfo_t *res)
{
freeaddrinfo(res);
}
/** Return string describing address translation error. */
char *su_gai_strerror(int errcode)
{
return gai_strerror(errcode);
}
#endif
/** Compare two socket addresses */
int su_cmp_sockaddr(su_sockaddr_t const *a, su_sockaddr_t const *b)
{
......
......@@ -146,9 +146,6 @@ typedef int su_socket_t;
typedef SOCKET su_socket_t;
#endif
/** RFC 1576 address info structure. */
typedef struct addrinfo su_addrinfo_t;
/** Common socket address structure. */
union su_sockaddr_u {
#ifdef DOCUMENTATION_ONLY
......@@ -248,15 +245,7 @@ int su_vrecv(su_socket_t s, su_iovec_t iov[], int iovlen, int flags,
/** Return local IP address */
int su_getlocalip(su_sockaddr_t *sin);
/** Translate address and service. */
int su_getaddrinfo(char const *node, char const *service,
su_addrinfo_t const *hints,
su_addrinfo_t **res);
/** Free su_addrinfo_t structure allocated by su_getaddrinfo(). */
void su_freeaddrinfo(su_addrinfo_t *res);
/** Return string describing address translation error. */
char *su_gai_strerror(int errcode);
#include <su_addrinfo.h>
#if SU_HAVE_BSDSOCK
#define su_socket socket
......@@ -267,9 +256,6 @@ char *su_gai_strerror(int errcode);
#define su_seterrno(n) ((errno = (n)), -1)
#define su_perror perror
#define su_strerror(e) strerror(e)
#define su_freeaddrinfo freeaddrinfo
#define su_gai_strerror gai_strerror
#endif
#if SU_HAVE_WINSOCK
......
This diff is collapsed.
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef SU_ADDRINFO_H /* Defined when <su_addrinfo.h> has been included */
#define SU_ADDRINFO_H
#ifndef SU_TYPES_H
#include <su_types.h>
#endif
#if !SU_HAVE_GETADDRINFO
/*
* Error return codes from getaddrinfo()
*/
#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
#define EAI_AGAIN 2 /* temporary failure in name resolution */
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
#define EAI_FAMILY 5 /* ai_family not supported */
#define EAI_MEMORY 6 /* memory allocation failure */
#define EAI_NODATA 7 /* no address associated with hostname */
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
#define EAI_SYSTEM 11 /* system error returned in errno */
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_MAX 14
#endif
/*
* Flag values for getaddrinfo()
*/
#ifndef AI_PASSIVE
#define AI_PASSIVE 0x00000001 /* get address to use bind() */
#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
/* valid flags for addrinfo */
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
/* special recommended flags for getipnodebyname */
#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
#endif
/*
* Constants for getnameinfo()
*/
#ifndef NI_MAXHOST
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
#endif
/*
* Flag values for getnameinfo()
*/
#ifndef NI_NOFQDN
#define NI_NOFQDN 0x00000001
#define NI_NUMERICHOST 0x00000002
#define NI_NAMEREQD 0x00000004
#define NI_NUMERICSERV 0x00000008
#define NI_DGRAM 0x00000010
#endif
struct addrinfo {
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
size_t ai_addrlen; /* length of ai_addr */
char *ai_canonname; /* canonical name for hostname */
struct sockaddr *ai_addr; /* binary address */
struct addrinfo *ai_next; /* next structure in linked list */
};
/** 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,
su_addrinfo_t **res);
/** Free su_addrinfo_t structure allocated by su_getaddrinfo(). */
void su_freeaddrinfo(su_addrinfo_t *res);
/** Return string describing address translation error. */
char const *su_gai_strerror(int errcode);
union su_sockaddr_u;
int
su_getnameinfo(const union su_sockaddr_u *su, size_t sulen,
char *host, size_t hostlen,
char *serv, size_t servlen,
int flags);
#endif /* !defined(SU_ADDRINFO_H) */
......@@ -61,6 +61,9 @@
/** Define as 1 if you have sa_len field in struct sockaddr */
#undef SU_HAVE_SOCKADDR_SA_LEN
/** Define as 1 if you have getaddrinfo() function. */
#undef SU_HAVE_GETADDRINFO
/** Define as 1 if you have Winsock interface */
#undef SU_HAVE_WINSOCK
/** Define as 1 if you have Winsock2 interface */
......
......@@ -1148,9 +1148,9 @@ int li_name(su_localinfo_t const *hints,
if (flags & LI_NUMERIC)
gni_flags |= NI_NUMERICHOST;
error = getnameinfo(&su->su_sa, su_sockaddr_size(su),
name, sizeof(name), NULL, 0,
gni_flags);
error = su_getnameinfo(su, su_sockaddr_size(su),
name, sizeof(name), NULL, 0,
gni_flags);
if (error) {
if ((flags & LI_NAMEREQD) == LI_NAMEREQD)
return 1;
......
......@@ -44,8 +44,8 @@
#include "su_time.h"
#endif
#if SU_HAVE_POLL
#include <stropts.h> /* stream operations */
#include <poll.h> /* poll is part of streams */
//#include <stropts.h> /* stream operations */
#include <sys/poll.h> /* poll is part of streams */
#endif
/* ---------------------------------------------------------------------- */
......
......@@ -188,7 +188,7 @@ AC_SUBST(GLIB_VERSION)
# ===========================================================================
AC_CHECK_FUNCS(gettimeofday strerror random initstate tcsetattr flock alarm)
AC_CHECK_FUNCS(socketpair gethostname getipnodebyname getaddrinfo poll)
AC_CHECK_FUNCS(socketpair gethostname getipnodebyname poll)
if false; then
# not yet
......@@ -206,6 +206,11 @@ fi
SAC_REPLACE_FUNCS(memmem memccpy memspn memcspn strcasestr strtoull)
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.
......@@ -257,7 +262,7 @@ _ACEOF
])
AC_DEFUN([SAC_REPLACE_FUNCS],[dnl
AC_CHECK_FUNCS($1,,[dnl
AC_CHECK_FUNCS($1,ifelse([$2], , :, [$2]),[dnl
case "$REPLACE_LIBADD" in
"$ac_func.lo" | \
*" $ac_func.lo" | \
......@@ -266,4 +271,5 @@ case "$REPLACE_LIBADD" in
*) REPLACE_LIBADD="$REPLACE_LIBADD $ac_func.lo" ;;
esac])
AC_SUBST([REPLACE_LIBADD])
ifelse([$3], , :, [$3])
])
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