<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

CS 779/879
Design of Network Protocols
Spring 2009
Midterm Exam
Time 2 & 1/2 hours
Open Book

 

 

 

Name:

 

Login:

 

All questions are of equal weights.


 Question 1:

 

A.     How to find out the IPv4 addresses of ALL our something machines?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

B.  How to find out the IPv6 addresses of ALL our something machines?


 Question 2:

Assume a TCP server with the following code:

main()
{
   int sd;
   struct   sockaddr_in name;
      
   sd = socket (PF_INET,SOCK_STREAM,0);
   name.sin_family = AF_INET;
   name.sin_addr.s_addr = htonl(INADDR_ANY);
   name.sin_port = htons(12345);
   bind( sd, (SA *) &name, sizeof(name) );
   listen(sd,0);
   pause();
}
 
 
  1. Assume we have four TCP clients tried to connect to this server. Describe what might happen to each of these four clients.

 

 

 

 

 

 

 

 

 

 

  1. Describe how to find the owner names of the clients connected to this server.

 


Question 3:

Q3S.c:
main()
{
   int sd, psd;
   struct   sockaddr_in name;
   sd = socket (PF_INET,SOCK_STREAM,0);
   name.sin_family = AF_INET;
   name.sin_addr.s_addr = htonl(INADDR_ANY);
   name.sin_port = htons(12345);
   bind( sd, (SA *) &name, sizeof(name) );
   listen(sd,0);
   printf(“%d\n”, sd);
   for(;;) {
       psd = accept(sd, 0, 0);
       printf(“%d\n”, psd);
   }
}
Q3C.c:
main()
{
       int    i, sd[4];
       struct sockaddr_in server;
       struct  hostent *hp, *gethostbyname();
       server.sin_family = AF_INET;
       hp = gethostbyname(“localhost”);
       bcopy ( hp->h_addr, &(server.sin_addr.s_addr), hp->h_length);
       server.sin_port = htons(12345);
      for (i=0;i<4;i++){
        sd[i] = socket (AF_INET,SOCK_STREAM,0);
        if (connect(sd[i], (SA *) &server, sizeof(server))<0)
             perror("connect error"); 
      }
}

Whet is the printout of the following:

% Q3S

 

 

 

When you go to another window at the same host and type:

% Q3C


Question 4:

 
sendmsg.c
 
main(int argc, char **argv)
{
   int sendsock;
   struct sockaddr_in dest;
   char sendBuf[MAX_LEN];
   int bytes=0;
 
   sendsock = socket(PF_INET,SOCK_DGRAM, 0);
   dest.sin_family = AF_INET;
   dest.sin_addr.s_addr = inet_addr(argv[1]);
   dest.sin_port =  htons(atoi(argv[2]));
 
   memset(sendBuf, '\0', MAX_LEN);
 
   while ((bytes = read(1,sendBuf,MAX_LEN)) > 0) 
      
       sendto(sendsock, sendBuf,bytes,0, (SA*)&dest, sizeof(dest));                    
     
}

 

Give an example of how to use this program to send:

 

A. Unicast messages

 

 

 

 

 

B. Multicast message

 

 


Question 5:

 

How to use tcpdump to:

A.   Capture only the TCP SYN segments.

 

 

 

 

 

 

 

 

B.   Capture IP packets with TTL > 16.

 

 


Question 6:

 

A.     How to make sure that a just terminated tcp connection has been terminated via simulations close?

 

 

 

 

 

 

 

 

B.     Pinging a host may take a long time to return its result. 

Show how to ensure that the ping command will not take longer that 1 second to return.

 

 


Question 7:

 

Describe how to use the sock program to transfer the contents of the directory:  /home/wahab/cs779

from cash.cs.odu.edu  to  godzilla.acpub.duke.edu