tags:

views:

127

answers:

2

Using the output of "ipconfig /all" i can get what I need but I want a more reliable technique to get ip of an interface (practically the interface has to be identified by it's name) in case of ipconfig was corrupted or was not available for any reason.

+3  A: 

I'm not sure what you mean by "server and client", but if you're looking for an API that tells you the IP address(es) associated with the local machine's network interfaces, check out getifaddrs() (for Linux/MacOSX/POSIX) and GetAdaptersAddresses() (for Windows). If you want a usage example for those calls, have a look at the GetNetworkInterfaceInfos() function in this file.

(If you wanted to get the IP address of a client connected to the local machine, call getpeername() on the socket that is associated with that client's connection)

Jeremy Friesner
+2  A: 

Since you mentioned ipconfig, I assume you want to do this on windows. Windows has a set of IP Helper apis designed for retrieval and modify networking settings.

And here is a simple sample: http://msdn.microsoft.com/en-us/library/aa366298%28VS.85%29.aspx

Raymond