Socket address conversion function Induction

Source: Internet
Author: User
  • Inet_aton ()

Inet_aton () is a 32-bit IP address in the byte sequence of the network.

Syntax:

# Include <sys/socket. h>

# Include <netinet/in. h>

# Include <ARPA/inet. h>

Int inet_aton (const char * string, struct in_addr * ADDR );

  • Inet_ntoa ()

Convert the IP address in the Set interface into a string in dotted-decimal format. The syntax is as follows:

# Include <sys/socket. h>

# Include <netinet/in. h>

# Include <ARPA/inet. h>

Char * inet_ntoa (struct in_addr ADDR );

  • Inet_network ()

Converts an IP address in dotted decimal format to a 32-bit binary IP address in the host's byte sequence. The syntax is as follows:

# Include <sys/socket. h>

# Include <netinet/in. h>

# Include <ARPA/inet. h>

Unsigned long inet_network (const char * ADDR );

The results returned in the byte order of the host can ensure that the user uses the network mask safely. If the returned value is in the network byte order, the network mask and program code used for different CPU platforms are different.

  • Inet_lnaof ()

Convert the IP address (Network byte) in the Set interface address to the host ID (host byte) without network bits ). Syntax:

# Include <sys/socket. h>

# Include <netinet/in. h>

# Include <ARPA/inet. h>

Unsigned long inet_lnaof (struct in_addr ADDR );

For example, inet_lnaof (192.168.9.1) = 0.0.0.1

  • Inet_netof ()

Different from the preceding function, inet_lnaof () returns the host ID, while inet_netof () returns the network ID. Syntax:

# Include <sys/socket. h>

# Include <netinet/in. h>

# Include <ARPA/inet. h>

Unsigned long inet_netof (struct in_addr ADDR );

For example, inet_netof (192.168.9.1) = 0.192.168.9

  • Inet_makeaddr ()

Combine the extracted network and host locations to generate a new IP address. Syntax:

# Include <sys/socket. h>

# Include <netinet/in. h>

# Include <ARPA/inet. h>

Struct in_addr inet_makeaddr (INT net, int host );

Net represents the network bit, and host represents the host bit

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.