Skip to content

Commit 3b7e305

Browse files
committed
DAG: Use PCAP_ERROR_NO_SUCH_DEVICE more in dag_activate().
Under particular error conditions produce more useful error codes (for the code that uses libpcap) and messages (for the users). Before: # tcpdump -ni dag0:1 tcpdump: dag_activate: tx (odd numbered) streams not supported for capture # tcpdump -ni dag0:0 tcpdump: dag_attach_stream64: Cannot allocate memory # tcpdump -ni dag0:8 tcpdump: dag_attach_stream64: Invalid argument After: # tcpdump -ni dag0:1 tcpdump: dag0:1: No such device exists (dag_activate: tx (odd numbered) streams not supported for capture) # tcpdump -ni dag0:0 tcpdump: dag0:0: No such device exists (/dev/dag0 has no memory allocated to Rx stream 0) # tcpdump -ni dag0:8 tcpdump: dag0:8: No such device exists (/dev/dag0 has no Rx stream 8)
1 parent ca89ebc commit 3b7e305

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
7777
Trust dag_get_stream_erf_types() to be available.
7878
Require the API to have 64-bit streams support.
7979
Make device descriptions more useful, make dagN conditional.
80+
Use PCAP_ERROR_NO_SUCH_DEVICE more in dag_activate().
8081

8182
DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
8283
Summary for 1.10.6 libpcap release (so far!)

pcap-dag.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,12 @@ static int dag_activate(pcap_t* p)
645645
}
646646

647647
if (pd->dag_stream%2) {
648-
ret = PCAP_ERROR;
648+
/*
649+
* dag_findalldevs() does not return any Tx streams, so
650+
* PCAP_ERROR_NO_SUCH_DEVICE is more consistent than
651+
* PCAP_ERROR_CAPTURE_NOTSUP.
652+
*/
653+
ret = PCAP_ERROR_NO_SUCH_DEVICE;
649654
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: tx (odd numbered) streams not supported for capture", __func__);
650655
goto fail;
651656
}
@@ -687,6 +692,24 @@ static int dag_activate(pcap_t* p)
687692

688693
/* Open requested stream. Can fail if already locked or on error */
689694
if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
695+
if (errno == ENOMEM) {
696+
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
697+
"%s has no memory allocated to Rx stream %u",
698+
device, pd->dag_stream);
699+
/*
700+
* dag_findalldevs() does not return streams that do
701+
* not have buffer memory, so PCAP_ERROR_NO_SUCH_DEVICE
702+
* is more consistent than PCAP_ERROR_CAPTURE_NOTSUP.
703+
*/
704+
ret = PCAP_ERROR_NO_SUCH_DEVICE;
705+
goto failclose;
706+
} else if (errno == EINVAL) {
707+
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
708+
"%s has no Rx stream %u",
709+
device, pd->dag_stream);
710+
ret = PCAP_ERROR_NO_SUCH_DEVICE;
711+
goto failclose;
712+
}
690713
ret = PCAP_ERROR;
691714
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
692715
errno, "dag_attach_stream64");

0 commit comments

Comments
 (0)