1 /* For terms of usage/redistribution/modification see the LICENSE file */
2 /* For authors and contributors see the AUTHORS file */
6 promisc.c - handles the promiscuous mode flag for the Ethernet/FDDI/
11 #include "iptraf-ng-compat.h"
17 static void promisc_add_dev(struct list_head
*promisc
, const char *dev_name
)
19 struct promisc_list
*p
= xmallocz(sizeof(*p
));
20 strcpy(p
->ifname
, dev_name
);
21 INIT_LIST_HEAD(&p
->list
);
23 list_add_tail(&p
->list
, promisc
);
26 void promisc_init(struct list_head
*promisc
, const char *device_name
)
29 int flags
= dev_promisc_flag(device_name
);
33 promisc_add_dev(promisc
, device_name
);
38 FILE *fp
= open_procnetdev();
40 die_errno("%s: open_procnetdev", __func__
);
42 char dev_name
[IFNAMSIZ
];
43 while (get_next_iface(fp
, dev_name
, sizeof(dev_name
))) {
44 if (!strcmp(dev_name
, ""))
47 int flags
= dev_promisc_flag(dev_name
);
51 promisc_add_dev(promisc
, dev_name
);
57 void promisc_set_list(struct list_head
*promisc
)
59 struct promisc_list
*entry
= NULL
;
60 list_for_each_entry(entry
, promisc
, list
) {
61 int r
= dev_set_promisc(entry
->ifname
);
63 write_error("Failed to set promiscuous mode on %s", entry
->ifname
);
67 void promisc_restore_list(struct list_head
*promisc
)
69 struct promisc_list
*entry
= NULL
;
70 list_for_each_entry(entry
, promisc
, list
) {
71 int r
= dev_clr_promisc(entry
->ifname
);
73 write_error("Failed to clear promiscuous mode on %s", entry
->ifname
);
77 void promisc_destroy(struct list_head
*promisc
)
79 struct promisc_list
*entry
, *tmp
;
80 list_for_each_entry_safe(entry
, tmp
, promisc
, list
) {
81 list_del(&entry
->list
);