3
promisc.c - handles the promiscuous mode flag for the Ethernet/FDDI
3
promisc.c - handles the promiscuous mode flag for the Ethernet/FDDI/
6
6
Written by Gerard Paul Java
7
Copyright (c) Gerard Paul Java 1997, 1998
7
Copyright (c) Gerard Paul Java 1997, 2002
9
9
This module contains functions that manage the promiscuous states of
62
62
fd = open_procnetdev();
65
get_next_iface(fd, buf);
67
if (strcmp(buf, "") != 0) {
68
ptmp = malloc(sizeof(struct promisc_states));
69
strcpy(ptmp->params.ifname, buf);
74
tail->next_entry = ptmp;
77
ptmp->next_entry = NULL;
80
* Retrieve and save interface flags
83
if ((strncmp(buf, "eth", 3) == 0) ||
84
(strncmp(buf, "vlan", 4) == 0) ||
85
(strncmp(buf, "fddi", 4) == 0) ||
86
(strncmp(ptmp->params.ifname, "wvlan", 4) == 0) ||
87
(strncmp(ptmp->params.ifname, "lec", 3) == 0) ||
88
(accept_unsupported_interfaces)) {
89
strcpy(ifr.ifr_name, buf);
91
istat = ioctl(ifd, SIOCGIFFLAGS, &ifr);
95
"Unable to obtain interface parameters for %s",
97
write_error(err_msg, daemonized);
98
ptmp->params.state_valid = 0;
100
ptmp->params.saved_state = ifr.ifr_flags;
101
ptmp->params.state_valid = 1;
65
get_next_iface(fd, buf);
67
if (strcmp(buf, "") != 0) {
68
ptmp = malloc(sizeof(struct promisc_states));
69
strcpy(ptmp->params.ifname, buf);
74
tail->next_entry = ptmp;
77
ptmp->next_entry = NULL;
80
* Retrieve and save interface flags
83
if ((strncmp(buf, "eth", 3) == 0) ||
84
(strncmp(buf, "ath", 3) == 0) ||
85
(strncmp(buf, "fddi", 4) == 0) ||
86
(strncmp(buf, "tr", 2) == 0) ||
87
(strncmp(ptmp->params.ifname, "wvlan", 4) == 0) ||
88
(strncmp(ptmp->params.ifname, "lec", 3) == 0) ||
89
(accept_unsupported_interfaces)) {
90
strcpy(ifr.ifr_name, buf);
92
istat = ioctl(ifd, SIOCGIFFLAGS, &ifr);
96
"Unable to obtain interface parameters for %s",
98
write_error(err_msg, daemonized);
99
ptmp->params.state_valid = 0;
101
ptmp->params.saved_state = ifr.ifr_flags;
102
ptmp->params.state_valid = 1;
105
106
} while (strcmp(buf, "") != 0);
121
122
fd = open(PROMISCLISTFILE, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
124
write_error("Unable to save interface flags", daemonized);
125
write_error("Unable to save interface flags", daemonized);
128
129
while (ptmp != NULL) {
129
write(fd, &(ptmp->params), sizeof(struct promisc_params));
130
ptmp = ptmp->next_entry;
130
write(fd, &(ptmp->params), sizeof(struct promisc_params));
131
ptmp = ptmp->next_entry;
147
148
fd = open(PROMISCLISTFILE, O_RDONLY);
150
write_error("Unable to retrieve saved interface flags",
151
write_error("Unable to retrieve saved interface flags",
157
ptmp = malloc(sizeof(struct promisc_states));
158
br = read(fd, &(ptmp->params), sizeof(struct promisc_params));
162
tail->next_entry = ptmp;
166
ptmp->next_entry = NULL;
158
ptmp = malloc(sizeof(struct promisc_states));
159
br = read(fd, &(ptmp->params), sizeof(struct promisc_params));
163
tail->next_entry = ptmp;
167
ptmp->next_entry = NULL;
170
171
} while (br > 0);
189
190
fd = socket(PF_INET, SOCK_DGRAM, 0);
192
write_error("Unable to open socket for flag change", daemonized);
193
write_error("Unable to open socket for flag change", daemonized);
196
197
while (ptmp != NULL) {
197
if (((strncmp(ptmp->params.ifname, "eth", 3) == 0) ||
198
(strncmp(ptmp->params.ifname, "vlan", 4) == 0) ||
199
(strncmp(ptmp->params.ifname, "fddi", 4) == 0) ||
200
(strncmp(ptmp->params.ifname, "wvlan", 4) == 0) ||
201
(strncmp(ptmp->params.ifname, "lec", 3) == 0)) &&
202
(ptmp->params.state_valid)) {
204
strcpy(ifr.ifr_name, ptmp->params.ifname);
207
ifr.ifr_flags = ptmp->params.saved_state | IFF_PROMISC;
209
ifr.ifr_flags = ptmp->params.saved_state;
211
istat = ioctl(fd, SIOCSIFFLAGS, &ifr);
214
sprintf(fullmsg, "Promisc change failed for %s",
215
ptmp->params.ifname);
216
write_error(fullmsg, daemonized);
219
ptmp = ptmp->next_entry;
198
if (((strncmp(ptmp->params.ifname, "eth", 3) == 0) ||
199
(strncmp(ptmp->params.ifname, "fddi", 4) == 0) ||
200
(strncmp(ptmp->params.ifname, "tr", 2) == 0) ||
201
(strncmp(ptmp->params.ifname, "wvlan", 4) == 0) ||
202
(strncmp(ptmp->params.ifname, "lec", 3) == 0)) &&
203
(ptmp->params.state_valid)) {
205
strcpy(ifr.ifr_name, ptmp->params.ifname);
208
ifr.ifr_flags = ptmp->params.saved_state | IFF_PROMISC;
210
ifr.ifr_flags = ptmp->params.saved_state;
212
istat = ioctl(fd, SIOCSIFFLAGS, &ifr);
215
sprintf(fullmsg, "Promisc change failed for %s",
216
ptmp->params.ifname);
217
write_error(fullmsg, daemonized);
220
ptmp = ptmp->next_entry;