aboutsummaryrefslogtreecommitdiff
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-04-22 22:20:45 -0700
committerGuy Harris <guy@alum.mit.edu>2014-04-22 22:20:45 -0700
commit8fca0afd122bd0eb3c4776e0e027bb22639f5e5c (patch)
tree8463a3bc760326a263eaadc2b3c3429c52423c1f /pcap-linux.c
parent53e0bc9f651a4bbd83b5b2ead444fc8c184b0767 (diff)
In activate routines, don't set status unless a warning or error occurs.
This makes the code a bit clearer, as you don't have to worry about the status variable accidentally being set to an inappropriate value, overriding a warning that's been put there.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index 9ff71ee9..67874ae4 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -1235,6 +1235,7 @@ pcap_activate_linux(pcap_t *handle)
const char *device;
struct ifreq ifr;
int status = 0;
+ int ret;
device = handle->opt.source;
@@ -1306,16 +1307,17 @@ pcap_activate_linux(pcap_t *handle)
* to be compatible with older kernels for a while so we are
* trying both methods with the newer method preferred.
*/
- status = activate_new(handle);
- if (status < 0) {
+ ret = activate_new(handle);
+ if (ret < 0) {
/*
* Fatal error with the new way; just fail.
- * status has the error return; if it's PCAP_ERROR,
+ * ret has the error return; if it's PCAP_ERROR,
* handle->errbuf has been set appropriately.
*/
+ status = ret;
goto fail;
}
- if (status == 1) {
+ if (ret == 1) {
/*
* Success.
* Try to use memory-mapped access.
@@ -1342,21 +1344,23 @@ pcap_activate_linux(pcap_t *handle)
/*
* We failed to set up to use it, or the kernel
* supports it, but we failed to enable it.
- * status has been set to the error status to
+ * ret has been set to the error status to
* return and, if it's PCAP_ERROR, handle->errbuf
* contains the error message.
*/
+ status = ret;
goto fail;
}
}
- else if (status == 0) {
+ else if (ret == 0) {
/* Non-fatal error; try old way */
- if ((status = activate_old(handle)) != 1) {
+ if ((ret = activate_old(handle)) != 1) {
/*
* Both methods to open the packet socket failed.
* Tidy up and report our failure (handle->errbuf
* is expected to be set by the functions above).
*/
+ status = ret;
goto fail;
}
}
@@ -1364,7 +1368,6 @@ pcap_activate_linux(pcap_t *handle)
/*
* We set up the socket, but not with memory-mapped access.
*/
- status = 0;
if (handle->opt.buffer_size != 0) {
/*
* Set the socket buffer size to the specified value.