InternetHost

Class for resolving IPv4 addresses.

Consider using getAddress, parseAddress and Address methods instead of using this class directly.

Members

Functions

getHostByAddr
bool getHostByAddr(uint addr)

Resolve IPv4 address number.

getHostByAddr
bool getHostByAddr(const(char)[] addr)

Same as previous, but addr is an IPv4 address string in the dotted-decimal form a.b.c.d.

getHostByName
bool getHostByName(const(char)[] name)

Resolve host name.

Variables

addrList
uint[] addrList;
aliases
string[] aliases;

These members are populated when one of the following functions are called successfully:

name
string name;

These members are populated when one of the following functions are called successfully:

Examples

InternetHost ih = new InternetHost;

ih.getHostByAddr(0x7F_00_00_01);
assert(ih.addrList[0] == 0x7F_00_00_01);
ih.getHostByAddr("127.0.0.1");
assert(ih.addrList[0] == 0x7F_00_00_01);

if (!ih.getHostByName("www.digitalmars.com"))
    return;             // don't fail if not connected to internet

assert(ih.addrList.length);
InternetAddress ia = new InternetAddress(ih.addrList[0], InternetAddress.PORT_ANY);
assert(ih.name == "www.digitalmars.com" || ih.name == "digitalmars.com",
        ih.name);

/* The following assert randomly fails in the test suite.
 * https://issues.dlang.org/show_bug.cgi?id=22791
 * So just ignore it when it fails.
 */
//assert(ih.getHostByAddr(ih.addrList[0]));
if (ih.getHostByAddr(ih.addrList[0]))
{
    string getHostNameFromInt = ih.name.dup;

    // This randomly fails in the compiler test suite
    //assert(ih.getHostByAddr(ia.toAddrString()));

    if (ih.getHostByAddr(ia.toAddrString()))
    {
        string getHostNameFromStr = ih.name.dup;
        assert(getHostNameFromInt == getHostNameFromStr);
    }
}

Meta