forked from osmocom/wireshark
Get IPv4 addresses and the loopback flag if we don't have
"pcap_findalldevs()". "if_info_ip()" is used - and can be compiled - only if libpcap has "pcap_findalldevs()". git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@11402 f5534014-38df-0310-8fa8-9805f1628bb7
This commit is contained in:
parent
cd32934f2f
commit
c7fda4c574
|
@ -28,6 +28,7 @@
|
||||||
#ifdef HAVE_LIBPCAP
|
#ifdef HAVE_LIBPCAP
|
||||||
|
|
||||||
extern if_info_t *if_info_new(char *name, char *description);
|
extern if_info_t *if_info_new(char *name, char *description);
|
||||||
|
extern void if_info_add_address(if_info_t *if_info, struct sockaddr *addr);
|
||||||
#ifdef HAVE_PCAP_FINDALLDEVS
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
||||||
extern GList *get_interface_list_findalldevs(int *err, char *err_str);
|
extern GList *get_interface_list_findalldevs(int *err, char *err_str);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -68,7 +68,7 @@ struct rtentry;
|
||||||
#ifndef HAVE_PCAP_FINDALLDEVS
|
#ifndef HAVE_PCAP_FINDALLDEVS
|
||||||
struct search_user_data {
|
struct search_user_data {
|
||||||
char *name;
|
char *name;
|
||||||
int found;
|
if_info_t *if_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -135,7 +135,7 @@ get_interface_list(int *err, char *err_str)
|
||||||
last = (struct ifreq *) ((char *) ifr + ifc.ifc_len);
|
last = (struct ifreq *) ((char *) ifr + ifc.ifc_len);
|
||||||
while (ifr < last) {
|
while (ifr < last) {
|
||||||
/*
|
/*
|
||||||
* Skip addresses that begin with "dummy", or that include
|
* Skip entries that begin with "dummy", or that include
|
||||||
* a ":" (the latter are Solaris virtuals).
|
* a ":" (the latter are Solaris virtuals).
|
||||||
*/
|
*/
|
||||||
if (strncmp(ifr->ifr_name, "dummy", 5) == 0 ||
|
if (strncmp(ifr->ifr_name, "dummy", 5) == 0 ||
|
||||||
|
@ -144,16 +144,19 @@ get_interface_list(int *err, char *err_str)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we already have this interface name on the list,
|
* If we already have this interface name on the list,
|
||||||
* don't add it (SIOCGIFCONF returns, at least on
|
* don't add it, but, if we don't already have an IPv4
|
||||||
* BSD-flavored systems, one entry per interface *address*;
|
* address for it, add that address (SIOCGIFCONF returns,
|
||||||
* if an interface has multiple addresses, we get multiple
|
* at least on BSD-flavored systems, one entry per
|
||||||
* entries for it).
|
* interface *address*; if an interface has multiple
|
||||||
|
* addresses, we get multiple entries for it).
|
||||||
*/
|
*/
|
||||||
user_data.name = ifr->ifr_name;
|
user_data.name = ifr->ifr_name;
|
||||||
user_data.found = FALSE;
|
user_data.if_info = NULL;
|
||||||
g_list_foreach(il, search_for_if_cb, &user_data);
|
g_list_foreach(il, search_for_if_cb, &user_data);
|
||||||
if (user_data.found)
|
if (user_data.if_info != NULL) {
|
||||||
|
if_info_add_address(user_data.if_info, &ifr->ifr_addr);
|
||||||
goto next;
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the interface flags.
|
* Get the interface flags.
|
||||||
|
@ -195,10 +198,13 @@ get_interface_list(int *err, char *err_str)
|
||||||
* device unless there are no non-loopback devices.
|
* device unless there are no non-loopback devices.
|
||||||
*/
|
*/
|
||||||
if_info = if_info_new(ifr->ifr_name, NULL);
|
if_info = if_info_new(ifr->ifr_name, NULL);
|
||||||
|
if_info_add_address(if_info, &ifr->ifr_addr);
|
||||||
if ((ifrflags.ifr_flags & IFF_LOOPBACK) ||
|
if ((ifrflags.ifr_flags & IFF_LOOPBACK) ||
|
||||||
strncmp(ifr->ifr_name, "lo", 2) == 0)
|
strncmp(ifr->ifr_name, "lo", 2) == 0) {
|
||||||
|
if_info->loopback = TRUE;
|
||||||
il = g_list_append(il, if_info);
|
il = g_list_append(il, if_info);
|
||||||
else {
|
} else {
|
||||||
|
if_info->loopback = FALSE;
|
||||||
il = g_list_insert(il, if_info, nonloopback_pos);
|
il = g_list_insert(il, if_info, nonloopback_pos);
|
||||||
/*
|
/*
|
||||||
* Insert the next non-loopback interface after this
|
* Insert the next non-loopback interface after this
|
||||||
|
@ -266,7 +272,7 @@ search_for_if_cb(gpointer data, gpointer user_data)
|
||||||
if_info_t *if_info = data;
|
if_info_t *if_info = data;
|
||||||
|
|
||||||
if (strcmp(if_info->name, search_user_data->name) == 0)
|
if (strcmp(if_info->name, search_user_data->name) == 0)
|
||||||
search_user_data->found = TRUE;
|
search_user_data->if_info = if_info;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_PCAP_FINDALLDEVS */
|
#endif /* HAVE_PCAP_FINDALLDEVS */
|
||||||
|
|
||||||
|
|
60
pcap-util.c
60
pcap-util.c
|
@ -189,42 +189,48 @@ if_info_new(char *name, char *description)
|
||||||
if_info->description = NULL;
|
if_info->description = NULL;
|
||||||
else
|
else
|
||||||
if_info->description = g_strdup(description);
|
if_info->description = g_strdup(description);
|
||||||
if_info->ip_addr = NULL;
|
if_info->ip_addr = NULL;
|
||||||
if_info->loopback = FALSE;
|
if_info->loopback = FALSE;
|
||||||
return if_info;
|
return if_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
/* get all ip address information from the given interface */
|
if_info_add_address(if_info_t *if_info, struct sockaddr *addr)
|
||||||
static void if_info_ip(if_info_t *if_info, pcap_if_t *d)
|
|
||||||
{
|
{
|
||||||
pcap_addr_t *a;
|
struct sockaddr_in *ai;
|
||||||
guint32 *ip_addr;
|
guint32 *ip_addr;
|
||||||
|
|
||||||
/* Loopback interface */
|
switch (addr->sa_family) {
|
||||||
if_info->loopback = (d->flags & PCAP_IF_LOOPBACK) ? TRUE : FALSE;
|
|
||||||
|
|
||||||
/* All addresses */
|
case AF_INET:
|
||||||
for(a=d->addresses;a;a=a->next) {
|
ai = (struct sockaddr_in *)addr;
|
||||||
switch(a->addr->sa_family)
|
ip_addr = g_malloc(sizeof(*ip_addr));
|
||||||
{
|
*ip_addr = *((guint32 *)&(ai->sin_addr.s_addr));
|
||||||
/* IPv4 address */
|
if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr);
|
||||||
case AF_INET:
|
break;
|
||||||
if (a->addr) {
|
}
|
||||||
struct sockaddr_in *ai = ((struct sockaddr_in *)(a->addr));
|
|
||||||
ip_addr = g_malloc(sizeof(*ip_addr));
|
|
||||||
*ip_addr = *((guint32 *)&(ai->sin_addr.s_addr));
|
|
||||||
if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_PCAP_FINDALLDEVS
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
||||||
|
/*
|
||||||
|
* Get all IPv4 address information, and the loopback flag, for the given
|
||||||
|
* interface.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
if_info_ip(if_info_t *if_info, pcap_if_t *d)
|
||||||
|
{
|
||||||
|
pcap_addr_t *a;
|
||||||
|
|
||||||
|
/* Loopback flag */
|
||||||
|
if_info->loopback = (d->flags & PCAP_IF_LOOPBACK) ? TRUE : FALSE;
|
||||||
|
|
||||||
|
/* All addresses */
|
||||||
|
for (a = d->addresses; a != NULL; a = a->next) {
|
||||||
|
if (a->addr != NULL)
|
||||||
|
if_info_add_address(if_info, a->addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GList *
|
GList *
|
||||||
get_interface_list_findalldevs(int *err, char *err_str)
|
get_interface_list_findalldevs(int *err, char *err_str)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue