RonWensley
asked on
Programmatically determine which eth0:x interfaces is requesting data
Greetings,
I have edited the /etc/network/interfaces file to provide me with several eth0:x interfaces. Now I want to programmatically determine which interface or IP address a request is coming through.
For example; I have eth0:1 = 192.168.227.205 and eth0:2 = 192.168.227.206
From my laptop I can ping either address.
In linux I want to run a program that responds differently based on the IP address being hit. If .205 do this if .206 do that.
How can I programmatically determine which IP address is being hit?
I have edited the /etc/network/interfaces file to provide me with several eth0:x interfaces. Now I want to programmatically determine which interface or IP address a request is coming through.
For example; I have eth0:1 = 192.168.227.205 and eth0:2 = 192.168.227.206
From my laptop I can ping either address.
In linux I want to run a program that responds differently based on the IP address being hit. If .205 do this if .206 do that.
How can I programmatically determine which IP address is being hit?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There's getifaddrs function, defined in ifaddr.h. Calling it will retrieve an array of interfaces and IP addresses.
http://man7.org/linux/man- pages/man3 /getifaddr s.3.html
http://man7.org/linux/man-
ASKER