1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-29 19:09:01 +00:00

Apply the nonblocking pcap read trick in readip_pcap too.

This commit is contained in:
david
2012-03-22 00:47:24 +00:00
parent cdcc9da0d8
commit b4cb468b1d
2 changed files with 22 additions and 3 deletions

View File

@@ -104,6 +104,7 @@
#include "NmapOps.h"
#include "Target.h"
#include "utils.h"
#include "libnetutil/netutil.h"
#include "struct_ip.h"
@@ -1641,11 +1642,28 @@ char *readip_pcap(pcap_t *pd, unsigned int *len, long to_usec,
#endif
p = NULL;
/* It may be that protecting this with !pcap_selectable_fd_one_to_one is not
necessary, that it is always safe to do a nonblocking read in this way on
all platforms. But I have only tested it on Solaris. */
if (!pcap_selectable_fd_one_to_one()) {
int rc, nonblock;
if (pcap_select(pd, to_usec) == 0)
timedout = 1;
else
nonblock = pcap_getnonblock(pd, NULL);
assert(nonblock == 0);
rc = pcap_setnonblock(pd, 1, NULL);
assert(rc == 0);
p = (char *) pcap_next(pd, &head);
rc = pcap_setnonblock(pd, nonblock, NULL);
assert(rc == 0);
}
if (p == NULL) {
/* Nonblocking pcap_next didn't get anything. */
if (pcap_select(pd, to_usec) == 0)
timedout = 1;
else
p = (char *) pcap_next(pd, &head);
}
if (p) {
if (head.caplen <= offset) {