mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 05:01:29 +00:00
Consolidate raw socket acquisition.
This commit is contained in:
25
tcpip.cc
25
tcpip.cc
@@ -87,31 +87,6 @@ extern NmapOps o;
|
||||
|
||||
static PacketCounter PktCt;
|
||||
|
||||
/* Create a raw socket and do things that always apply to raw sockets:
|
||||
* Set SO_BROADCAST.
|
||||
* Set IP_HDRINCL.
|
||||
* Bind to an interface with SO_BINDTODEVICE (if o.device is set).
|
||||
The socket is created with address family AF_INET, but may be usable for
|
||||
AF_INET6, depending on the operating system. */
|
||||
int nmap_raw_socket() {
|
||||
int rawsd;
|
||||
int one = 1;
|
||||
|
||||
rawsd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
|
||||
if (rawsd < 0)
|
||||
return rawsd;
|
||||
if (setsockopt (rawsd, SOL_SOCKET, SO_BROADCAST, (const char *) &one, sizeof(int)) != 0) {
|
||||
error("Failed to secure socket broadcasting permission");
|
||||
perror("setsockopt");
|
||||
}
|
||||
#ifndef WIN32
|
||||
sethdrinclude(rawsd);
|
||||
#endif
|
||||
socket_bindtodevice(rawsd, o.device);
|
||||
|
||||
return rawsd;
|
||||
}
|
||||
|
||||
/* Fill buf (up to buflen -- truncate if necessary but always
|
||||
terminate) with a short representation of the packet stats.
|
||||
Returns buf. Aborts if there is a problem. */
|
||||
|
||||
Reference in New Issue
Block a user