Linuxsocket note constants & predefined INADDR_ANY

Source: Internet
Author: User
Linuxsocket note constant & amp; pre-defined INADDR_ANY and other INADDR_ANY: all address definitions: # include & lt; netinet/in. h & gt; INADDR_ANY indicates the address 0.0.0.0. In fact, this address indicates an uncertain address, or all or any address. In general...
Linux socket note constants & predefined INADDR_ANY and other INADDR_ANY: all address definitions: # include <netinet/in. h> INADDR_ANY indicates the address 0.0.0.0. In fact, this address indicates an uncertain address, "all addresses", or "any address ". Generally, it is defined as 0 in each system. Www.2cto.com/* Address to accept any incoming messages. */# define INADDR_ANY (in_addr_t) 0x00000000) serveraddr. sin_addr.s_addr = INADDR_ANY; char * local_addr = "0.0.0.0"; serveraddr. sin_addr.s_addr = inet_addr (local_addr); // converts inet_addr to several bytes in the network's byte order. conversion function: · htonl (): convert 32-bit values from the host byte to the network byte order · htons (): convert 16-bit values from the host byte order to the network byte order · ntohl (): convert 32-bit values from the network byte to the host byte order · ntohs (): convert 16-bit values from the network byte order to the host byte order FD_ZERO (fd_set * set) ---- clears a file descriptor set; FD_SET (int fd, fd_set * set) ---- add a file descriptor to the file descriptor set; FD_CLR (int fd, fd_set * set) ---- clear a file descriptor from the file descriptor set; FD_ISSET (int fd, fd_set * set) ---- try to determine whether the file descriptor is set. Socket parameters. Www.2cto.com int socket (int domain, int type, int protocol); in the parameter table, the domain specifies the address type, which is commonly used: PF_INET, AF_INET: Ipv4 network protocol; PF_INET6, AF_INET6: Ipv6 network protocol. The type parameter is used to set the protocol type of communication. the possible values are as follows: SOCK_STREAM: provides connection-oriented stable data transmission, that is, TCP protocol. OOB: you must use connect () to establish the connection status before transmitting all data. Www.2cto.com SOCK_DGRAM: use non-continuous and unreliable data packet connection. SOCK_SEQPACKET: provides continuous and reliable data packet connection. SOCK_RAW: provides original network protocol access. SOCK_RDM: provides reliable data packet connection. SOCK_PACKET: directly communicates with the network driver.
 
Related Article

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.