Commit 199dc4be authored by Pekka Pessi's avatar Pekka Pessi

su_localinfo.c: using SU_LOCALINFO_TEST

darcs-hash:20090113222006-db55f-7754f5133136a84da3bbe835dba65d8073eec40d.gz
parent 7181c156
......@@ -67,7 +67,11 @@
#include <net/if_types.h>
#endif
#if HAVE_GETIFADDRS
#if SU_LOCALINFO_TEST
#undef USE_LOCALINFO0
#elif HAVE_GETIFADDRS
#define USE_LOCALINFO0 1
#define localinfo0 bsd_localinfo
......@@ -81,6 +85,7 @@ static int bsd_localinfo(su_localinfo_t const *, su_localinfo_t **);
static int win_localinfo(su_localinfo_t const *, su_localinfo_t **);
#else
/* No localinfo0(), use localinfo4() and localinfo6() */
#undef USE_LOCALINFO0
static int localinfo4(su_localinfo_t const *, su_localinfo_t **);
......@@ -90,9 +95,13 @@ static int localinfo6(su_localinfo_t const *, su_localinfo_t **);
#endif
static int li_scope4(uint32_t ip4);
static int li_scope6(struct in6_addr const *ip6);
#if !SU_LOCALINFO_TEST
static int li_name(su_localinfo_t const*, int, su_sockaddr_t const*, char **);
static void li_sort(su_localinfo_t *i, su_localinfo_t **rresult);
static int li_scope4(uint32_t ip4);
/** @brief Request local address information.
*
......@@ -196,8 +205,13 @@ int su_getlocalinfo(su_localinfo_t const *hints,
*hh = *hints;
if (hh->li_canonname)
hh->li_flags |= LI_CANONNAME;
#if 0
/* hints->li_ifname is used to select by interface,
li_ifname is returned with LI_IFNAME flag
*/
if ((hh->li_flags & LI_IFNAME) && hh->li_ifname == NULL)
return ELI_BADHINTS;
#endif
}
switch (hh->li_family) {
......@@ -255,6 +269,8 @@ int su_getlocalinfo(su_localinfo_t const *hints,
return error;
}
#endif
/** Free local address information.
*
* Free a list of su_localinfo_t structures obtained with su_getlocalinfo()
......@@ -415,16 +431,17 @@ int su_sockaddr_scope(su_sockaddr_t const *su, socklen_t sulen)
extern int su_get_local_ip_addr(su_sockaddr_t *su);
#endif
#if USE_LOCALINFO0
#if SU_LOCALINFO_TEST
#elif USE_LOCALINFO0
/* no localinfo4 */
#elif HAVE_IFCONF
#if __APPLE_CC__
/** Build a list of local IPv4 addresses and append it to *rresult. */
static
int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult)
{
su_localinfo_t *tbf = NULL, **lli = &tbf;
su_localinfo_t *li = NULL, *li_first = NULL;
su_localinfo_t *li = NULL;
su_sockaddr_t *su;
int error = ELI_NOADDRESS;
char *canonname = NULL;
......@@ -453,8 +470,8 @@ int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult)
}
li = calloc(1, sizeof(su_localinfo_t));
sa = calloc(1, sizeof(su_sockaddr_t));
li = calloc(1, (sizeof *li) + (sizeof *sa));
sa = (void *)(li + 1);
error = getsockname(s, (struct sockaddr *) sa, &salen);
if (error < 0 && errno == SOCKET_ERROR) {
......@@ -511,8 +528,7 @@ int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult)
err:
if (canonname) free(canonname);
if (li_first) free(li_first);
su_freelocalinfo(tbf);
if (li) free(li);
su_close(s);
return error;
......@@ -772,8 +788,7 @@ int localinfo4(su_localinfo_t const *hints, su_localinfo_t **rresult)
li->li_addrlen = su_sockaddr_size(su);
li->li_addr = su;
li->li_canonname = canonname;
if (hints->li_flags & LI_IFNAME)
li->li_ifname = if_name;
li->li_ifname = if_name;
canonname = NULL;
li_first = NULL;
......@@ -917,8 +932,8 @@ err:
#endif
#if USE_LOCALINFO0 || !SU_HAVE_IN6
#if USE_LOCALINFO0 || !SU_HAVE_IN6 || SU_LOCALINFO_TEST
/* No localinfo6() */
#elif HAVE_PROC_NET_IF_INET6
/** Build a list of local IPv6 addresses and append it to *return_result. */
static
......@@ -1128,8 +1143,9 @@ err:
}
#endif
#if HAVE_GETIFADDRS
#if !USE_LOCALINFO0
/* no localinfo0() or bsd_localinfo() */
#elif HAVE_GETIFADDRS
#include <ifaddrs.h>
......@@ -1455,6 +1471,7 @@ err:
}
#elif HAVE_SIO_ADDRESS_LIST_QUERY
static
int localinfo0(su_localinfo_t const *hints, su_localinfo_t **rresult)
{
......@@ -1572,6 +1589,8 @@ err:
}
#endif
#if !SU_LOCALINFO_TEST
static
int li_name(su_localinfo_t const *hints,
int gni_flags,
......@@ -1639,6 +1658,8 @@ void li_sort(su_localinfo_t *i, su_localinfo_t **rresult)
}
}
#endif
/**Get local IP address.
*
* @deprecated
......
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