What is struct sockaddr?
sockaddr. The first structure is sockaddr that holds the socket information − struct sockaddr { unsigned short sa_family; char sa_data[14]; }; This is a generic socket address structure, which will be passed in most of the socket function calls. The following table provides a description of the member fields −
What is the size of Sockaddr_in?
With IPv4 (what basically everyone in 2005 still uses), the struct s_addr is a 4-byte number that represents one digit in an IP address per byte. (You won’t ever see an IP address with a number in it greater than 255.)
What does the struct In_addr structure represent?
The in_addr structure represents an IPv4 Internet address.
What type is Inaddr_any?
This is an IP address that is used when we don’t want to bind a socket to any specific IP.
What is the job of the Connect INT Sockfd const struct sockaddr * addr Socklen_t Addrlen function?
Bind: int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); After creation of the socket, bind function binds the socket to the address and port number specified in addr(custom data structure).
What is the value of Inaddr_any?
It means ‘listen at any interface’. To quote the above link: “When INADDR_ANY is specified in the bind call, the socket will be bound to all local interfaces.” From another link: The value “INADDR_ANY” means that we will bind to any/all IP addresses that the local computer currently has.
What are Htons used for?
The htons() function translates a short integer from host byte order to network byte order. The unsigned short integer to be put into network byte order. Is typed to the unsigned short integer to be put into network byte order.
What is Sockfd?
sockfd is the listening socket descriptor. information about incoming connection is stored in. addr which is a pointer to a local struct sockaddr_in. addrlen is set to sizeof(struct sockaddr_in)
What is Af_inet in socket?
This address family provides interprocess communication between processes that run on the same system or on different systems. Addresses for AF_INET sockets are IP addresses and port numbers. You can specify an IP address for an AF_INET socket either as an IP address (such as 130.99.
What is Htons and Ntohs?
The htons() function converts the unsigned short integer hostshort from host byte order to network byte order. The ntohl() function converts the unsigned integer netlong from network byte order to host byte order.
What is a sock stream?
SOCK_STREAM. Provides sequenced, two-way byte streams with a transmission mechanism for stream data. This socket type transmits data on a reliable basis, in order, and with out-of-band capabilities. In the UNIX domain, the SOCK_STREAM socket type works like a pipe.