capt_get_packet(): check for key press only every 20ms
[iptraf-ng.git] / src / promisc.c
blobffab126fd20e6c31350165f98e8cf6c1a4ddc7a8
1 /* For terms of usage/redistribution/modification see the LICENSE file */
2 /* For authors and contributors see the AUTHORS file */
4 /***
6 promisc.c - handles the promiscuous mode flag for the Ethernet/FDDI/
7 Token Ring interfaces
9 ***/
11 #include "iptraf-ng-compat.h"
13 #include "ifaces.h"
14 #include "error.h"
15 #include "promisc.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)
28 if (device_name) {
29 int flags = dev_promisc_flag(device_name);
30 if (flags < 0)
31 return;
33 promisc_add_dev(promisc, device_name);
35 return;
38 FILE *fp = open_procnetdev();
39 if (!fp)
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, ""))
45 continue;
47 int flags = dev_promisc_flag(dev_name);
48 if (flags < 0)
49 continue;
51 promisc_add_dev(promisc, dev_name);
54 fclose(fp);
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);
62 if (r < 0)
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);
72 if (r < 0)
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);
82 free(entry);