C network programming-basic functions

Source: Internet
Author: User

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

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.