mirror of
https://github.com/nmap/nmap.git
synced 2025-12-15 20:29:03 +00:00
Updated the included libpcap to 1.5.3
This commit is contained in:
@@ -71,6 +71,17 @@ static int pcap_setnonblock_win32(pcap_t *, int, char *);
|
||||
/* Equivalent to ntohs(), but a lot faster under Windows */
|
||||
#define SWAPS(_X) ((_X & 0xff) << 8) | (_X >> 8)
|
||||
|
||||
/*
|
||||
* Private data for capturing on WinPcap devices.
|
||||
*/
|
||||
struct pcap_win {
|
||||
int nonblock;
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
int dag_fcs_bits; /* Number of checksum bits from link layer */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* Header that the WinPcap driver associates to the packets.
|
||||
* Once was in bpf.h
|
||||
@@ -165,6 +176,13 @@ pcap_setmintocopy_win32(pcap_t *p, int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*return the Adapter for a pcap_t*/
|
||||
static Adapter *
|
||||
pcap_getadapter_win32(pcap_t *p)
|
||||
{
|
||||
return p->adapter;
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
@@ -238,7 +256,7 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
*/
|
||||
(*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen);
|
||||
bp += Packet_WORDALIGN(caplen + hdrlen);
|
||||
if (++n >= cnt && cnt > 0) {
|
||||
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
|
||||
p->bp = bp;
|
||||
p->cc = ep - bp;
|
||||
return (n);
|
||||
@@ -253,6 +271,7 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
static int
|
||||
pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
struct pcap_win *pw = p->priv;
|
||||
u_char *dp = NULL;
|
||||
int packet_len = 0, caplen = 0;
|
||||
struct pcap_pkthdr pcap_header;
|
||||
@@ -295,7 +314,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
break;
|
||||
|
||||
/* Increase the number of captured packets */
|
||||
p->md.stat.ps_recv++;
|
||||
pw->stat.ps_recv++;
|
||||
|
||||
/* Find the beginning of the packet */
|
||||
dp = ((u_char *)header) + dag_record_size;
|
||||
@@ -312,7 +331,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
|
||||
case TYPE_ETH:
|
||||
swt = SWAPS(header->wlen);
|
||||
packet_len = swt - (p->md.dag_fcs_bits);
|
||||
packet_len = swt - (pw->dag_fcs_bits);
|
||||
caplen = erf_record_len - dag_record_size - 2;
|
||||
if (caplen > packet_len)
|
||||
{
|
||||
@@ -324,7 +343,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
|
||||
case TYPE_HDLC_POS:
|
||||
swt = SWAPS(header->wlen);
|
||||
packet_len = swt - (p->md.dag_fcs_bits);
|
||||
packet_len = swt - (pw->dag_fcs_bits);
|
||||
caplen = erf_record_len - dag_record_size;
|
||||
if (caplen > packet_len)
|
||||
{
|
||||
@@ -397,7 +416,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
header = (dag_record_t*)((char*)header + erf_record_len);
|
||||
|
||||
/* Stop if the number of packets requested by user has been reached*/
|
||||
if (++n >= cnt && cnt > 0)
|
||||
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
|
||||
{
|
||||
p->bp = (char*)header;
|
||||
p->cc = endofbuf - (char*)header;
|
||||
@@ -457,6 +476,7 @@ pcap_cleanup_win32(pcap_t *p)
|
||||
static int
|
||||
pcap_activate_win32(pcap_t *p)
|
||||
{
|
||||
struct pcap_win *pw = p->priv;
|
||||
NetType type;
|
||||
|
||||
if (p->opt.rfmon) {
|
||||
@@ -622,11 +642,23 @@ pcap_activate_win32(pcap_t *p)
|
||||
|
||||
PacketInitPacket(p->Packet,(BYTE*)p->buffer,p->bufsize);
|
||||
|
||||
/* tell the driver to copy the buffer only if it contains at least 16K */
|
||||
if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
|
||||
if (p-opt.immediate)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s", pcap_win32strerror());
|
||||
goto bad;
|
||||
/* tell the driver to copy the buffer as soon as data arrives */
|
||||
if(PacketSetMinToCopy(p->adapter,0)==FALSE)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s", pcap_win32strerror());
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* tell the driver to copy the buffer only if it contains at least 16K */
|
||||
if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s", pcap_win32strerror());
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -672,13 +704,13 @@ pcap_activate_win32(pcap_t *p)
|
||||
|
||||
/* Set the length of the FCS associated to any packet. This value
|
||||
* will be subtracted to the packet length */
|
||||
p->md.dag_fcs_bits = p->adapter->DagFcsLen;
|
||||
pw->dag_fcs_bits = p->adapter->DagFcsLen;
|
||||
}
|
||||
#else
|
||||
goto bad;
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
PacketSetReadTimeout(p->adapter, p->md.timeout);
|
||||
PacketSetReadTimeout(p->adapter, p->opt.timeout);
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
if(p->adapter->Flags & INFO_FLAG_DAG_CARD)
|
||||
@@ -706,6 +738,7 @@ pcap_activate_win32(pcap_t *p)
|
||||
p->setbuff_op = pcap_setbuff_win32;
|
||||
p->setmode_op = pcap_setmode_win32;
|
||||
p->setmintocopy_op = pcap_setmintocopy_win32;
|
||||
p->getadapter_op = pcap_getadapter_win32;
|
||||
p->cleanup_op = pcap_cleanup_win32;
|
||||
|
||||
return (0);
|
||||
@@ -715,7 +748,7 @@ bad:
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_create(const char *device, char *ebuf)
|
||||
pcap_create_interface(const char *device, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
@@ -743,12 +776,12 @@ pcap_create(const char *device, char *ebuf)
|
||||
}
|
||||
|
||||
snprintf(deviceAscii, length + 1, "%ws", (wchar_t*)device);
|
||||
p = pcap_create_common(deviceAscii, ebuf);
|
||||
p = pcap_create_common(deviceAscii, ebuf, sizeof (struct pcap_win));
|
||||
free(deviceAscii);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = pcap_create_common(device, ebuf);
|
||||
p = pcap_create_common(device, ebuf, sizeof (struct pcap_win));
|
||||
}
|
||||
|
||||
if (p == NULL)
|
||||
@@ -801,25 +834,26 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->md.use_bpf = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_getnonblock_win32(pcap_t *p, char *errbuf)
|
||||
{
|
||||
struct pcap_win *pw = p->priv;
|
||||
|
||||
/*
|
||||
* XXX - if there were a PacketGetReadTimeout() call, we
|
||||
* would use it, and return 1 if the timeout is -1
|
||||
* and 0 otherwise.
|
||||
*/
|
||||
return (p->nonblock);
|
||||
return (pw->nonblock);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
|
||||
{
|
||||
struct pcap_win *pw = p->priv;
|
||||
int newtimeout;
|
||||
|
||||
if (nonblock) {
|
||||
@@ -833,14 +867,14 @@ pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
|
||||
* (Note that this may be -1, in which case we're not
|
||||
* really leaving non-blocking mode.)
|
||||
*/
|
||||
newtimeout = p->md.timeout;
|
||||
newtimeout = p->opt.timeout;
|
||||
}
|
||||
if (!PacketSetReadTimeout(p->adapter, newtimeout)) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"PacketSetReadTimeout: %s", pcap_win32strerror());
|
||||
return (-1);
|
||||
}
|
||||
p->nonblock = (newtimeout == -1);
|
||||
pw->nonblock = (newtimeout == -1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user