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

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

 

 

 

Name:

 

Login:

 

All questions are of equal weights.

 


Question 1: 20 points

 

A.     If you are logged into a UNIX/LINUX  host. How to find   the name of that host,  its IPv4 and IPv6 addresses?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

B.     If you know a host IPv4 address and you do not have a login access to that host, how to find   the name of that host, and its IPv6 addresses?


Question 2: 30 points

To allow two groups to exchange multicast messages we may use a udp tunnel between the two groups A and B  (e.g. ODU and UNC)  as shown below:

FigMidterm

The program mTunnel has the following syntax:

mTunnel <RemoteIP> <GroupIP> <Port>

 

Example:

We may run the mTunnel  between  two sites  e.g. ODU  ( host 128.82.4.98) &  UNC  (host 152.2.131.244) as follows:

 ODU  % mTunnel     152.2.131.244   224.0.0.3   10333

 UNC  % mTunnel     128.82.4.98       224.0.0.4   10333

 

Any person at ODU or at UNC  may  chat together by  running  the mcastChat as follows:

 

% mcastChat 224.0.0.3 10333

 

In such case you will see the messages exchanged between ODU and UNC chatters via the two mTunnel programs running at 128.82.4.98  and  152.2.131.244.

 

The following is an outline code for the mTunnel program.

You are required to implement the  missing function HandleTraffic() using the following three different implementations:

1.      Select

2.      Thread

3.      Fork


#define SA      struct sockaddr

int             UnicastSocket, MulticastSocket;

struct sockaddr_in RemoteAddress;

struct sockaddr_in LocalAddress;

struct sockaddr_in GroupAddress;

struct hostent *hp, *gethostbyname();

char            RemoteIP[100];

char            RemotePort[100];

char            GroupIP[100];

char            GroupPort[100];

char            LocalPort[100];

int main(int argc, char **argv)

{

   strcpy(RemoteIP, argv[1]);

   strcpy(GroupIP, argv[2]);

   strcpy(LocalPort, argv[3]);

   strcpy(RemotePort, argv[3]);

   strcpy(GroupPort, argv[3]);

 

   RemoteAddress.sin_family = AF_INET;

   RemoteAddress.sin_addr.s_addr = htonl (inet_addr (RemoteIP));

   RemoteAddress.sin_port = htons(atoi(RemotePort));

 

   LocalAddress.sin_family = AF_INET;

   LocalAddress.sin_addr.s_addr = htonl(INADDR_ANY);

   LocalAddress.sin_port = htons(atoi(LocalPort));

   UnicastSocket = socket(AF_INET, SOCK_DGRAM, 0);

   reusePort(UnicastSocket);

   if (bind(UnicastSocket,(SA*)&LocalAddress, sizeof(LocalAddress))<0) {

      close(UnicastSocket);

      perror("binding UnicastSocket socket");

      exit(-1);

   }

 

   GroupAddress.sin_family = AF_INET;

   GroupAddress.sin_addr.s_addr = htonl (inet_addr (GroupIP));

   GroupAddress.sin_port = htons(atoi(GroupPort));

   MulticastSocket = socket(AF_INET, SOCK_DGRAM, 0);

   reusePort(MulticastSocket);

   if (bind(MulticastSocket,(SA*)&GroupAddress, sizeof(GroupAddress))<0) {

      close(MulticastSocket);

      perror("binding MulticastSocket socket");

      exit(-1);

   }

   joinGroup(MulticastSocket, (char *) GroupIP);

   setLoopback(MulticastSocket, 0);

 

   HandleTraffic();

 

}


 

 

1.      Select implementation:


 

2.      Thread implementation:


 

3.      Fork implementation:


Question 3: 30 points

Consider the following executions of Server and Client:

Q3Srv.c

