parseAddress

Provides _protocol-independent parsing of network addresses. Does not attempt name resolution. Uses getAddressInfo with AddressInfoFlags.NUMERICHOST if the current system supports it, and InternetAddress otherwise.

  1. Address parseAddress(const(char)[] hostaddr, const(char)[] service)
    @safe
    parseAddress
    (
    scope const(char)[] hostaddr
    ,
    scope const(char)[] service = null
    )
  2. Address parseAddress(const(char)[] hostaddr, ushort port)

Return Value

Type: Address

An Address instance representing specified address.

Throws

SocketException on failure.

Examples

1 writeln("Enter IP address:");
2 string ip = readln().chomp();
3 try
4 {
5     Address address = parseAddress(ip);
6     writefln("Looking up reverse of %s:",
7         address.toAddrString());
8     try
9     {
10         string reverse = address.toHostNameString();
11         if (reverse)
12             writefln("  Reverse name: %s", reverse);
13         else
14             writeln("  Reverse hostname not found.");
15     }
16     catch (SocketException e)
17         writefln("  Lookup error: %s", e.msg);
18 }
19 catch (SocketException e)
20 {
21     writefln("  %s is not a valid IP address: %s",
22         ip, e.msg);
23 }

Meta

Suggestion Box / Bug Report