Helper Functions and Macros

Top  Previous  Next

ntohs

unsigned short ntohs(unsigned short netshort);

 

The ntohs macro converts netshort from network byte order to host byte order.

 

Parameter

netshort

network byte-order value to convert.

Return value

The ntohs macro returns a host-order unsigned short.

htons

unsigned short htons(unsigned short hostshort);

 

The htons macro converts hostshort from host byte order to network byte order.

 

Parameter

hostshort

host byte-ordered value to convert.

Return value

The htons macro returns a network-ordered unsigned short.

inet_aton

int inet_aton(const char *cp, struct in_addr *addr);

 

inet_aton converts the specified string from the Internet standard dot notation to a network address and stores the address in the structure provided.  The converted address is in network byte order (bytes ordered from left to right).

 

Values specified using dot notation take one of the following forms:

 

a.b.c.d

When four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the four bytes of an internet address.

a.b.c

When a three-part address is specified, the last part is interpreted as a 16-bit quantity and placed in the rightmost two bytes of the network address. This makes the three-part address format convenient for specifying Class B network addresses as 128.net.host.

a.b

When a two-part address is supplied, the last part is interpreted as a 24-bit quantity and placed in the rightmost three bytes of the network address. This makes the two-part address format convenient for specifying Class A network addresses as net.host.

a

When only one part is given, the value is stored directly in the network address without any byte rearrangement.

 

All numbers supplied as parts in dot notation may be decimal, octal, or hexadecimal, as specified in the ISO C standard (that is, a leading 0x or 0X implies hexadecimal, a leading 0 implies octal, otherwise the number is interpreted as decimal).

 

Parameters

cp

points to a string in Internet standard dot notation.

addr

is a buffer where the converted address is to be stored.

 

Return value

inet_aton returns 1 if the address is successfully converted, or 0 if the conversion failed.