Skip to content

Commit fe67050

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

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

std/socket.d

Lines changed: 13 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,18 @@ 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* buf = cast(char*) .malloc(INET6_ADDRSTRLEN);
1872+
string addrString = to!string(.inet_ntop(AddressFamily.INET6, &sin6.sin6_addr, buf, INET6_ADDRSTRLEN));
1873+
.free(buf);
1874+
return addrString;
1875+
}
1876+
}
1877+
18661878
/**
18671879
* Parse an IPv6 host address string as described in RFC 2373, and return the
18681880
* address.

0 commit comments

Comments
 (0)