How can i find my LAN IP Address using std.socket?

Forest forest at example.com
Sun Feb 18 01:19:34 UTC 2024


On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle 
wrote:
> I'm trying to find my own ip address using std.socket with 
> little success. How would i go about doing this? (It should be 
> a AddressFamily.INET socket)

Sadly, the standard library doesn't seem to offer network 
interface enumeration.

However, if you don't mind delving into platform-specific C APIs 
that are exposed by Phobos but not mentioned in the docs ([issue 
5872](https://issues.dlang.org/show_bug.cgi?id=5872)), it can be 
done. The code I found here was enough to get me started:

https://github.com/Kripth/my-ip/blob/356e02f0/src/myip/private_.d

The key to a linux implementation was `getifaddrs()`, which can 
be found in core.sys.linux.ifaddrs.


More information about the Digitalmars-d-learn mailing list