CS 779/879 Design of Network Protocols Open Book

advertisement
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:
Consider the following commands:
% hostname
something
% ifconfig –a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu
8232 index 1 inet 127.0.0.1 netmask ff000000
eri0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index
2 inet 128.82.4.210 netmask fffffe00 broadcast 128.82.5.255
hme0: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet 0.0.0.0 netmask 0
lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu
8252 index 1 inet6 ::1/128
eri0: flags=2004841<UP,RUNNING,MULTICAST,DHCP,IPv6> mtu 1500 index 2
inet6 fe80::203:baff:fe2a:67ff/10
A. What is hme0 is used for?
B. What are the ipv4 and the ipv6 address of this host?
C. Assume you have no permission to login to a given host name N. Describe how to
obtain:
I.
The ipv4 address of N
II.
The ipv6 address of N
Question 2:
A. Without using tcpdump, how can you tell if a certain TCP connection
has terminated via a simultaneous close?
B. Using tcpdump, how can you tell if a certain TCP connection is
established via a simultaneous open?
Question 3:
A. TCP server called Q3Srv has the following code:
main(int argc, char *argv[])
{
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);
for(;;) {
psd = accept (sd, 0,0);
sleep (atoi (argv[1]));
close (psd);
}
}
A. Assume we have three TCP clients tried to simultaneously connect to Q3Srv. Describe
what might happens to each of the three clients, if the Q3Srv is invoked as:
1. Q3Srv 10
2. Q3Srv 1000
B. If you try to execute Q3Srv on one of our “something” machines and you get an error
message: “Address already in use”. How to find the user name of the process causing
this error? Is it possible to do the same if this happens on a “fast” machine?
Question 4:
A TCP server Q4Srv has the same code as QSrv3 expect that the statement:
name.sin_addr.s_addr = htonl(INADDR_ANY);
Is replaced with:
gethostname(ThisHost, 80);
hp = gethostbyname(ThisHost)
bcopy ( hp->h_addr, &(name.sin_addr.s_addr), hp->h_length);
A TCP client Q4Clt has the following code:
main(int argc, char *argv[] )
{
int
struct
struct
sd;
sockaddr_in server;
hostent *hp, *gethostbyname();
sd = socket (AF_INET,SOCK_STREAM,0);
server.sin_family = AF_INET;
hp = gethostbyname(argv[1]);
bcopy ( hp->h_addr, &(server.sin_addr.s_addr), hp->h_length);
server.sin_port = htons(12345);
if (connect(sd, (SA *) &server, sizeof(server))<0){
printf("connect error\n");
exit(-1);
}
else
printf("connected\n");
}
Assume we started the server as:
something % Q4Srv 10
What is the output of each of the following statements?
something % Q4Clt 128.82.4.210
something % Q4Clt 127.0.0.1
Question 5:
A.
A UDP server Q5Srv has the following code. Modify this code so that the server
receives multicast messages. The multicast group is given as argv[2].
int main(int argc, char *argv[])
{
int
sd;
struct
sockaddr_in server;
char buf[512];
int rc;
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons(atoi(argv[1]));
sd = socket (AF_INET,SOCK_DGRAM,0);
bind( sd, (SA *) &server, sizeof(server));
for(;;){
rc=recv (sd, buf, sizeof(buf), 0);
buf[rc]= (char) NULL;
printf("Received: %s\n", buf);
}
}
B.
A UDP client Q5Clt has the following code:
main(int argc, char *argv[])
{
int sendsock;
struct sockaddr_in dest;
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]));
sendto(sendsock,argv[3],strlen(argv[3]),0,(SA*)&dest,sizeof(dest));
}
Give an example to show how to use Q5Srv and Q5Clt to receive and send:
I. A unicast message
II. A multicast message
Download