((errno != EACCES && errno != ENOENT) ||
(fd = open(cloning_device, O_RDONLY)) == -1)) {
if (errno != ENOENT) {
- if (errno == EACCES)
+ if (errno == EACCES) {
fd = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed - root privileges may be required",
+ cloning_device);
+ } else {
fd = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
- errno, "(cannot open device) %s", cloning_device);
+ pcap_fmt_errmsg_for_errno(errbuf,
+ PCAP_ERRBUF_SIZE, errno,
+ "(cannot open device) %s", cloning_device);
+ }
return (fd);
}
no_cloning_bpf = 1;
* if any.
*/
fd = PCAP_ERROR_PERM_DENIED;
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
- errno, "(cannot open BPF device) %s", device);
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed - root privileges may be required",
+ device);
break;
default:
*/
if (errno == ENOENT)
ret = PCAP_ERROR_NO_SUCH_DEVICE;
- else if (errno == EPERM || errno == EACCES)
+ else if (errno == EPERM || errno == EACCES) {
ret = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed with %s - additional privileges may be required",
+ device, (errno == EPERM) ? "EPERM" : "EACCES");
+ } else {
ret = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
- errno, "dag_config_init %s", device);
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "dag_config_init %s", device);
+ }
goto fail;
}
static int dlpromiscon(pcap_t *, bpf_u_int32);
static int dlbindreq(int, bpf_u_int32, char *);
static int dlbindack(int, char *, char *, int *);
-static int dlokack(int, const char *, char *, char *);
+static int dlokack(int, const char *, char *, char *, int *);
static int dlinforeq(int, char *);
static int dlinfoack(int, char *, char *);
*/
cp = "/dev/dlpi";
if ((fd = open(cp, O_RDWR)) < 0) {
- if (errno == EPERM || errno == EACCES)
+ if (errno == EPERM || errno == EACCES) {
status = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed with %s - root privilege may be required",
+ cp, (errno == EPERM) ? "EPERM" : "EACCES");
+ } else {
status = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
- errno, "%s", cp);
+ pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
+ errno, "Attempt to open %s failed", cp);
+ }
return (status);
}
/* Try device without unit number */
if ((fd = open(dname, O_RDWR)) < 0) {
if (errno != ENOENT) {
- if (errno == EPERM || errno == EACCES)
+ if (errno == EPERM || errno == EACCES) {
status = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed with %s - root privilege may be required",
+ dname,
+ (errno == EPERM) ? "EPERM" : "EACCES");
+ } else {
status = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
- errno, "%s", dname);
+ pcap_fmt_errmsg_for_errno(errbuf,
+ PCAP_ERRBUF_SIZE, errno,
+ "Attempt to open %s failed", dname);
+ }
return (status);
}
snprintf(errbuf, PCAP_ERRBUF_SIZE,
"%s: No DLPI device found", name);
} else {
- if (errno == EPERM || errno == EACCES)
+ if (errno == EPERM || errno == EACCES) {
status = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed with %s - root privilege may be required",
+ dname2,
+ (errno == EPERM) ? "EPERM" : "EACCES");
+ } else {
status = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(errbuf,
- PCAP_ERRBUF_SIZE, errno, "%s", dname2);
+ pcap_fmt_errmsg_for_errno(errbuf,
+ PCAP_ERRBUF_SIZE, errno,
+ "Attempt to open %s failed",
+ dname2);
+ }
}
return (status);
}
if (send_request(fd, (char *)&req, sizeof(req), "attach", ebuf) < 0)
return (PCAP_ERROR);
- err = dlokack(fd, "attach", (char *)buf, ebuf);
+ err = dlokack(fd, "attach", (char *)buf, ebuf, NULL);
if (err < 0)
return (err);
return (0);
dl_promiscon_req_t req;
bpf_u_int32 buf[MAXDLBUF];
int err;
+ int uerror;
req.dl_primitive = DL_PROMISCON_REQ;
req.dl_level = level;
p->errbuf) < 0)
return (PCAP_ERROR);
err = dlokack(p->fd, "promiscon" STRINGIFY(level), (char *)buf,
- p->errbuf);
- if (err < 0)
+ p->errbuf, &uerror);
+ if (err < 0) {
+ if (err == PCAP_ERROR_PERM_DENIED) {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to set promiscuous mode failed with %s - root privilege may be required",
+ (uerror == EPERM) ? "EPERM" : "EACCES");
+ err = PCAP_ERROR_PROMISC_PERM_DENIED;
+ }
return (err);
+ }
return (0);
}
}
static int
-dlokack(int fd, const char *what, char *bufp, char *ebuf)
+dlokack(int fd, const char *what, char *bufp, char *ebuf, int *uerror)
{
- return (recv_ack(fd, DL_OK_ACK_SIZE, what, bufp, ebuf, NULL));
+ return (recv_ack(fd, DL_OK_ACK_SIZE, what, bufp, ebuf, uerror));
}
req.dl_primitive = DL_PASSIVE_REQ;
if (send_request(fd, (char *)&req, sizeof(req), "dlpassive", ebuf) == 0)
- (void) dlokack(fd, "dlpassive", (char *)buf, ebuf);
+ (void) dlokack(fd, "dlpassive", (char *)buf, ebuf, NULL);
}
#endif
if (retv == DLPI_ELINKNAMEINVAL || retv == DLPI_ENOLINK)
status = PCAP_ERROR_NO_SUCH_DEVICE;
else if (retv == DL_SYSERR &&
- (errno == EPERM || errno == EACCES))
+ (errno == EPERM || errno == EACCES)) {
status = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open DLPI device failed with %s - root privilege may be required",
+ (errno == EPERM) ? "EPERM" : "EACCES");
+ } else {
status = PCAP_ERROR;
- pcap_libdlpi_err(p->opt.device, "dlpi_open", retv,
- p->errbuf);
+ pcap_libdlpi_err(p->opt.device, "dlpi_open", retv,
+ p->errbuf);
+ }
return (status);
}
pd->dlpi_hd = dh;
retv = dlpi_promiscon(pd->dlpi_hd, level);
if (retv != DLPI_SUCCESS) {
if (retv == DL_SYSERR &&
- (errno == EPERM || errno == EACCES))
- err = PCAP_ERROR_PERM_DENIED;
- else
+ (errno == EPERM || errno == EACCES)) {
+ if (level == DL_PROMISC_PHYS) {
+ err = PCAP_ERROR_PROMISC_PERM_DENIED;
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to set promiscuous mode failed with %s - root privilege may be required",
+ (errno == EPERM) ? "EPERM" : "EACCES");
+ } else {
+ err = PCAP_ERROR_PERM_DENIED;
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to set %s mode failed with %s - root privilege may be required",
+ (level == DL_PROMISC_MULTI) ? "multicast" : "SAP promiscuous",
+ (errno == EPERM) ? "EPERM" : "EACCES");
+ }
+ } else {
err = PCAP_ERROR;
- pcap_libdlpi_err(p->opt.device, "dlpi_promiscon" STRINGIFY(level),
- retv, p->errbuf);
+ pcap_libdlpi_err(p->opt.device,
+ "dlpi_promiscon" STRINGIFY(level),
+ retv, p->errbuf);
+ }
return (err);
}
return (0);
* socket.
*/
status = PCAP_ERROR_PERM_DENIED;
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to create packet socket failed - CAP_NET_RAW may be required");
} else {
/*
* Other error.
pcap_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name));
ifr.ifr_data = (void *)&hwconfig;
+ /*
+ * This may require CAP_NET_ADMIN.
+ */
if (ioctl(handle->fd, SIOCSHWTSTAMP, &ifr) < 0) {
switch (errno) {
* try requesting hardware time stamps.
*/
*status = PCAP_ERROR_PERM_DENIED;
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to set hardware timestamp failed - CAP_NET_ADMIN may be required");
return -1;
case EOPNOTSUPP:
/*
* There is, but we don't have permission to
* use it.
+ *
+ * XXX - we currently get ERROR_BAD_UNIT if the
+ * user says "no" to the UAC prompt.
*/
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "The helper program for \"Admin-only Mode\" must be allowed to make changes to your device");
return (PCAP_ERROR_PERM_DENIED);
default:
if (fd < 0 && errno == EACCES)
p->fd = fd = open(dev, O_RDONLY);
if (fd < 0) {
- if (errno == EACCES)
+ if (errno == EACCES) {
err = PCAP_ERROR_PERM_DENIED;
- else
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed with EACCES - root privileges may be required",
+ dev);
+ } else {
err = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
- errno, "%s", dev);
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "%s", dev);
+ }
goto bad;
}
/*
* We didn't have permission to open it.
*/
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Attempt to open %s failed with EACCES - root privileges may be required",
+ full_path);
return PCAP_ERROR_PERM_DENIED;
default: