Description of inet_ntoa:
Converts a network address to a string format separated.
# Include <Winsock. h>
Char far * Pascal far inet_ntoa (struct in_addr in );
In: An Internet host address structure.
Note:
This function converts an Internet address structure represented by the In parameter to a string separated by ".", such as "A. B. C. D. Note that the strings returned by inet_ntoa () are stored in the memory allocated by the Windows interface. The application should not assume how the memory is allocated. Before calling the next Windows interface of the same thread, the data will be valid.
Return Value:
If no error occurs, inet_ntoa () returns a character pointer. Otherwise, null is returned. The data should be copied before the next Windows interface call.
Inet_addr () Description: converts an interval address into an in_addr address.
# Include <Winsock. h>
Unsigned long Pascal far inet_addr (const struct far * CP );
CP: A string separated by the internet standard.
Note:
This function explains the string in the CP parameter. This string uses the "." interval format of the Internet to represent the Internet address of a number. The return value can be used as an Internet address. All Internet addresses are returned in bytes of the network (bytes are arranged from left to right ).
The addresses separated by "." can be expressed in the following ways:
A. B. C. D, A. B. C, A. B,
When each of the four parts has a fixed value, each part is interpreted as a byte data, which forms an Internet four-byte address from left to right. Note that when an Internet address is expressed as a 32-bit integer on an Intel Server, the above bytes are "d. C. B. ". This is because intel processor bytes are arranged from right to left.
Note: Only Berkeley supports the following expressions, but not the rest of the Internet. Considering the compatibility with the software, it should be used as required.
For a three-part address, the last part is interpreted as 16-bit data and serves as the rightmost two bytes of the network address. In this way, the three addresses can easily represent the network addresses of group B, such as "128.net. Host ".
For a two-part address, the last part is interpreted as 24-bit data and serves as the rightmost three bytes of the network address. In this way, the two-part address can easily represent a group C network address, for example, "net. host ".
For an address with only one part, the value is directly stored in the network address without any reorganizations.
Return Value:
If no error occurs, inet_addr () returns an unsigned long integer, where the Internet address is stored in the appropriate byte sequence. If the input string is not a valid Internet address, for example, if any of the "A. B. C. D" addresses exceeds 255, inet_addr () returns inaddr_none.
See:
Inet_ntoa ().
For example, what does *. sin_addr.s_addr = htonl (innaddr_any) mean?
A: *. sin_addr.s_addr = htonl (innaddr_any) is used in socket programming.
* Any sockaddr_in struct object sin_addr is an attribute of sockaddr_in. It is used to define an IP address. It is a struct in_addr object and s_addr is the object of the in_addr struct, simply put, it is a package of three struct nested packages.
Innaddr_any is generally specified for the kernel. Most systems take 0 to indicate any IP addresses.
Htonl () is a function that converts the IP address of the local machine to the format specified in the network protocol.