The server uses the sufx indexhtml to nd the le on

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: e well-known port port. It returns a file descriptor that is ready for input and output using Unix file I/O. code/src/csapp.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 int open_clientfd(char *hostname, int port) { int clientfd; struct hostent *hp; struct sockaddr_in serveraddr; clientfd = Socket(AF_INET, SOCK_STREAM, 0); /* fill in the server’s IP address and port */ hp = Gethostbyname(hostname); bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; bcopy((char *)hp->h_addr, (char *)&serveraddr.sin_addr.s_addr, hp->h_length); serveraddr.sin_port = htons(port); /* establish a connection with the server */ Connect(clientfd, (SA *) &serveraddr, sizeof(serveraddr)); return clientfd; } code/src/csapp.c Figure 12.24: open clientfd: helper function that establishes a connection with a server. After creating the socket descriptor (line 11), we retrieve the DNS host entry for the server (line 14) and copy the first IP address in the host entry (which is already in network byte order)...
View Full Document

Ask a homework question - tutors are online