The function of conversion between network address and binary number in C language _c language

Source: Internet
Author: User

C language Inet_ntoa () function: Converts the number of network binaries into network addresses
header file:

 #include <sys/socket.h>  #include <netinet/in.h>  #include <arpa/inet.h>

To define a function:

char * INET_NTOA (struct in_addr in);

Function Description: Inet_ntoa () is used to convert the number of network binary digits in the parameter in to the network address, and then returns a pointer to this network address string.

Return value: Returns a string pointer to success and returns NULL if it fails.

C language Inet_aton () function: To convert the network address into a network binary number
header file:

#include <sys/scoket.h>  #include <netinet/in.h>  #include <arpa/inet.h>

To define a function:

int Inet_aton (const char * cp, struct in_addr *INP);

Function Description: Inet_aton () is used to convert the network address string referred to in the parameter CP to a binary number used by the network, and then to be stored in the IN_ADDR structure referred to in the parameter INP.

The structure in_addr is defined as follows

struct in_addr
{
  unsigned long int s_addr;
};

Return value: Success returns a non 0 value, and a failure returns 0.

C language inet_addr () function: The number that converts the network address into binary
header file:

#include <sys/socket.h>  #include <netinet/in.h>  #include <arpa/inet.h>

To define a function:

unsigned long int inet_addr (const char *CP);

Function Description: inet_addr () is used to convert the network address string that the parameter CP refers to into the binary digits used by the network. A network address string is a string of numbers and dots, for example: "163. 13.132. 68 ".

Return value: Success returns the number of the corresponding network binary, failure returns-1.

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.