getAddressInfo

Provides _protocol-independent translation from host names to socket addresses. If advanced functionality is not required, consider using getAddress for compatibility with older systems.

@safe
getAddressInfo
(
T...
)
(
scope const(char)[] node
,
scope T options
)

Parameters

node const(char)[]

string containing host name or numeric address

options T

optional additional parameters, identified by type:

  • string - service name or port number
  • AddressInfoFlags - option flags
  • AddressFamily - address family to filter by
  • SocketType - socket type to filter by
  • ProtocolType - protocol to filter by

Return Value

Type: AddressInfo[]

Array with one AddressInfo per socket address.

Throws

SocketOSException on failure, or SocketFeatureException if this functionality is not available on the current system.

Examples

1 // Roundtrip DNS resolution
2 auto results = getAddressInfo("www.digitalmars.com");
3 assert(results[0].address.toHostNameString() ==
4     "digitalmars.com");
5 
6 // Canonical name
7 results = getAddressInfo("www.digitalmars.com",
8     AddressInfoFlags.CANONNAME);
9 assert(results[0].canonicalName == "digitalmars.com");
10 
11 // IPv6 resolution
12 results = getAddressInfo("ipv6.google.com");
13 assert(results[0].family == AddressFamily.INET6);
14 
15 // Multihomed resolution
16 results = getAddressInfo("google.com");
17 assert(results.length > 1);
18 
19 // Parsing IPv4
20 results = getAddressInfo("127.0.0.1",
21     AddressInfoFlags.NUMERICHOST);
22 assert(results.length && results[0].family ==
23     AddressFamily.INET);
24 
25 // Parsing IPv6
26 results = getAddressInfo("::1",
27     AddressInfoFlags.NUMERICHOST);
28 assert(results.length && results[0].family ==
29     AddressFamily.INET6);

Meta

Suggestion Box / Bug Report