#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
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 **);
#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.
*
*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) {
return error;
}
+#endif
+
/** Free local address information.
*
* Free a list of su_localinfo_t structures obtained with su_getlocalinfo()
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;
}
- 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) {
err:
if (canonname) free(canonname);
- if (li_first) free(li_first);
- su_freelocalinfo(tbf);
+ if (li) free(li);
su_close(s);
return error;
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;
#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
}
#endif
-
-#if HAVE_GETIFADDRS
+#if !USE_LOCALINFO0
+/* no localinfo0() or bsd_localinfo() */
+#elif HAVE_GETIFADDRS
#include <ifaddrs.h>
}
#elif HAVE_SIO_ADDRESS_LIST_QUERY
+
static
int localinfo0(su_localinfo_t const *hints, su_localinfo_t **rresult)
{
}
#endif
+#if !SU_LOCALINFO_TEST
+
static
int li_name(su_localinfo_t const *hints,
int gni_flags,
}
}
+#endif
+
/**Get local IP address.
*
* @deprecated