A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

December 31, 2011

Fetch IP address of interface(port) in Kernel

Hi guys, ( I am author/founder TrafficSqueezer - Linux kernel wan opt.solution).

I want a quick portion of code to get IP address of interface, (preferrably also IPv6) for a given interface/port name in a API.

for example I need whihin kernel context (its a part of TrafficSqueezer kernel source):
int ts_get_port_ip_addr(char *port_name, char *ip_addr, char *ipv6_addr)


So that i can call this:
ts_get_port_ip_addr("eth0", ip_addr, ipv6_addr) --> something like that.

Can someone come up with a direct suggestion or some api for it ? Which I can call in that above my API wrapper i.e: ts_get_port_ip_addr().

Currently I have this blank dummy api, so I push actually from user-space to kernel space, the extracted IPaddr directly. But I want to happen implicit within kernel. I search for APis in kernel, still didnt figured out exact API or call sequence, and I need a tip/suggestions from someone who knows it already.

Thank you in advance.

Click Here!