diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-07-18 02:34:45 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-07-18 02:34:45 +0000 |
commit | c7cbe51e76656d6f3278ec6514c6a168232b7933 (patch) | |
tree | 8543e3b248e90fd2174e0abb38767900a02d0093 /pcap-util.c | |
parent | 860750fb903d286bb037848f9da0127df9d46007 (diff) | |
download | wireshark-c7cbe51e76656d6f3278ec6514c6a168232b7933.tar.gz wireshark-c7cbe51e76656d6f3278ec6514c6a168232b7933.tar.bz2 wireshark-c7cbe51e76656d6f3278ec6514c6a168232b7933.zip |
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()".
svn path=/trunk/; revision=11402
Diffstat (limited to 'pcap-util.c')
-rw-r--r-- | pcap-util.c | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/pcap-util.c b/pcap-util.c index 72d369a5a6..a1e9feb8cf 100644 --- a/pcap-util.c +++ b/pcap-util.c @@ -189,42 +189,48 @@ if_info_new(char *name, char *description) if_info->description = NULL; else if_info->description = g_strdup(description); - if_info->ip_addr = NULL; - if_info->loopback = FALSE; + if_info->ip_addr = NULL; + if_info->loopback = FALSE; return if_info; } - -/* get all ip address information from the given interface */ -static void if_info_ip(if_info_t *if_info, pcap_if_t *d) +void +if_info_add_address(if_info_t *if_info, struct sockaddr *addr) { - pcap_addr_t *a; - guint32 *ip_addr; - - /* Loopback interface */ - if_info->loopback = (d->flags & PCAP_IF_LOOPBACK) ? TRUE : FALSE; - - /* All addresses */ - for(a=d->addresses;a;a=a->next) { - switch(a->addr->sa_family) - { - /* IPv4 address */ - case AF_INET: - 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; - } - } -} + struct sockaddr_in *ai; + guint32 *ip_addr; + + switch (addr->sa_family) { + case AF_INET: + ai = (struct sockaddr_in *)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; + } +} #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 * get_interface_list_findalldevs(int *err, char *err_str) { |