Chapter 13


Chapter 4

4.1

Look at the definitions for the constants beginning with INADDR_ except INADDR_ANY (which is all zero bits) and INADDR_NONE (which is all one bits). For example, the class D multicast address INADDR_MAX_LOCAL_GROUP is defined as 0xe00000ff with the comment "224.0.0.255," which is clearly in host byte order.

4.2

Here are the new lines added after the call to connect :

 len = sizeof(cliaddr); Getsockname(sockfd, (SA *) &cliaddr, &len); printf("local addr: %s\n", Sock_ntop((SA *) &cliaddr, len)); 

This requires a declaration of len as a socklen_t and a declaration of cliaddr as a struct sockaddr_in . Notice that the value-result argument for getsockname ( len ) must be initialized before the call to the size of the variable pointed to by the second argument. The most common programming error with value-result arguments is to forget this initialization.

4.3

When the child calls close , the reference count is decremented from 2 to 1, so a FIN is not sent to the client. Later, when the parent calls close , the reference count is decremented to 0 and the FIN is sent.

4.4

accept returns EINVAL , since the first argument is not a listening socket.

4.5

Without a call to bind , the call to listen assigns an ephemeral port to the listening socket.




UNIX Network Programming Volume 1, Third Edition
Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition)
ISBN: 0131411551
EAN: 2147483647
Year: 2003
Pages: 441

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net