How to get the list of active interface in a system using C? what API or library i need to use? and Can i choose a particular interface to send data in socket programming? if yes then please give an example.
Asked
Active
Viewed 1,620 times
1
-
You can choose a specific interface by [binding](http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html) it to that interfaces address. – Some programmer dude Aug 09 '13 at 12:06
-
What operating system? (The answer here is more platform-specific than "unix") – Nemo Aug 09 '13 at 14:49
3 Answers
1
If on Linux you might like to take look at:
int getifaddrs(struct ifaddrs **ifap);
The getifaddrs() function creates a linked list of structures describing the network interfaces of the local system, and stores the address of the first item of the list in *ifap.

alk
- 69,737
- 10
- 105
- 255
-
but how to choose a particular interface to send data.(i.e. eth0/wlan0 etc.) – prashant Aug 12 '13 at 02:54
-
@prashant: Send to the interface's address or to an address routed via the interface. – alk Aug 12 '13 at 06:34
-
can this "getifaddrs()" function able to detect interfaces for 3G/4G_LTE modem? it will be great if you can provide an example with output for the same. thanks! – prashant Aug 12 '13 at 10:41
-
@prashant: My answer links to a page containing an example on how to use `getifaddrs()`. – alk Aug 12 '13 at 10:49
0
On Windows, use GetAdaptersInfo()
and/or GetAdaptersAddresses()
.
On most POSIX-compatible systems, you can use getifaddrs()
.

Remy Lebeau
- 555,201
- 31
- 458
- 770