query whether IP address is bound?
Felipe Gasper
felipe at felipegasper.com
Fri Nov 23 13:59:35 UTC 2018
Hi all,
I’m looking for a way to query whether the (Linux) kernel has a specific IP address bound. Forking is not an option. I’d like to avoid directly enumerating every IP address on the machine, which appears to be the only way that RtNetlink facilitates this. (I’d love to be contradicted on that!)
Normally we’d use bind() and check for EADDRNOTAVAIL or EADDRINUSE, but if /proc/sys/net/ipv4/ip_nonlocal_bind is turned on, then bind() will succeed where we want it to fail.
There is a socket option (IP_FREEBIND) for setting ip_nonlocal_bind per individual socket, but it only appears to _enable_ the behaviour; i.e., if the /proc flag is on, then disabling this socket option appears to have no effect.
Does the usual suite of D-Bus interfaces on a Linux machine have any function that checks this? I’m looking through NetworkManager but only see logic for listing the addresses. Or do folks here have any other ideas for how I might approach this?
Thank you!
-Felipe Gasper
Mississauga, Ontario
More information about the dbus
mailing list