const char *device = handle->opt.device;
int is_any_device = (strcmp(device, "any") == 0);
int protocol = pcap_protocol(handle);
- int sock_fd = -1, arptype;
+ int sock_fd = -1, arptype, ret;
#ifdef HAVE_PACKET_AUXDATA
int val;
#endif
*/
return 0;
}
-
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
- errno, "socket");
if (errno == EPERM || errno == EACCES) {
/*
* You don't have permission to open the
* socket.
*/
- return PCAP_ERROR_PERM_DENIED;
+ ret = PCAP_ERROR_PERM_DENIED;
} else {
/*
* Other error.
*/
- return PCAP_ERROR;
+ ret = PCAP_ERROR;
}
+ pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "socket");
+ return ret;
}
/* It seems the kernel supports the new interface. */
}
sock_fd = socket(PF_PACKET, SOCK_DGRAM, protocol);
if (sock_fd == -1) {
- pcap_fmt_errmsg_for_errno(handle->errbuf,
- PCAP_ERRBUF_SIZE, errno, "socket");
if (errno == EPERM || errno == EACCES) {
/*
* You don't have permission to
* open the socket.
*/
- return PCAP_ERROR_PERM_DENIED;
+ ret = PCAP_ERROR_PERM_DENIED;
} else {
/*
* Other error.
*/
- return PCAP_ERROR;
+ ret = PCAP_ERROR;
}
+ pcap_fmt_errmsg_for_errno(handle->errbuf,
+ PCAP_ERRBUF_SIZE, errno, "socket");
+ return ret;
}
handlep->cooked = 1;
has_wext(int sock_fd, const char *device, char *ebuf)
{
struct iwreq ireq;
+ int ret;
if (is_bonding_device(sock_fd, device))
return 0; /* bonding device, so don't even try */
sizeof ireq.ifr_ifrn.ifrn_name);
if (ioctl(sock_fd, SIOCGIWNAME, &ireq) >= 0)
return 1; /* yes */
+ if (errno == ENODEV)
+ ret = PCAP_ERROR_NO_SUCH_DEVICE;
+ else
+ ret = 0;
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno,
"%s: SIOCGIWNAME", device);
- if (errno == ENODEV)
- return PCAP_ERROR_NO_SUCH_DEVICE;
- return 0;
+ return ret;
}
/*
iface_get_arptype(int fd, const char *device, char *ebuf)
{
struct ifreq ifr;
+ int ret;
memset(&ifr, 0, sizeof(ifr));
pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
- pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
- errno, "SIOCGIFHWADDR");
if (errno == ENODEV) {
/*
* No such device.
*/
- return PCAP_ERROR_NO_SUCH_DEVICE;
- }
- return PCAP_ERROR;
+ ret = PCAP_ERROR_NO_SUCH_DEVICE;
+ } else
+ ret = PCAP_ERROR;
+ pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
+ errno, "SIOCGIFHWADDR");
+ return ret;
}
return ifr.ifr_hwaddr.sa_family;
{
struct pcap_usb_linux *handlep = handle->priv;
char full_path[USB_LINE_LEN];
+ int ret;
/*
* Turn a negative snapshot value (invalid), a snapshot value of
handle->fd = open(full_path, O_RDONLY, 0);
}
if (handle->fd < 0) {
- /*
- * Is the problem that we didn't have
- * sufficient permission to open it?
- */
- if (errno == EACCES) {
+ if (errno == ENOENT)
+ {
/*
- * Yes - return that error.
+ * The problem is that the file
+ * doesn't exist. Report that as
+ * "no such device". (That could
+ * mean "no such USB bus" or
+ * "monitoring not supported".)
*/
- return PCAP_ERROR_PERM_DENIED;
+ ret = PCAP_ERROR_NO_SUCH_DEVICE;
}
-
- /*
- * No - was the problem something other
- * than "it doesn't exist"?
- */
- if (errno != ENOENT) {
+ else if (errno == EACCES)
+ {
/*
- * Yes - return *that* error.
+ * The problem is that we don't
+ * have sufficient permission to
+ * open the file. Report that.
*/
- pcap_fmt_errmsg_for_errno(handle->errbuf,
- PCAP_ERRBUF_SIZE, errno,
- "Can't open USB bus file %s",
- full_path);
- return PCAP_ERROR;
+ ret = PCAP_ERROR_PERM_DENIED;
}
-
- /*
- * No. Report that as "no such device".
- * (That could mean "no such USB bus"
- * or "monitoring not supported".)
- */
- return PCAP_ERROR_NO_SUCH_DEVICE;
+ else
+ {
+ /*
+ * Some other error.
+ */
+ ret = PCAP_ERROR;
+ }
+ pcap_fmt_errmsg_for_errno(handle->errbuf,
+ PCAP_ERRBUF_SIZE, errno,
+ "Can't open USB bus file %s",
+ full_path);
+ return ret;
}
}