summaryrefslogtreecommitdiff
path: root/tcpdump.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-11-23 19:28:01 -0800
committerGuy Harris <guy@alum.mit.edu>2019-11-23 19:28:17 -0800
commitcbd0d78fce1b7ef6019cb6cb7c3b2dc3393bdbd2 (patch)
tree411bafb4ed6d01f86139736f0ca2a63471a17d55 /tcpdump.c
parent6f531302736fa22264dce423234deeb4d5a4fed6 (diff)
downloadtcpdump-cbd0d78fce1b7ef6019cb6cb7c3b2dc3393bdbd2.tar.gz
Move some code to better show how to handle pcap_activate() failure.
If you call pcap_activate() and it fails, you still have a pcap_t from pcap_create(), and should close it. Moving the code after the error() calls doesn't make a difference, as error() exits, but it may make it clearer to those reading tcpdump.c for help in figuring out how to use libpcap that you should close the pcap_t if pcap_activate() fails. (In the future, there may also be the option of changing some options and trying again, e.g. changing the user name or password for a remote capture.)
Diffstat (limited to 'tcpdump.c')
-rw-r--r--tcpdump.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/tcpdump.c b/tcpdump.c
index a44baa29..dfa340b6 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1347,8 +1347,6 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf)
*/
snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s\n(%s)",
device, pcap_statustostr(status), cp);
- pcap_close(pc);
- return (NULL);
} else if (status == PCAP_ERROR_PERM_DENIED && *cp != '\0')
error("%s: %s\n(%s)", device,
pcap_statustostr(status), cp);
@@ -1379,6 +1377,8 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf)
else
error("%s: %s", device,
pcap_statustostr(status));
+ pcap_close(pc);
+ return (NULL);
} else if (status > 0) {
/*
* pcap_activate() succeeded, but it's warning us