Commit 9c38f171 authored by chris's avatar chris

""

parent c280b1f7
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment