|
Description
Use of the inet_addr(), inet_lnaof(), inet_makeaddr(), inet_netof() inet_network() and inet_ntoa() functions only makes sense in the AF_INET address family.
The inet_addr() function converts the character string pointed to by the cp parameter from the dot notation usual for IPv4 addresses into an integer value. This integer value can then be used as the Internet address.
The inet_lnaof() function extracts the local network address in the byte order of the host, from the Internet host address passed in the in parameter.
The inet_makeaddr() function creates an Internet address from
the subnetwork section of the Internet address specified in the net parameter and
the subnetwork-local address section specified in the lna parameter.
The subnetwork section of the Internet address and subnetwork-local address section are both passed in the byte order of the host.
The inet_netof() function extracts the network number in the byte order of the host, from the Internet address passed in the in parameter.
The inet_network() function converts the character string to which pointer cp points, from the dot notation usual for IPv4 addresses into an integer value which can then be used as the subnetwork section of the Internet address.
The inet_ntoa() function converts the Internet address passed in the in parameter into a character string according to the dot notation usual for IPv4 addresses.
All Internet addresses are returned in network byte order in which the bytes are arranged from left to right.
Values can be specified in the following period notation formats:
a.b.c.d
If a four-part address is specified, each part is interpreted as one data byte and assigned from left to right to the four bytes of an Internet address.a.b.c
If a three-part address is specified, the last part is interpreted as a 16-bit sequence and transferred to the two right bytes of the Internet address. This allows three-part address formats to be used without problems for specifying class B addresses (e.g. net.host).a.b
If a two-part address is specified, the last part is interpreted as a 24-bit sequence and transferred to the right three bytes of an Internet address. This allows three-part address formats to be used without problems for specifying class A addresses (e.g. net.host).a
If a single-part address is specified, the value is transferred without changing the byte order directly to the network address.
The numbers specified as address parts in period notation may be either decimal, octal or hexadecimal numbers:
Numbers not prefixed with either 0, 0x or 0X are interpreted as decimal numbers.
Numbers prefixed with 0 are interpreted as octal numbers.
Numbers prefixed with 0x or 0X are interpreted as hexadecimal numbers.
Return value
After successful execution, inet_addr() returns the Internet address. Otherwise, (in_addr_t)-1 is returned.
After successful execution, inet_network() returns the converted Internet number.Otherwise, (in_addr_t)-1 is returned.
The inet_makeaddr() function returns the created Internet address.
The inet_lnaof() returns the local network address.
The inet_netof() function returns the network number.
The inet_ntoa() returns a pointer to the network address in the normal Internet period notation.
Errors
No errors are defined.
Note
The return value of inet_ntoa() may point to static data which can be overwritten by subsequent inet_ntoa() calls.