1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-06 06:29:03 +00:00

Protect pcap_selectable_fd_valid from platforms that don't have it.

Thanks jah for catching this.
This commit is contained in:
david
2012-03-24 01:52:43 +00:00
parent e10d1bad27
commit 9958ed8ebe

View File

@@ -857,15 +857,30 @@ void set_ttl(int sd, int ttl) {
#endif
}
#if defined(WIN32) || defined(MACOSX) || (defined(FREEBSD) && (__FreeBSD_version < 500000))
/* Returns whether the system supports pcap_get_selectable_fd() properly */
int pcap_selectable_fd_valid() {
#if defined(WIN32) || defined(MACOSX) || (defined(FREEBSD) && (__FreeBSD_version < 500000))
return 0;
#else
return 1;
#endif
}
/* Call this instead of pcap_get_selectable_fd directly (or your code
won't compile on Windows). On systems which don't seem to support
the pcap_get_selectable_fd() function properly, returns -1,
otherwise simply calls pcap_selectable_fd and returns the
results. If you just want to test whether the function is supported,
use pcap_selectable_fd_valid() instead. */
int my_pcap_get_selectable_fd(pcap_t *p) {
return -1;
}
#else
int pcap_selectable_fd_valid() {
return 1;
}
int my_pcap_get_selectable_fd(pcap_t *p) {
return pcap_get_selectable_fd(p);
}
#endif
/* Are we guaranteed to be able to read exactly one frame for each time the pcap
fd is selectable? If not, it's possible for the fd to become selectable, then
for pcap_dispatch to buffer two or more frames, and return only the first one
@@ -883,19 +898,6 @@ int pcap_selectable_fd_one_to_one() {
return pcap_selectable_fd_valid();
}
/* Call this instead of pcap_get_selectable_fd directly (or your code
won't compile on Windows). On systems which don't seem to support
the pcap_get_selectable_fd() function properly, returns -1,
otherwise simply calls pcap_selectable_fd and returns the
results. If you just want to test whether the function is supported,
use pcap_selectable_fd_valid() instead. */
int my_pcap_get_selectable_fd(pcap_t *p) {
if (pcap_selectable_fd_valid())
return pcap_get_selectable_fd(p);
else
return -1;
}
/* returns -1 if we can't use select() on the pcap device, 0 for timeout, and
* >0 for success. If select() fails we bail out because it couldn't work with