socket - Socket Programming Quick Reference Data Structures...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Socket Programming Quick Reference Data Structures The sockaddr in data structure contains an IP address and port number. struct sockaddr_in { short int sin_family; // Address family unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address unsigned char sin_zero[8]; // Same size as struct sockaddr };- sin family : Set this to AF INET .- sin port : Port number of socket in network byte order.- sin addr : IP address of socket in network byte order- sin zero : Set this to all zeros to pad structure. The hostent data structure contains information on the name of a host and its IP address. struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }; #define h_addr h_addr_list[0]- h name : Offical name of host.- h aliases : A NULL-terminated array of alternate names for the host.- h addrtype : The type of address being returned; usually AF INET .- h length : The length of the address in bytes.- h addr list : A zero-terminated array of network addresses for the host in network byte order.- h addr : The first address in h addr list . System Calls int socket(int domain, int type, int protocol);- This function creates the socket and returns a unique file descriptor for the socket. The socket can either be a stream (TCP) socket, or a datagram (UDP) socket depending on the input arguments. – domain : Set this to AF INET or PF INET . It doesn’t really matter which one. – type : Specifies what kind of socket. Set this to SOCK STREAM for TCP streams (telnet, http, etc.). Set this to SOCK DGRAM for UDP datagrams. – protocol : Takes one of the following values: * 0: Automatically selects correct protocol based on type ....
View Full Document

Page1 / 3

socket - Socket Programming Quick Reference Data Structures...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online