]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap-dag.c
Add a routine to format error messages with an errno-based message at the end.
[libpcap] / pcap-dag.c
index 24bf31a54cd45dd94cdcc462f42f151765769260..7046db23e397cea3f7df8ab889dcb701ad442c16 100644 (file)
@@ -749,20 +749,22 @@ static int dag_activate(pcap_t* p)
        struct timeval poll;
 
        if (device == NULL) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL: %s", pcap_strerror(errno));
+               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL");
                return -1;
        }
 
        /* Initialize some components of the pcap structure. */
        newDev = (char *)malloc(strlen(device) + 16);
        if (newDev == NULL) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate string for device name: %s", pcap_strerror(errno));
+               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) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_parse_name");
                goto fail;
        }
        device = newDev;
@@ -774,13 +776,15 @@ static int dag_activate(pcap_t* p)
 
        /* setup device parameters */
        if((p->fd = dag_open((char *)device)) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_open %s: %s", device, pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_open %s", device);
                goto fail;
        }
 
        /* Open requested stream. Can fail if already locked or on error */
        if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_attach_stream: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_attach_stream");
                goto failclose;
        }
 
@@ -789,7 +793,8 @@ static int dag_activate(pcap_t* p)
         */
        if (dag_get_stream_poll64(p->fd, pd->dag_stream,
                                &mindata, &maxwait, &poll) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_get_stream_poll");
                goto faildetach;
        }
 
@@ -825,7 +830,8 @@ static int dag_activate(pcap_t* p)
 
        if (dag_set_stream_poll64(p->fd, pd->dag_stream,
                                mindata, &maxwait, &poll) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_set_stream_poll");
                goto faildetach;
        }
 
@@ -846,7 +852,8 @@ static int dag_activate(pcap_t* p)
 #endif
 
        if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_start_stream %s: %s", device, pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_start_stream %s", device);
                goto faildetach;
        }
 
@@ -908,7 +915,8 @@ static int dag_activate(pcap_t* p)
        p->bufsize = 0;
 
        if (new_pcap_dag(p) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "new_pcap_dag %s: %s", device, pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "new_pcap_dag %s", device);
                goto failstop;
        }
 
@@ -1021,8 +1029,8 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
        p->tstamp_precision_count = 2;
        p->tstamp_precision_list = malloc(2 * sizeof(u_int));
        if (p->tstamp_precision_list == NULL) {
-               pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
-                   pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
+                   errno, "malloc");
                pcap_close(p);
                return NULL;
        }
@@ -1158,7 +1166,8 @@ dag_setnonblock(pcap_t *p, int nonblock)
 
        if (dag_get_stream_poll64(p->fd, pd->dag_stream,
                                &mindata, &maxwait, &poll) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_get_stream_poll");
                return -1;
        }
 
@@ -1173,7 +1182,8 @@ dag_setnonblock(pcap_t *p, int nonblock)
 
        if (dag_set_stream_poll64(p->fd, pd->dag_stream,
                                mindata, &maxwait, &poll) < 0) {
-               pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+                   errno, "dag_set_stream_poll");
                return -1;
        }
 
@@ -1195,7 +1205,8 @@ dag_get_datalink(pcap_t *p)
        memset(types, 0, 255);
 
        if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
-               (void)pcap_snprintf(p->errbuf, sizeof(p->errbuf), "malloc: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
+                   errno, "malloc");
                return (-1);
        }
 
@@ -1204,7 +1215,8 @@ dag_get_datalink(pcap_t *p)
 #ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
        /* Get list of possible ERF types for this card */
        if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
-               pcap_snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_stream_erf_types: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
+                   errno, "dag_get_stream_erf_types");
                return (-1);
        }
 
@@ -1213,7 +1225,8 @@ dag_get_datalink(pcap_t *p)
 #elif defined HAVE_DAG_GET_ERF_TYPES
        /* Get list of possible ERF types for this card */
        if (dag_get_erf_types(p->fd, types, 255) < 0) {
-               pcap_snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_erf_types: %s", pcap_strerror(errno));
+               pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
+                   errno, "dag_get_erf_types");
                return (-1);
        }