|
5.1.10 inet_addr ()
Brief description: Convert a dot interval address into an in_addr.
#include <winsock.h>
unsigned long PASCAL FAR inet_addr (const struct FAR * cp);
cp: A string separated by the Internet standard ".".
Notes:
This function interprets the string in the cp parameter. This string uses the Internet "." Interval format to represent a numeric Internet address. The return value can be used as an Internet address. All Internet addresses are returned in network byte order (bytes are arranged from left to right).
Internet addresses with "." Intervals can be expressed in the following ways:
a.b.c.d, a.b.c, a.b, a
When the four parts have a fixed value, each is interpreted as a byte of data, which forms an Internet four-byte address from left to right. Please note that when an Internet address is represented as a 32-bit integer on Intel machines, the above byte is "d.c.b.a". This is because the bytes of Intel processors are arranged from right to left.
Please note: Only Berkeley supports the following expressions, not the rest of the Internet. Considering compatibility with the software, it should be used in accordance with regulations.
For a three-part address, the last part is interpreted as 16-bit data and used as the right-most two bytes of the network address. In this way, the three-part address can easily represent the group B network address, such as "128.net.host".
For a two-part address, the last part is interpreted as 24-bit data and used as the rightmost three bytes of the network address. In this way, the two-part address can easily represent a group C network address, such as "net.host".
For an address with only one part, its value is directly stored in the network address without any byte reorganization.
return value:
If no error occurs, inet_addr () returns an unsigned long integer, which stores the Internet address in the proper byte order. If the string passed in is not a valid Internet address, for example, any of the "a.b.c.d" addresses exceeds 255, then inet_addr () returns INADDR_NONE. |
|