Article title: Introduction to Network address translation functions in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
During socket programming, the ip address and port number are specified but cannot be connected. this is caused by the character sequence of the network address and the local host address.
Some operation functions are provided in linux as follows:
Unsigned long int htonl (unsigned long int hostlong );
It is used to convert the 32-bit hostlong specified by the parameter to the network character sequence.
Unsigned short int htons (unsigned short int hostshort );
It is used to convert the 16-bit hostshort specified by the parameter to the network character sequence.
Unsigned long int inet_addr (const char * cp );
It is used to convert the network address string referred to by the parameter cp to the binary number used by the network.
The network address string is a string composed of numbers and points, for example, "163.13.132.68 ".
Int inet_aton (const char * cp, struct in_addr * indium );
It is used to convert the network address string referred to by the parameter cp to the binary number used by the network, and store it in the in_addr structure referred to by the parameter p.
Char * inet_ntoa (struct in_addr in );
It is used to convert the binary number of the network referred to by the parameter in to the network address, and then return the pointer pointing to the network address string.
Unsigned long inet_network (const char * addr );
This function requires an address input string that contains a vertex separation in the addr parameter.
The returned value is the 32-bit value of the host-ordered IP address.
The inet_lnaof () function returns the local host address part
The Internet address in. The local host address is returned in local host byte order.
The inet_netof () function returns the network number part of the Internet Address in.
The network number is returned in local host byte order.