TCP/IP Learning---4 (Linux network base API)

Source: Internet
Author: User

1 sockaddr_in, sockaddr_in6, and Sockadd_un can be cast to sockaddr.

The 2 IP address is a string in the form of a decimal, but is used in the network using a number of type unsigned int.

    1.   in_addr_t inet_addr (const char* strptr);   Returns the address of the IPv4 usigned int type.
    2.   int Inet_aton (const char* CP , struct in_addr* INP);   If nonzero is returned successfully, the 0
    3.  char * INET_NTOA () If the failure returns null if the correct dotted decimal address is returned successfully.
    4.   int net_pton (int af, const char* src, void* DST); Dot decimal is converted to a network address. Applies to IPv4 and IPv6
    5. const char* inet_ntop (int af, const void* SRC, char* DST, socklen_t CNT); The network address is converted into a dotted decimal address. Applies to IPv4 and IPv6

3 function Listen, the second parameter backlog, indicates the maximum length of the kernel listener queue, if the number of the set value of +1 is exceeded (if the test is more than the set value in Windows connection, will not be connected), the server will not accept new customer connections. As long as you do not accept, the number of sockets in the kernel queue will not be reduced.

4 Close: When we close the connection, we use close to actually just subtract the reference count of the file descriptor by 1, and one fork causes the open see Descriptor reference count in the parent process to be added by 1. So in this case we should do a close to the file descriptor in the parent-child process. If you want to terminate the connection directly, you can use the shutdown function, with the values of the parameter howto shut_rd, SHUT_WR, and Shut_rdwr respectively.

5 Msg_oob data. The send and RECV functions can set the message options, when set to emergency data (MSG_OOB), only one byte of emergency data, if the message sent is a multibyte message, only the most one byte is the emergency data.

6 UDP sends data using SENDMSG, receiving data using RECVMSG, similar to send and recv, is just the parameters of the socket address structure. These two functions can also be used with TCP, when used for TCP, with the following two parameters set to null.

TCP/IP Learning---4 (Linux network base API)

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.