diff --git a/nping/ProbeMode.cc b/nping/ProbeMode.cc index 199329b40..e621876c3 100644 --- a/nping/ProbeMode.cc +++ b/nping/ProbeMode.cc @@ -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() */