""
This commit is contained in:
27
options.c
27
options.c
@@ -23,6 +23,27 @@ char optstr[] = "+i:f:n:dhpbP";
|
|||||||
|
|
||||||
/* Global options. */
|
/* 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) {
|
static char *get_first_interface(void) {
|
||||||
int s, size = 1;
|
int s, size = 1;
|
||||||
struct ifreq *ifr;
|
struct ifreq *ifr;
|
||||||
@@ -43,9 +64,7 @@ static char *get_first_interface(void) {
|
|||||||
} while (size * sizeof *ifc.ifc_req <= ifc.ifc_len);
|
} while (size * sizeof *ifc.ifc_req <= ifc.ifc_len);
|
||||||
/* Ugly. */
|
/* Ugly. */
|
||||||
for (ifr = ifc.ifc_req; (char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len; ++ifr) {
|
for (ifr = ifc.ifc_req; (char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len; ++ifr) {
|
||||||
if (strcmp(ifr->ifr_name, "lo") != 0
|
if (strcmp(ifr->ifr_name, "lo") != 0 && !is_bad_interface_name(ifr->ifr_name)
|
||||||
&& strncmp(ifr->ifr_name, "dummy", 5) != 0
|
|
||||||
&& strncmp(ifr->ifr_name, "vmnet", 5) != 0
|
|
||||||
&& ioctl(s, SIOCGIFFLAGS, ifr) == 0 && ifr->ifr_flags & IFF_UP) {
|
&& ioctl(s, SIOCGIFFLAGS, ifr) == 0 && ifr->ifr_flags & IFF_UP) {
|
||||||
i = xstrdup(ifr->ifr_name);
|
i = xstrdup(ifr->ifr_name);
|
||||||
break;
|
break;
|
||||||
@@ -137,7 +156,7 @@ static void usage(FILE *fp) {
|
|||||||
" -p run in promiscuous mode (show traffic between other\n"
|
" -p run in promiscuous mode (show traffic between other\n"
|
||||||
" hosts on the same network segment)\n"
|
" hosts on the same network segment)\n"
|
||||||
" -b don't display a bar graph of traffic\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"
|
" -f filter code use filter code to select packets to count\n"
|
||||||
" (default: none, but only IP packets are counted)\n"
|
" (default: none, but only IP packets are counted)\n"
|
||||||
" -n net/mask show traffic flows in/out of network\n"
|
" -n net/mask show traffic flows in/out of network\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user