From 9c38f171626c2973bd7c47f95912bdb885e9848c Mon Sep 17 00:00:00 2001 From: chris <> Date: Mon, 21 Oct 2002 10:31:40 +0000 Subject: [PATCH] "" --- options.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/options.c b/options.c index 1520b8f..59cd453 100644 --- a/options.c +++ b/options.c @@ -23,6 +23,27 @@ char optstr[] = "+i:f:n:dhpbP"; /* Global options. */ +/* Selecting an interface on which to listen: */ + +/* This is a list of interface name prefixes which are `bad' in the sense + * that they don't refer to interfaces of external type on which we are + * likely to want to listen. We also compare candidate interfaces to lo. */ +static char *bad_interface_names[] = { + "dummy", + "vmnet", + NULL /* last entry must be NULL */ + }; + +static int is_bad_interface_name(char *i) { + char **p; + for (p = bad_interface_names; *p; ++p) + if (strncmp(i, *p, strlen(*p)) == 0) + return 1; + return 0; +} + +/* This finds the first interface which is up and is not the loopback + * interface or one of the interface types listed in bad_interface_names. */ static char *get_first_interface(void) { int s, size = 1; struct ifreq *ifr; @@ -43,9 +64,7 @@ static char *get_first_interface(void) { } while (size * sizeof *ifc.ifc_req <= ifc.ifc_len); /* Ugly. */ for (ifr = ifc.ifc_req; (char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len; ++ifr) { - if (strcmp(ifr->ifr_name, "lo") != 0 - && strncmp(ifr->ifr_name, "dummy", 5) != 0 - && strncmp(ifr->ifr_name, "vmnet", 5) != 0 + if (strcmp(ifr->ifr_name, "lo") != 0 && !is_bad_interface_name(ifr->ifr_name) && ioctl(s, SIOCGIFFLAGS, ifr) == 0 && ifr->ifr_flags & IFF_UP) { i = xstrdup(ifr->ifr_name); break; @@ -137,7 +156,7 @@ static void usage(FILE *fp) { " -p run in promiscuous mode (show traffic between other\n" " hosts on the same network segment)\n" " -b don't display a bar graph of traffic\n" -" -i interface listen on named interface (default: eth0)\n" +" -i interface listen on named interface\n" " -f filter code use filter code to select packets to count\n" " (default: none, but only IP packets are counted)\n" " -n net/mask show traffic flows in/out of network\n"