Nping: bind to device when possible. See https://seclists.org/nmap-dev/2024/q2/9

This commit is contained in:
dmiller 2025-02-10 21:04:34 +00:00
parent dd7b7d76e8
commit 43234fbbdd

View file

@ -301,6 +301,11 @@ int ProbeMode::start(){
/* Get socket descriptor. No need for it in ARP since we send at eth level */
if ((rawipsd = obtainRawSocket()) < 0 )
nping_fatal(QT_3,"Couldn't acquire raw socket. Are you root?");
if ( o.issetDevice() ) {
if (!socket_bindtodevice(rawipsd, o.getDevice()) && errno != EPERM) {
nping_warning(QT_2, "Error binding socket to device %s", o.getDevice() );
}
}
}
/* Check if we have enough information to get the party started */
@ -720,16 +725,6 @@ int ProbeMode::doIPv6ThroughSocket(int rawfd){
}
#endif
/* Bind IPv6 socket to a specific network interface */
if ( o.issetDevice() ) {
/* It seems that SO_BINDTODEVICE only work on Linux */
#ifdef LINUX
if (setsockopt(rawfd, SOL_SOCKET, SO_BINDTODEVICE, o.getDevice(), strlen(o.getDevice())+1) == -1) {
nping_warning(QT_2, "Error binding IPv6 socket to device %s", o.getDevice() );
}
#endif
}
return OP_SUCCESS;
} /* End of doIPv6ThroughSocket() */