Html that is stored on the cmu web server if the user

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: olution was to define sockets functions to expect a pointer to a generic sockaddr structure, and then require applications to cast pointers to protocol-specific structures to this generic structure. To simplify our code examples, we will follow Stevens’s lead and define the following type 1 typedef struct sockaddr SA; that we use whenever we need to cast a protocol-specific structure to a generic one. 12.5.2 The socket Function Clients and servers use the socket function to create a socket descriptor. #include <sys/types.h> #include <sys/socket.h> int socket(int domain, int type, int protocol); returns: nonnegative descriptor if OK, -1 on error In our codes, we will always call the socket function with the following arguments: 1 sockfd = Socket(AF_INET, SOCK_STREAM, 0); where AF INET indicates that we are using the Internet, and SOCK STREAM indicates that the socket will be an endpoint for an Internet connection. The sockfd descriptor returned by socket is only partially opened and cannot yet be used for reading and writing. How we finish opening the socket depends on...
View Full Document

Ask a homework question - tutors are online