Introduction to Network address translation functions in Linux

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.