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

2024-02-17 Thread Forest via Digitalmars-d-learn
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.


Re: length's type.

2024-02-17 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 14 February 2024 at 00:56:21 UTC, Kevin Bailey 
wrote:
Personally, I don't have a problem with .length being unsigned. 
How do you have a negative length? My problem is that the 
language doesn't correctly compare signed and unsigned.


The length itself is technically the index of a non-existing 
element right after the array. And -1 is technically the index of 
a non-existing element right before the array. Hence just 
mechanically reversing the direction of processing array elements 
during refactoring may be potentially dangerous if one is not 
careful enough.