Question

I am converting a unit that holds a network interface list to be cross platform. The current version uses raw winsock to obtain the address, mask and broadcast address for each network interface in the system.

I figure the easiest way to make this cross platform is to use Indy. I have found that AddLocalAddressesToList is a nice simple way to get the IP address of all the interfaces but I cannot find out how to get the other information I need (mask and broadcast address). I think I can calculate the broadcast address so its really just the mask that I cant figure out.

FYI. This is the code I found to get the IP addresses of all interfaces.

TIdStack.IncUsage;
try
  GStack.AddLocalAddressesToList(Memo1.Lines);
finally
  TIdStack.DecUsage;
end;
Was it helpful?

Solution

WinSock does not support reporting that kind of info. You have to use OS-specific APIs instead. On Windows, that means using the Win32 API GetAdaptersInfo() and GetAdaptersAddresses() functions. On other platforms, you can use the getifaddrs() function where available.

Indy does not currently support what you are asking for. Also, do note that at this time, AddLocalAddressesToList() only supports IPv4 addresses on most platforms, including Windows.

Support for retreiving local IPv6 addresses, as well as other info like subnet masks, is currently in the works, but there is no ETA on its availability yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top