1.
Byte sorting function, which returns the size-end storage type
# Include <netinet/in. h> // returns the network byte sequence uint32_t htonl (uint32_t hostlong); uint16_t htons (uint16_t hostshort); // returns the host byte sequence uint32_t ntohl (uint32_t netlong ); uint16_t ntohs (uint16_t netshort );
2.
Byte manipulation Function
# Include <strings. h> // set DEST memory to zero void bzero (void * DEST, size_t nbytes); // copy SRC to DEST's nbytesvoid bcopy (const void * SRC, void * DEST, size_t nbytes); // compare the size of int bcmp (const void * ptr1, const void * ptr2, size_t nbytes); // set the bit value void memset (void * DEST, int C, size_t Len); void memcopy (void * DEST, const void * SRC, size_t nbytes); int memcmp (const void * ptr1, const void * ptr2, size_t nbytes );
3.
IP address Conversion Function
# Include <ARPA/inet. h> int inet_aton (const char * straddr, struct in_addr * addrptr); // 1 is returned for success; otherwise 0 char * inet_ntoa (struct in_addr inaddr); // The failure is null, otherwise, the system returns the pointer in_addr_t inet_addr (const char * straddr) to the decimal number string. // The Network byte address of the 32bit binary is returned. If an error occurs, the system returns inaddr_none.
4.
IP and domain name Conversion
# Include <netdb. h> struct hostent * gethostbyname (const char * hostname); struct hostent * gethostbyaddr (const char * ADDR, size_t Len, int family); // return NULL if an error occurs, at the same time, set the global variable h_errno to the corresponding value // host_not_found // try_again // no_recovery // no_data
You can call h_strerror () to return detailed error information.
C network programming-basic functions