mirror of
https://github.com/nmap/nmap.git
synced 2025-12-23 07:59:03 +00:00
Add socket_bindtodevice function to Nbase.
The Linux-specific SO_BINDTODEVICE sockopt causes packets to be sent on a specific interface, in cases where merely setting the source address does not uniquely determine the interface.
This commit is contained in:
@@ -459,6 +459,7 @@ int inheritable_socket(int af, int style, int protocol);
|
|||||||
int dup_socket(int sd);
|
int dup_socket(int sd);
|
||||||
int unblock_socket(int sd);
|
int unblock_socket(int sd);
|
||||||
int block_socket(int sd);
|
int block_socket(int sd);
|
||||||
|
int socket_bindtodevice(int sd, const char *device);
|
||||||
|
|
||||||
/* CRC32 Cyclic Redundancy Check */
|
/* CRC32 Cyclic Redundancy Check */
|
||||||
unsigned long nbase_crc32(unsigned char *buf, int len);
|
unsigned long nbase_crc32(unsigned char *buf, int len);
|
||||||
|
|||||||
@@ -281,6 +281,18 @@ int block_socket(int sd) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use the SO_BINDTODEVICE sockopt to bind with a specific interface (Linux
|
||||||
|
only). Pass NULL or an empty string to remove device binding. */
|
||||||
|
int socket_bindtodevice(int sd, const char *device) {
|
||||||
|
#ifdef SO_BINDTODEVICE
|
||||||
|
/* Linux-specific sockopt asking to use a specific interface. See socket(7). */
|
||||||
|
if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) < 0)
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert a time specification into a count of seconds. A time specification is
|
/* Convert a time specification into a count of seconds. A time specification is
|
||||||
* a non-negative real number, possibly followed by a units suffix. The suffixes
|
* a non-negative real number, possibly followed by a units suffix. The suffixes
|
||||||
* are "ms" for milliseconds, "s" for seconds, "m" for minutes, or "h" for
|
* are "ms" for milliseconds, "s" for seconds, "m" for minutes, or "h" for
|
||||||
|
|||||||
Reference in New Issue
Block a user