Linux C network address translation function _IP family

IP address is usually expressed as "dotted decimal" mode, in the Linux network programming will use the 32-bit binary value, the Linux group provides functions for converting the two values, these functions include inet_aton, inet_ntoa inet_addr and so on.

IP address translation function family

  • inet_aton function for an IP address in dotted decimal network byte order converted into 32-bit binary value. Input dotted decimal IP straddr stored in the parameter, and returns the result of the binary values ​​stored in addrptr.
#include <arpa/inet.h>
int inet_aton (const char *straddr, struct in_addr *addrptr);
  • Results inet_ntoa function call is returned as the return value of the function to the calling function.
#include <arpa/inet.h>
char *inet_ntoa (struct in_addr inaddr);
  • Inet_aton function int_addr function and the same function, but different ways of transmitting the results. The decimal point input the number of parameters stored in the straddr the IP, but the results returned in the form of a return value, the function type in_addr_t, unlike inet_aton integer.
#include < arpa/inet.h>
in_addr_t inet_addr (const char *straddr);
Published 70 original articles · won praise 131 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_43239560/article/details/103054520