1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-18 12:19:02 +00:00

Update to libpcap 1.9.1 (initial commit, no Nmap-specific patches)

This commit is contained in:
dmiller
2019-11-19 17:53:36 +00:00
parent 42bb2feed8
commit f1107301e8
125 changed files with 7238 additions and 13624 deletions

View File

@@ -1,14 +1,6 @@
/*
* pcap-dag.c: Packet capture interface for Endace DAG cards.
*
* The functionality of this code attempts to mimic that of pcap-linux as much
* as possible. This code is compiled in several different ways depending on
* whether DAG_ONLY and HAVE_DAG_API are defined. If HAVE_DAG_API is not
* defined it should not get compiled in, otherwise if DAG_ONLY is defined then
* the 'dag_' function calls are renamed to 'pcap_' equivalents. If DAG_ONLY
* is not defined then nothing is altered - the dag_ functions will be
* called as required from their pcap-linux/bpf equivalents.
*
* Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
* Modifications: Jesper Peterson
* Koryn Grant
@@ -258,12 +250,18 @@ dag_platform_cleanup(pcap_t *p)
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);
/* Note: don't need to call close(p->fd) or dag_close(p->fd) as dag_config_dispose(pd->dag_ref) does this. */
}
static void
@@ -722,7 +720,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
static int
dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
{
strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
pcap_strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
PCAP_ERRBUF_SIZE);
return (-1);
}
@@ -746,18 +744,20 @@ static int dag_activate(pcap_t* p)
daginf_t* daginf;
char * newDev = NULL;
char * device = p->opt.device;
int ret;
dag_size_t mindata;
struct timeval maxwait;
struct timeval poll;
if (device == NULL) {
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL");
return -1;
return PCAP_ERROR;
}
/* Initialize some components of the pcap structure. */
newDev = (char *)malloc(strlen(device) + 16);
if (newDev == NULL) {
ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't allocate string for device name");
goto fail;
@@ -765,6 +765,13 @@ static int dag_activate(pcap_t* p)
/* 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;
@@ -772,25 +779,40 @@ static int dag_activate(pcap_t* p)
device = newDev;
if (pd->dag_stream%2) {
ret = PCAP_ERROR;
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) {
/*
* 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);
goto fail;
goto failclose;
}
/* Open requested stream. Can fail if already locked or on error */
if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_attach_stream");
goto failclose;
@@ -809,6 +831,7 @@ static int dag_activate(pcap_t* p)
*/
if (dag_get_stream_poll64(p->fd, pd->dag_stream,
&mindata, &maxwait, &poll) < 0) {
ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_get_stream_poll");
goto faildetach;
@@ -853,6 +876,7 @@ static int dag_activate(pcap_t* p)
if (dag_set_stream_poll64(p->fd, pd->dag_stream,
mindata, &maxwait, &poll) < 0) {
ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_set_stream_poll");
goto faildetach;
@@ -875,6 +899,7 @@ static int dag_activate(pcap_t* p)
#endif
if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "dag_start_stream %s", device);
goto faildetach;
@@ -910,6 +935,7 @@ static int dag_activate(pcap_t* p)
if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
pd->dag_fcs_bits = n;
} else {
ret = PCAP_ERROR;
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n);
goto failstop;
@@ -932,12 +958,15 @@ static int dag_activate(pcap_t* p)
pd->dag_timeout = p->opt.timeout;
p->linktype = -1;
if (dag_get_datalink(p) < 0)
if (dag_get_datalink(p) < 0) {
ret = PCAP_ERROR;
goto failstop;
}
p->bufsize = 0;
if (new_pcap_dag(p) < 0) {
ret = PCAP_ERROR;
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "new_pcap_dag %s", device);
goto failstop;
@@ -977,6 +1006,14 @@ faildetach:
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:
@@ -985,7 +1022,7 @@ fail:
free((char *)newDev);
}
return PCAP_ERROR;
return ret;
}
pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
@@ -1137,7 +1174,7 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
}
rxstreams = dag_rx_get_stream_count(dagfd);
for(stream=0;stream<DAG_STREAM_MAX;stream+=2) {
if (0 == dag_attach_stream(dagfd, stream, 0, 0)) {
if (0 == dag_attach_stream64(dagfd, stream, 0, 0)) {
dag_detach_stream(dagfd, stream);
pcap_snprintf(name, 10, "dag%d:%d", c, stream);