X-Git-Url: http://git.samba.org/samba.git/?p=obnox%2Fwireshark%2Fwip.git;a=blobdiff_plain;f=pcap-util.c;h=f2cb31cac6694475938bf6c3cd65bf524fbc1ffd;hp=30fb056491f751b22879f44e13d9c89cfea07153;hb=21bb66873389526d59e469e7aa47b216dac3142e;hpb=5ee8cc1ff1c55d509d2d9a0ff6573e85e0c204ae diff --git a/pcap-util.c b/pcap-util.c index 30fb056491..f2cb31cac6 100644 --- a/pcap-util.c +++ b/pcap-util.c @@ -1,7 +1,7 @@ /* pcap-util.c * Utility routines for packet capture * - * $Id: pcap-util.c,v 1.20 2003/11/21 08:30:40 guy Exp $ + * $Id$ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -28,6 +28,8 @@ #ifdef HAVE_LIBPCAP +#include + #include #include @@ -42,14 +44,17 @@ #include #endif -#include - #include #include #include "pcap-util.h" #include "pcap-util-int.h" +#ifndef _WIN32 +#include +#endif + + /* * Get the data-link type for a libpcap device. * This works around AIX 5.x's non-standard and incompatible-with-the- @@ -57,18 +62,18 @@ */ int get_pcap_linktype(pcap_t *pch, char *devname -#ifndef AIX +#ifndef _AIX _U_ #endif ) { int linktype; -#ifdef AIX +#ifdef _AIX char *ifacename; #endif linktype = pcap_datalink(pch); -#ifdef AIX +#ifdef _AIX /* * The libpcap that comes with AIX 5.x uses RFC 1573 ifType values @@ -120,7 +125,7 @@ get_pcap_linktype(pcap_t *pch, char *devname */ ifacename = strchr(devname, '/'); if (ifacename == NULL) - ifacename = devnames; + ifacename = devname; /* See if it matches any of the LAN device names. */ if (strncmp(ifacename, "en", 2) == 0) { @@ -184,10 +189,65 @@ 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; return if_info; } +void +if_info_add_address(if_info_t *if_info, struct sockaddr *addr) +{ + if_addr_t *ip_addr; + struct sockaddr_in *ai; +#ifdef INET6 + struct sockaddr_in6 *ai6; +#endif + + switch (addr->sa_family) { + + case AF_INET: + ai = (struct sockaddr_in *)addr; + ip_addr = g_malloc(sizeof(*ip_addr)); + ip_addr->type = AT_IPv4; + ip_addr->ip_addr.ip4_addr = + *((guint32 *)&(ai->sin_addr.s_addr)); + if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr); + break; + +#ifdef INET6 + case AF_INET6: + ai6 = (struct sockaddr_in6 *)addr; + ip_addr = g_malloc(sizeof(*ip_addr)); + ip_addr->type = AT_IPv6; + memcpy((void *)&ip_addr->ip_addr.ip6_addr, + (void *)&ai6->sin6_addr.s6_addr, + sizeof ip_addr->ip_addr.ip6_addr); + if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr); + break; +#endif + } +} + #ifdef HAVE_PCAP_FINDALLDEVS +/* + * Get all IP 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) { @@ -211,6 +271,7 @@ get_interface_list_findalldevs(int *err, char *err_str) for (dev = alldevs; dev != NULL; dev = dev->next) { if_info = if_info_new(dev->name, dev->description); il = g_list_append(il, if_info); + if_info_ip(if_info, dev); } pcap_freealldevs(alldevs); @@ -218,6 +279,12 @@ get_interface_list_findalldevs(int *err, char *err_str) } #endif /* HAVE_PCAP_FINDALLDEVS */ +static void +free_if_info_addr_cb(gpointer addr, gpointer user_data _U_) +{ + g_free(addr); +} + static void free_if_cb(gpointer data, gpointer user_data _U_) { @@ -226,6 +293,9 @@ free_if_cb(gpointer data, gpointer user_data _U_) g_free(if_info->name); if (if_info->description != NULL) g_free(if_info->description); + + g_slist_foreach(if_info->ip_addr, free_if_info_addr_cb, NULL); + g_slist_free(if_info->ip_addr); } void @@ -342,7 +412,11 @@ free_pcap_linktype_list(GList *linktype_list) /* Set the data link type on a pcap. */ const char * -set_pcap_linktype(pcap_t *pch, char *devname, int dlt) +set_pcap_linktype(pcap_t *pch, char *devname +#ifdef HAVE_PCAP_SET_DATALINK + _U_ +#endif + , int dlt) { #ifdef HAVE_PCAP_SET_DATALINK if (pcap_set_datalink(pch, dlt) == 0)