C language between the network address and binary number conversion function summary
- 2020-04-02 03:21:14
- OfStack
C language inet_ntoa() function: the network binary number into the network address
The header file:
#include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
Definition function:
char * inet_ntoa(struct in_addr in);
Inet_ntoa () converts the network binary number referred to by the parameter in toa network address and returns a pointer to the network address string.
Return value: returns a string pointer on success and NULL on failure.
C inet_aton() function: converts a network address to a network binary number
The header file:
#include <sys/scoket.h> #include <netinet/in.h> #include <arpa/inet.h>
Definition function:
int inet_aton(const char * cp, struct in_addr *inp);
Inet_aton () is used to convert the network address string referred to by the parameter cp to the binary number used by the network, and then stored in the in_addr structure referred to by the parameter inp.
The structure in_addr is defined as follows
struct in_addr
{
unsigned long int s_addr;
};
Return value: non-zero on success, zero on failure.
C inet_addr() function: converts a network address to a binary number
The header file:
#include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
Definition function:
unsigned long int inet_addr(const char *cp);
Inet_addr () is used to convert the network address string referred to by the parameter cp into the binary number used by the network.
Return value: returns the corresponding network binary number on success, and -1 on failure.