int main(int argc, char *argv[])
{
     int             sd;
     struct sockaddr_in server;
     struct hostent *hp, *gethostbyname();
     char            buf[512];
     int             rc;

 

     sd = socket(AF_INET, SOCK_DGRAM, 0);

     reusePort(sd);

     server.sin_family = AF_INET;
     server.sin_port = 10234;
     if (argc == 1) server.sin_addr.s_addr = htonl(INADDR_ANY);
     else if (argc == 2) {
          server.sin_addr.s_addr = htonl (inet_addr (argv[1]));

         joinGroup(argv[1]);
     }
     bind(sd, (SA *) & server, sizeof(server));

     for (;;) {
          rc = recv(sd, buf, sizeof(buf), 0);
          buf[rc] = (char) NULL;
          printf("Received: %s\n", buf);
     }
}


 

 

A.

Assume we run the server  simultaneously on  different ssh windows on host something (128.82.4.210) as follows in that order:

S1: Q3Srv 127.0.0.1

S2: Q3Srv 128.82.4.210

S3: Q3Srv 224.0.0.1

S4: Q3Srv

 

 

And assume we run the UDPClient1 on the same host something on different ssh windows as follows:

C1:  UDPClient1  127.0.0.1          10234

C2:  UDPClient1  128.82.4.210    10234

C3:  UDPClient1  224.0.0.1          10234

 

Fill the following table with Y or N.

Y: means the server will receive the client messages.

N: means the server will NOT receive the client messages.

 

 

S1

S2

S3

S4

C1

 

 

 

 

C2

 

 

 

 

C3

 

 

 

 

 

 

 

B.

Repeat A if the UDPClient1  runs on host somethingels instead of something..

 

 

 

S1

S2

S3

S4

C1

 

 

 

 

C2

 

 

 

 

C3

 

 

 

 

 

 

 


 

Question 4:20 points

A.     Consider the following program:

Q4Clt.c

 

main(int argc, char *argv[])
{
     int             sendsock;
     struct sockaddr_in dest;
     struct sockaddr_in server;
     char            sendBuf[512];
     char            buf[512];
     int             bytes;
     int             rc;


     dest.sin_family = AF_INET;
     dest.sin_port = 10234;
     dest.sin_addr.s_addr = inet_addr(argv[1]);


     sendsock = socket(PF_INET,
SOCK_DGRAM, 0);
     reusePort(sendsock);


     if ( bind(sendsock, (SA *) &dest, sizeof(dest)) < 0) {

        perror(“Error in binding sendsock”);

        exit (-1);

    }


     sendto(sendsock, “HI”, 2, 0, (SA *) & dest, sizeof(dest));

while (;;) {
     rc = recv(sendsock, buf, sizeof(buf), 0);
     buf[rc] = NULL;
     printf("Received Back: %s\n", buf);

    }

}

Describe and explain what happens if we run the following clients on different ssh windows on host something (128.82.4.210)  as follows in that order:

C1: Q4Clt 128.82.4.210

C2: Q4Clt 128.82.4.210

C3: Q4Clt 128.82.4.210

 

 

 

 

 

 

 

 

 

What will happen if we run these programs as described above on any host other than something?


 

 

 

B.     Consider the following program:

 

Q4Srv.c

main(int argc, char *argv[])
{
     int sd;
     struct sockaddr_in server;
     struct hostent *hp, *gethostbyname();
     struct sockaddr_in from;
     char buf[512];
     int rc;
     int len;
     server.sin_family = AF_INET;
     server.sin_port = 10234;
     server.sin_addr.s_addr = htonl(INADDR_ANY);
     sd = socket(AF_INET,
SOCK_STREAM, 0);
     reusePort(sd);
     if ( bind(sd, (SA *) & server, sizeof(server)) < 0) {

          perror(sd bind failed”);

          exit(-1);

     }

     listen(sd, 0);

     psd = accept (sd, 0, 0);

     
     while (1) {
          len = sizeof(from);
          rc = read(psd,buf,sizeof(buf));
          buf[rc] = NULL;
          printf("Received: %s\n", buf);
          write (psd, buf, rc);
     }
}

 

Describe and explain what happens if we run the following  on different ssh windows on  the same host  as follows in that order:

S1: Q4Srv

S2: Q4Srv