Try to return PCAP_ERROR_NO_SUCH_DEVICE or PCAP_ERROR_PERM_DENIED when
appropriate; return PCAP_ERROR otherwise.
If we fail in dag_config_get_card_fd(), make sure we dispose of the
dag_card_ref_t - go to failclose rather than fail.
If dag_get_datalink() fails, set the error message.
After we do diag_config_dispose(), set p->fd to -1, as
diag_config_dispose() has already taken care of closing that handle.
if(pd->dag_ref != NULL) {
dag_config_dispose(pd->dag_ref);
if(pd->dag_ref != NULL) {
dag_config_dispose(pd->dag_ref);
+ /*
+ * Note: we don't need to call close(p->fd) or
+ * dag_close(p->fd), as dag_config_dispose(pd->dag_ref)
+ * does this.
+ *
+ * Set p->fd to -1 to make sure that's not done.
+ */
p->fd = -1;
pd->dag_ref = NULL;
}
delete_pcap_dag(p);
pcap_cleanup_live_common(p);
p->fd = -1;
pd->dag_ref = NULL;
}
delete_pcap_dag(p);
pcap_cleanup_live_common(p);
- /* Note: don't need to call close(p->fd) or dag_close(p->fd) as dag_config_dispose(pd->dag_ref) does this. */
daginf_t* daginf;
char * newDev = NULL;
char * device = p->opt.device;
daginf_t* daginf;
char * newDev = NULL;
char * device = p->opt.device;
dag_size_t mindata;
struct timeval maxwait;
struct timeval poll;
if (device == NULL) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL");
dag_size_t mindata;
struct timeval maxwait;
struct timeval poll;
if (device == NULL) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL");
}
/* Initialize some components of the pcap structure. */
newDev = (char *)malloc(strlen(device) + 16);
if (newDev == NULL) {
}
/* Initialize some components of the pcap structure. */
newDev = (char *)malloc(strlen(device) + 16);
if (newDev == NULL) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't allocate string for device name");
goto fail;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't allocate string for device name");
goto fail;
/* Parse input name to get dag device and stream number if provided */
if (dag_parse_name(device, newDev, strlen(device) + 16, &pd->dag_stream) < 0) {
/* Parse input name to get dag device and stream number if provided */
if (dag_parse_name(device, newDev, strlen(device) + 16, &pd->dag_stream) < 0) {
+ /*
+ * XXX - it'd be nice if this indicated what was wrong
+ * with the name. Does this reliably set errno?
+ * Should this return PCAP_ERROR_NO_SUCH_DEVICE in some
+ * cases?
+ */
+ ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_parse_name");
goto fail;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_parse_name");
goto fail;
device = newDev;
if (pd->dag_stream%2) {
device = newDev;
if (pd->dag_stream%2) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture");
goto fail;
}
/* setup device parameters */
if((pd->dag_ref = dag_config_init((char *)device)) == NULL) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture");
goto fail;
}
/* setup device parameters */
if((pd->dag_ref = dag_config_init((char *)device)) == NULL) {
+ /*
+ * XXX - does this reliably set errno?
+ */
+ if (errno == ENOENT)
+ ret = PCAP_ERROR_NO_SUCH_DEVICE;
+ else if (errno == EPERM || errno == EACCES)
+ ret = PCAP_ERROR_PERM_DENIED;
+ else
+ ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_config_init %s", device);
goto fail;
}
if((p->fd = dag_config_get_card_fd(pd->dag_ref)) < 0) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_config_init %s", device);
goto fail;
}
if((p->fd = dag_config_get_card_fd(pd->dag_ref)) < 0) {
+ /*
+ * XXX - does this reliably set errno?
+ */
+ ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_config_get_card_fd %s", device);
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_config_get_card_fd %s", device);
}
/* Open requested stream. Can fail if already locked or on error */
if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
}
/* Open requested stream. Can fail if already locked or on error */
if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_attach_stream");
goto failclose;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_attach_stream");
goto failclose;
*/
if (dag_get_stream_poll64(p->fd, pd->dag_stream,
&mindata, &maxwait, &poll) < 0) {
*/
if (dag_get_stream_poll64(p->fd, pd->dag_stream,
&mindata, &maxwait, &poll) < 0) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_get_stream_poll");
goto faildetach;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_get_stream_poll");
goto faildetach;
if (dag_set_stream_poll64(p->fd, pd->dag_stream,
mindata, &maxwait, &poll) < 0) {
if (dag_set_stream_poll64(p->fd, pd->dag_stream,
mindata, &maxwait, &poll) < 0) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_set_stream_poll");
goto faildetach;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_set_stream_poll");
goto faildetach;
#endif
if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
#endif
if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_start_stream %s", device);
goto faildetach;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_start_stream %s", device);
goto faildetach;
if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
pd->dag_fcs_bits = n;
} else {
if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
pd->dag_fcs_bits = n;
} else {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n);
goto failstop;
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n);
goto failstop;
pd->dag_timeout = p->opt.timeout;
p->linktype = -1;
pd->dag_timeout = p->opt.timeout;
p->linktype = -1;
- if (dag_get_datalink(p) < 0)
+ if (dag_get_datalink(p) < 0) {
+ ret = PCAP_ERRNO;
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "dag_get_datalink %s", device);
p->bufsize = 0;
if (new_pcap_dag(p) < 0) {
p->bufsize = 0;
if (new_pcap_dag(p) < 0) {
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "new_pcap_dag %s", device);
goto failstop;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "new_pcap_dag %s", device);
goto failstop;
failclose:
dag_config_dispose(pd->dag_ref);
failclose:
dag_config_dispose(pd->dag_ref);
+ /*
+ * Note: we don't need to call close(p->fd) or dag_close(p->fd),
+ * as dag_config_dispose(pd->dag_ref) does this.
+ *
+ * Set p->fd to -1 to make sure that's not done.
+ */
+ p->fd = -1;
+ pd->dag_ref = NULL;
delete_pcap_dag(p);
fail:
delete_pcap_dag(p);
fail:
}
pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
}
pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)