Skip to contentSkip to conversation

How to get a local IPv4 address from within a kernel module?

DISCUSSION Jean Tourrilhes 1 participant 1 message Oct 31, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines · Juan Gomez

Is there any standard way of doing this? I looked into ipv4 code but I did not find a function that would provide a direct, clean way to query the local IPv4 addresses of a given node.

There is no such thing as the local IPv4 addresses of a given
node. IP addresses are assigned for each network interfaces, so you may have more than one IP address. Note that I have many systems that don't have any "eth0" and still have many IP addresses (on wlan0, ppp0, bnep0...).
On top of that, the DNS may assign an IP address that map to
your current hostname (which may correspond to one of the addresses above). That's purely a user space stuff.

So, you are basically starting on a wrong assumption, the
information you are looking for doesn't exist, and I therefore suspect that you need to rethink the thing you want to do.

I suggest you use a user space application to pick the IP
address most relevant to your setup (i.e. policy decision) and inject it in your module.

Good luck,

Jean