Fall back to non-promiscous mode on error
This commit is contained in:
parent
784536c410
commit
36900f298b
1 changed files with 16 additions and 5 deletions
15
ethsock.c
15
ethsock.c
|
|
@ -599,6 +599,7 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
|
||||||
struct ethsock *sock;
|
struct ethsock *sock;
|
||||||
bool is_bridge = false;
|
bool is_bridge = false;
|
||||||
int err;
|
int err;
|
||||||
|
int promisc;
|
||||||
|
|
||||||
#ifdef NMRPFLASH_WINDOWS
|
#ifdef NMRPFLASH_WINDOWS
|
||||||
intf = intf_name_to_wpcap(intf);
|
intf = intf_name_to_wpcap(intf);
|
||||||
|
|
@ -616,11 +617,21 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol)
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
sock->intf = intf;
|
sock->intf = intf;
|
||||||
sock->pcap = pcap_open_live(sock->intf, BUFSIZ, 1, 1, buf);
|
promisc = true;
|
||||||
|
|
||||||
|
do {
|
||||||
|
sock->pcap = pcap_open_live(sock->intf, BUFSIZ, promisc, 1, buf);
|
||||||
if (!sock->pcap) {
|
if (!sock->pcap) {
|
||||||
fprintf(stderr, "%s.\n", buf);
|
if (!promisc) {
|
||||||
|
fprintf(stderr, "Error: %s.\n", buf);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Warning: failed to enable promiscous mode.\n");
|
||||||
|
promisc = false;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} while (!sock->pcap);
|
||||||
|
|
||||||
if (*buf) {
|
if (*buf) {
|
||||||
fprintf(stderr, "Warning: %s.\n", buf);
|
fprintf(stderr, "Warning: %s.\n", buf);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue