From 36900f298b1a6946fcb1e633acdc98673c00f803 Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Sat, 9 Jul 2022 14:38:14 +0200 Subject: [PATCH] Fall back to non-promiscous mode on error --- ethsock.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ethsock.c b/ethsock.c index bff4c19..c77911a 100644 --- a/ethsock.c +++ b/ethsock.c @@ -599,6 +599,7 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol) struct ethsock *sock; bool is_bridge = false; int err; + int promisc; #ifdef NMRPFLASH_WINDOWS intf = intf_name_to_wpcap(intf); @@ -616,11 +617,21 @@ struct ethsock *ethsock_create(const char *intf, uint16_t protocol) buf[0] = '\0'; sock->intf = intf; - sock->pcap = pcap_open_live(sock->intf, BUFSIZ, 1, 1, buf); - if (!sock->pcap) { - fprintf(stderr, "%s.\n", buf); - goto cleanup; - } + promisc = true; + + do { + sock->pcap = pcap_open_live(sock->intf, BUFSIZ, promisc, 1, buf); + if (!sock->pcap) { + if (!promisc) { + fprintf(stderr, "Error: %s.\n", buf); + goto cleanup; + } else { + fprintf(stderr, "Warning: failed to enable promiscous mode.\n"); + promisc = false; + continue; + } + } + } while (!sock->pcap); if (*buf) { fprintf(stderr, "Warning: %s.\n", buf);