WsGetNameAddress Procedure

Returns the address for a specified host name or string address.

Syntax

[ vAddress = ] WsGetNameAddress ( sName[, bIPv6][, bString] )

The WsGetNameAddress procedure syntax has the following parts:

 

Name

Type

Description

vAddress

Long

Returned address of host name specified by sName:

  • IPv4 string address (x.x.x.x), or long number.

  • IPv6 string address (x:x:x:x:x:x:x:x%s or shorter notations using ::, %s is scope id), or array of 16 elements (vtUI1 vtArray.

If error occurs (host does not exist), the return is -1 for Ipv4, vtEmpty for Ipv6, or empty string when bString is True.

bIPv6

Val Bool

Optional. Default is False for IPv4 address, TRUE for IPv6 address. ATEasy 2024 (v13)

bString

Val Bool

Optional. Default is False for returning raw network address, True is for string address. ATEasy 2024 (v13)

sName

Val BString

Character string representing a number expressed in the Internet standard ".'' (dotted) notation. or a host name.

Comments

The WsGetNameAddress function converts a string containing an Internet address string (IPv4 or IPv6) or a host name into a proper address for the usage of the Wsxxxx functions. IPv6 is supported from ATEasy 2024 (v13),

The WsGetNameAddress function interprets the character string specified by the sName parameter. This string represents a host name (i.e. "ibm.com"), or a numeric Internet address expressed in the Internet standard ".'' notation IPv4, or a string containing : or :: to express IPv6 address. The value returned is a number suitable for use as an Internet address. All Internet addresses are returned in IP's network order (bytes ordered from left to right).

IPv4 Internet Addresses

IPv4 Values specified using the ".'' notation take one of the following forms:

a.b.c.d a.b.c a.b a

When four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the 4 bytes of an Internet address. When an Internet address is viewed as a 32-bit integer quantity on the Intel architecture, the bytes referred to above appear as "d.c.b.a''. That is, the bytes on an Intel processor are ordered from right to left.

The parts that make up an address in "." notation can be decimal, octal or hexadecimal. Numbers that start with "0x" or "0X" imply hexadecimal. Numbers that start with "0" imply octal. All other numbers are interpreted as decimal.

Example

Type

"4.3.2.16"

Decimal

"004.003.002.020"

Octal

"0x4.0x3.0x2.0x10"

Hexadecimal

"4.003.002.0x10"

Mix

IPv6 Internet Addresses

You can also specify IPv6 address string. The string contains up to 8 hexadecimal numbers separated by ":". A single ":: " can also be used representing single or multiple 0000 to complete the address to 8 hexadecimal numbers.

For example:

fe80:0000:0000:0000:9ce6:0108:f120:4704

Can also specify as:

fe80::9ce6:108:f120:4704  

in this case the :: replace 3 zero (0000) numbers.

Sometimes the number can also have a scope id (%s) at the end representing the interface number in the computer:

fe80::9ce6:108:f120:4704%2

Example

The following examples show some sample output of calling WsGetNameAddress with different parameters:

print "WsGetNameAddress(\"1.2.3.4\")->"; WsGetNameAddress("1.2.3.4")      ! 0x4030201

print "WsGetNameAddress(\"unit255-1\")->"; WsGetNameAddress("unit255-1")  ! some known hostname

print "WsGetNameAddress(\"1.2.3.4.5\")->"; WsGetNameAddress("1.2.3.4.5")  ! erroneous address

! hexadecimal representation of the address

print "WsGetNameAddress(\"1.2.3.4.5\")->"; str(WsGetNameAddress("1.2.3.4.5"), 16) ! error (-1)

print "WsGetNameAddress(\"1.2.3.4\")->"; str(WsGetNameAddress("1.2.3.4"), 16)     ! network byte order

print "WsGetNameAddress("unit208", True, True)->"; WsGetNameAddress("unit208", True, True)

print "WsGetNameAddress("localhost", True, True)->"; WsGetNameAddress("localhost", True, True)

print "WsGetNameAddress("localhost", True, False)->"; WsGetNameAddress("localhost", True, False)

Yields:

WsGetNameAddress("1.2.3.4")->67305985          

WsGetNameAddress("unit255-1")->2787616206

WsGetNameAddress("1.2.3.4.5")->4294967295

WsGetNameAddress("1.2.3.4.5")->ffffffff

WsGetNameAddress("1.2.3.4.5")->4030201

WsGetNameAddress("unit208", True, True->fe80::9ce6:108:f120:4704%2

WsGetNameAddress("localhost", True, True)->::1

WsGetNameAddress("localhost", True, False)->{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}

 

See Also

WsBind, WsGetAddress, WsGetAddressName, WsGetName