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

writeln("Enter IP address:");
string ip = readln().chomp();
try
{
    Address address = parseAddress(ip);
    writefln("Looking up reverse of %s:",
        address.toAddrString());
    try
    {
        string reverse = address.toHostNameString();
        if (reverse)
            writefln("  Reverse name: %s", reverse);
        else
            writeln("  Reverse hostname not found.");
    }
    catch (SocketException e)
        writefln("  Lookup error: %s", e.msg);
}
catch (SocketException e)
{
    writefln("  %s is not a valid IP address: %s",
        ip, e.msg);
}

Meta