Skip to content

Commit 7bf2d07

Browse files
committed
std/socket: use inet_ntop for toAddrString
Additionally, fix a misleading comment.
1 parent f879790 commit 7bf2d07

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

std/socket.d

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ abstract class Address
12841284
// libraries shipped with DMD. Thus, we check for getnameinfo at
12851285
// runtime in the shared module constructor, and use it if it's
12861286
// available in the base class method. Classes for specific network
1287-
// families (e.g. InternetHost) override this method and use a
1287+
// families (e.g. InternetAddress) override this method and use a
12881288
// deprecated, albeit commonly-available method when getnameinfo()
12891289
// is not available.
12901290
// http://technet.microsoft.com/en-us/library/aa450403.aspx
@@ -1863,6 +1863,19 @@ public:
18631863
sin6 = addr;
18641864
}
18651865

1866+
version (Posix)
1867+
{
1868+
/// Human readable string representing the IPv6 address in RFC 2373 form.
1869+
override string toAddrString() @trusted const
1870+
{
1871+
char[INET6_ADDRSTRLEN] buf;
1872+
string addrString = to!string(
1873+
.inet_ntop(AddressFamily.INET6, &sin6.sin6_addr, cast(char*) buf, INET6_ADDRSTRLEN)
1874+
);
1875+
return addrString;
1876+
}
1877+
}
1878+
18661879
/**
18671880
* Parse an IPv6 host address string as described in RFC 2373, and return the
18681881
* address.

0 commit comments

Comments
 (0)