
Nmap Development mailing list archives
[PATCH] nping: bind to interface on Linux for IPv4 send-ip
From: ValdikSS via dev <dev () nmap org>
Date: Thu, 30 May 2024 19:43:46 +0300
Linux RAW sockets need to be bound to interface, if the interface is L3 tunnel (OpenVPN TUN for example). Otherwise the packet goes via default route, regardless of `--interface` or `--source-ip` options. --- nping/ProbeMode.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nping/ProbeMode.cc b/nping/ProbeMode.cc index 199329b40..ba4c3f82d 100644 --- a/nping/ProbeMode.cc +++ b/nping/ProbeMode.cc @@ -807,6 +807,17 @@ int ProbeMode::fillPacketTCP(NpingTarget *target, u16 port, u8 *buff, int buffle }else{ t.setSum(); } + + /* Bind IPv4 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 IPv4 socket to device %s", o.getDevice() ); + } + #endif + } + /* Store result in user supplied buffer */ *filledlen = i.dumpToBinaryBuffer(buff, bufflen); -- 2.45.1 _______________________________________________ Sent through the dev mailing list https://nmap.org/mailman/listinfo/dev Archived at https://seclists.org/nmap-dev/
Current thread:
- [PATCH] nping: bind to interface on Linux for IPv4 send-ip ValdikSS via dev (May 30)
- Re: [PATCH] nping: bind to interface on Linux for IPv4 send-ip David Fifield (May 30)