InternetHost

InternetHost is a 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

name
string name;

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

Examples

1 InternetHost ih = new InternetHost;
2 
3 ih.getHostByAddr(0x7F_00_00_01);
4 assert(ih.addrList[0] == 0x7F_00_00_01);
5 ih.getHostByAddr("127.0.0.1");
6 assert(ih.addrList[0] == 0x7F_00_00_01);
7 
8 if (!ih.getHostByName("www.digitalmars.com"))
9     return;             // don't fail if not connected to internet
10 
11 assert(ih.addrList.length);
12 InternetAddress ia = new InternetAddress(ih.addrList[0], InternetAddress.PORT_ANY);
13 assert(ih.name == "www.digitalmars.com" || ih.name == "digitalmars.com",
14         ih.name);
15 
16 assert(ih.getHostByAddr(ih.addrList[0]));
17 string getHostNameFromInt = ih.name.dup;
18 
19 assert(ih.getHostByAddr(ia.toAddrString()));
20 string getHostNameFromStr = ih.name.dup;
21 
22 assert(getHostNameFromInt == getHostNameFromStr);

Meta

Suggestion Box / Bug Report