Tue Jan 13 16:20:06 CST 2009 Pekka Pessi <first.last@nokia.com>

* su_localinfo.c: using SU_LOCALINFO_TEST



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11819 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-02-11 16:57:55 +00:00
parent b8b13a8a8a
commit 2fb33f1857
1 changed files with 36 additions and 15 deletions

View File

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