mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 17:59:04 +00:00
Moving block_socket() and unblock_socket() from Nmap to Nbase for reuse in
Nsock and Ncat
This commit is contained in:
30
tcpip.cc
30
tcpip.cc
@@ -1854,21 +1854,6 @@ int send_ip_raw( int sd, struct eth_nfo *eth,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int unblock_socket(int sd) {
|
|
||||||
#ifdef WIN32
|
|
||||||
u_long one = 1;
|
|
||||||
if(sd != 501) // Hack related to WinIP Raw Socket support
|
|
||||||
ioctlsocket (sd, FIONBIO, &one);
|
|
||||||
#else
|
|
||||||
int options;
|
|
||||||
/*Unblock our socket to prevent recvfrom from blocking forever
|
|
||||||
on certain target ports. */
|
|
||||||
options = O_NONBLOCK | fcntl(sd, F_GETFL);
|
|
||||||
fcntl(sd, F_SETFL, options);
|
|
||||||
#endif //WIN32
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returns -1 if we can't use select() on the pcap device, 0 for timeout, and
|
/* 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
|
* >0 for success. If select() fails we bail out because it couldn't work with
|
||||||
* the file descriptor we got from my_pcap_get_selectable_fd()
|
* the file descriptor we got from my_pcap_get_selectable_fd()
|
||||||
@@ -3394,21 +3379,6 @@ int max_sd() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a socket to blocking mode */
|
|
||||||
int block_socket(int sd) {
|
|
||||||
#ifdef WIN32
|
|
||||||
unsigned long options=0;
|
|
||||||
if(sd == 501) return 1;
|
|
||||||
ioctlsocket(sd, FIONBIO, &options);
|
|
||||||
#else
|
|
||||||
int options;
|
|
||||||
options = (~O_NONBLOCK) & fcntl(sd, F_GETFL);
|
|
||||||
fcntl(sd, F_SETFL, options);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Give broadcast permission to a socket */
|
/* Give broadcast permission to a socket */
|
||||||
void broadcast_socket(int sd) {
|
void broadcast_socket(int sd) {
|
||||||
int one = 1;
|
int one = 1;
|
||||||
|
|||||||
4
tcpip.h
4
tcpip.h
@@ -700,7 +700,6 @@ bool setTargetNextHopMAC(Target *target);
|
|||||||
|
|
||||||
int islocalhost(const struct in_addr * const addr);
|
int islocalhost(const struct in_addr * const addr);
|
||||||
int isipprivate(const struct in_addr * const addr);
|
int isipprivate(const struct in_addr * const addr);
|
||||||
int unblock_socket(int sd);
|
|
||||||
|
|
||||||
// Takes a protocol number like IPPROTO_TCP, IPPROTO_UDP, or
|
// Takes a protocol number like IPPROTO_TCP, IPPROTO_UDP, or
|
||||||
// IPPROTO_IP and returns a ascii representation (or "unknown" if it
|
// IPPROTO_IP and returns a ascii representation (or "unknown" if it
|
||||||
@@ -746,9 +745,6 @@ void max_rcvbuf(int sd);
|
|||||||
max allowed */
|
max allowed */
|
||||||
int max_sd();
|
int max_sd();
|
||||||
|
|
||||||
/* Convert a socket to blocking mode */
|
|
||||||
int block_socket(int sd);
|
|
||||||
|
|
||||||
/* Give broadcast permission to a socket */
|
/* Give broadcast permission to a socket */
|
||||||
void broadcast_socket(int sd);
|
void broadcast_socket(int sd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user