final

advertisement
CS 779/879
Design of Network Protocols
Spring 2003
Final Exam
Time 2 & 1/2 hours
Open Book & Notes
Name:
Login:
1
In this test we will develop a secure tcp tunnel to allow two different groups
(e.g., one at ODU the other at UNC) to chat in the public Internet as shown in
the next Figure:
C
C
C
c
C
C
Secure tunnel
C
S
S
C
C
ODU
UNC
Tcp socket
S Server
Mcast socket
C Client
C
The tunnel is connected with two tcp S programs. S has two sockets, one is a
multicast socket and the other is a tcp socket. Each client C has a multicast
socket. For the pupose of that test assume:
 all sockets (udp and tcp) are binded to port 4444.
 The multicast address to join is 224.1.a.b, where a.b.c.d is the IP
address of the host where the program is running. For example if the
program runs at host 128.82.4.4, then the multicast address is
224.1.128.82
2
S behaves as either client (if it runs first) or server (if it runs second).
To run S, type:
S <the-other-host>
For example to establish the tunnel we may do it as follows:
AT ODU:
% S buzzard.cs.unc.edu
This instance of S at ODU will behave as server.
AT UNC:
% S cash.cs.odu.edu
This instance of S at UNC will behave as client and connects to the other S
running at ODU.
Any message typed by a client is send as plain text to its local peers and the
server at that site encrypts the message and sends it to the other server across
the tunnel. The other server decrypts the message and multicasts it to its local
clients.
3
Q1: [25 points]
Write a function with the following description:
int tsock( char *host)
This function creates a tcp socket t, connects it to “host” at port 4444. If
the connection is not established within 4 seconds, the function waits for a
connection from “host” and port 4444. Any connection comes from
different host or port should be rejected. The function returns t.
4
5
Q2: [20 points]
Write a function with following description:
int msock()
The fuction creates a multicast socket m and joins it to the multicast group
given by “224.1.a.b/4444” where the “a.b.c.d” the IP address where the
program is running. The function returns m.
6
Q3: [15 points]
Write a function with the following description:
char *encdec (char *buf, char *key)
This function use “xor” to encrypt/decrypt buf using key and returns the
result of encryption/decryption.
7
Q4: [15 points]
Write the following function:
void
switch (int m, int t, struct sockaddr_in mgroup)
In the function m represents multicast socket and t is a tcp socket and
mgroup is the multicast group. Any packet received from m is encrypted and
sent to t and any message received from t is decrypted and sent via m to the
multicast group mgroup. Use the encdec function of Q3.
8
Q5: [15 points]
Write the code for the server S using the functions developed in the above
questions. S accepts one argument, the “host” to connect to or to accept
connections from as in:
% S <host>
9
Q6: [10 points]
Write the code for the chat C client using the functions developed above in
the above questions. C accepts no arguments as in:
% C
10
Download