From: Guy Harris Date: Fri, 9 Dec 2011 06:50:56 +0000 (-0800) Subject: Arrange to have pcap_close_all() earlier. X-Git-Tag: libpcap-1.3-bp~19 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/ebdced89b8f78534a9df2fd35c31fc2bed4d1616?ds=sidebyside Arrange to have pcap_close_all() earlier. Do so before we put the adapter into monitor mode, so that if we can't arrange to clean up monitor mode on exit, we don't try to put the adapter into monitor mode. --- diff --git a/pcap-linux.c b/pcap-linux.c index e0238142..d4f50b7d 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -861,6 +861,18 @@ added: nanosleep(&delay, NULL); #endif + /* + * If we haven't already done so, arrange to have + * "pcap_close_all()" called when we exit. + */ + if (!pcap_do_addexit(handle)) { + /* + * "atexit()" failed; don't put the interface + * in rfmon mode, just give up. + */ + return PCAP_ERROR_RFMON_NOTSUP; + } + /* * Now configure the monitor interface up. */ @@ -902,18 +914,6 @@ added: */ pcap_add_to_pcaps_to_close(handle); - /* - * If we haven't already done so, arrange to have - * "pcap_close_all()" called when we exit. - */ - if (!pcap_do_addexit(handle)) { - /* - * "atexit()" failed; don't put the interface - * in rfmon mode, just give up. - */ - return PCAP_ERROR_RFMON_NOTSUP; - } - return 1; } #endif /* HAVE_LIBNL */