<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
CS 779/879
Design of Network Protocols
Spring 2012
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 IPv6 address of a given
host?
B. Assume you tried to execute the following
command:
Something % sock
–s 10123
And you got the
following error:
can't bind local
address: Address already in use
How to find out
the name and the owner of the program that is using port 10123?
C.
Assume a TCP server (Q1Srv) 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();
}
Describe what might happen to the following commands in the specified order:
Something % Q1Srv
Somethingelse % sock something 12345
Somethingmore % sock something 12345
Question
2:
To allow two groups to exchange multicast
messages we may use a udp
tunnel between the two groups as shown below:

The program mTunnel has the following syntax:
mTunnel <LocalPort#> <RemoteIP> <RemotePort#> <GroupIP> <GroupPort#>
Example:
We may run the mTunnel at somethingelse & somethingmore as follows:
somethingelse % mTunnel 10111 somethingmore 10222 224.0.0.3 10333
somethingmore % mTunnel
10222 somethingelse
10111 224.0.0.4 10444
Then we run the mchat on antares & capella as follows:
antares % mcastChat 224.0.0.3 10333
capella % mcastChat 224.0.0.4 10444
In such case you will see the messages are exchanged between antaress and capella via the two mTunnel programs
running at somethingelse and somethingmore.
You are required to implement the two functions: handleUnicast() and handleGroup()
#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(LocalPort,
argv[1]);
strcpy(RemoteIP,
argv[2]);
strcpy(RemotePort,
argv[3]);
strcpy(GroupIP,
argv[4]);
strcpy(GroupPort,
argv[5]);
RemoteAddress.sin_family
= AF_INET;
hp
= gethostbyname(RemoteIP);
bcopy(hp->h_addr, &(RemoteAddress.sin_addr.s_addr),
hp->h_length);
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;
hp
= gethostbyname(GroupIP);
bcopy(hp->h_addr, &(GroupAddress.sin_addr.s_addr),
hp->h_length);
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);
if
(fork() == 0)
handleUnicast();
else
handleGroup();
}
void handleUnicast()
{
}
void handleGroup()
{
}
Question
3:
Consider the following executions of Server and Clients:
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);
server.sin_family = AF_INET;
server.sin_port
= 1234;
if (argc
== 1) server.sin_addr.s_addr = htonl(INADDR_ANY);
else if (argc
== 2) {
hp = gethostbyname(argv[1]);
bcopy(hp->h_addr,&(server.sin_addr.s_addr),hp->h_length);
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 on host something (128.82.4.210) as follows:
S1: Q3Srv
S2: Q3Srv 127.0.0.1
S3: Q3Srv 128.82.4.210
S4: Q3Srv 224.0.0.1
And assume we
run the client on the same host something follows:
C1: sock -u
127.0.0.1 1234
C2: sock -u
128.82.4.210 1234
C3: sock –u 224.0.0.1
1234
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.
Fill the
following table with Y or N if the client runs on host somethingels while the server runs on something.
|
|
S1 |
S2 |
S3 |
S4 |
|
C1 |
|
|
|
|
|
C2 |
|
|
|
|
|
C3 |
|
|
|
|
Question
4:
Consider
the following two programs:
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
= 1234;
server.sin_addr.s_addr
= htonl(INADDR_ANY);
sd =
socket(AF_INET, SOCK_DGRAM, 0);
reusePort(sd);
bind(sd,
(SA *) & server, sizeof(server));
while (1) {
len
= sizeof(from);
rc
= recvfrom(sd,buf,sizeof(buf),0,(SA *)&from,&len);
buf[rc] = NULL;
printf("Received:
%s\n", buf);
sendto(sd, buf, rc,
0, (SA *) & from, sizeof(from));
}
}
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
= 1234;
dest.sin_addr.s_addr
= inet_addr(argv[1]);
server.sin_family
= AF_INET;
server.sin_port
= 1234;
server.sin_addr.s_addr
= htonl(INADDR_ANY);
sendsock =
socket(PF_INET, SOCK_DGRAM, 0);
reusePort(sendsock);
bind(sendsock,
(SA *) & server, sizeof(server));
sendto(sendsock, “HI”, 2, 0, (SA *) & dest,
sizeof(dest));
rc = recv(sendsock, buf, sizeof(buf),
0);
buf[rc] = NULL;
printf("Received
Back: %s\n", buf);
}
Explain the
behavior/outcome of the following scenarios if we
executs both the server and the client
at the same host something (128.82.4.210):
1.
Run the server
then the client as follows:
something % Q4Srv
something % Q4Clt 128.82.4.210
2.
Run the client
then the server and follows:
something % Q4Clt 128.82.4.210
something % Q4Srv