You are on page 1of 2

Birla Institute of Technology & Science, Pilani

Distance Learning Programmes Division


Second Semester 2008-2009
Comprehensive Examination (EC-2 Regular)

Course No. : IS ZC462
Course Title : NETWORK PROGRAMMING
Nature of Exam : Open Book
Weightage : 60%
Duration : 3 Hours
Date of Exam : 04/04/2009 (FN)
Note:
1. Please follow all the Instructions to Candidates given on the cover page of the answer book.
2. All parts of a question should be answered consecutively. Each answer should start from a fresh page.

Q.1 Mention the system calls with syntax used for the following purposes.
(a) mapping current file descriptor a new file descriptor
(b) knowing the foreign address of a TCP socket
(c) for writing data from multiple buffers into socket in one single write() system call
(d) for closing one write end of TCP connection. [4]

Q.2 What are the meanings of the following terms?
(a) INADDR_ANY
(b) AF_INET
(c) SIGCHLD
(d) FIN_WAIT_2 [4]

Q.3 Give a reason why the following block of code is logically and semantically wrong.

If ( fork() == 0 )
{ printf(How are you?);
args = n;
execl(/home/users/sam/mypgm, mypgm, abc, xyz, 0);
printf(Now Im back);
} [2]

Q.4 Explain briefly first what this program fragment does, and then explain in detail the
meaning of each numbered line.

char *
sock_ntop(const struct sockaddr *sa, socklen_t salen)
{
char portstr[8];
static char str[128];

10 switch (sa->sa_family) {
11 case AF_INET: {
12 struct sockaddr_in *sin = (struct sockaddr_in *) sa;
13 if (inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL)
14 return(NULL);
15 if (ntohs(sin->sin_port) != 0) {
16 snprintf(portstr, sizeof(portstr), ":%d", ntohs(sin->sin_port));
17 strcat(str, portstr);
}
19 return(str);
} [5]
No. of Pages = 2
No. of Questions = 11
IS ZC462 (EC-2 Regular) Second Semester 2008-2009 Page 2

Q.5 Develop a multicast terminal chat program that takes as optional arguments a multicast
host address and optionally a port number. The program should print the host address and
port that it is using. After bind and setsockopt() the program should send a message like:
SIGNING IN using getuid and gethostname(). The program should create a child
process to continuously read from the socket and write to the terminal, prefacing each
received line with the name, hostname of the sender. The parent process should
continuously read a line from stdin and send it out on the socket until the user types Ctrl-
d. Then the parent process should send a sign-off message as SIGNING OUT and kill
the child and exit. [10]

Q.6 Consider a situation where you need to access files on a remote machine. The files are
stored on the secondary storage in the remote machine. A server process running on the
remote machine serves files to clients requesting the files. Clients and server communicate
using messages of the format: message length (4 bytes in NBO), message code (4 bytes in
NBO), and optional parameter (as large as required). Client takes the host name and port
of the server on command line. Displays the following menu for the user. 1. get file 2. list
files 3.exit. Client accepts the option and performs the task. It does this in a loop until user
gives opton for exiting. Client maintains a persisten TCP connection to the server all-
throughout. Client can only send two message codes to server; 101 for getting a file given
its path and 102 for listing files given the path. The first field in the message conatins the
total length of the message so that the process can wait for the whole message to reach.
The file path is sent in the place of optional parameter. Server returns codes 201(File not
found) or 301 (file found with file data in optional parameter). Implemenet client that
communicates with server. [10]

Q.7 Write a client server program using Unix Domain Protocol Family such that they perform
the following task: The client will pass the server a string consisting of a sequence of
characters taken from stdin. If the server sends a "Sorry" response to the client, it will
immediately exit else it will display the received result. The server will respond with
"Sorry, cannot compute, if the received string contains anything but not numbers. If the
string contains all numbers, the individual digits will be added together and returned as a
string. If the server receives a string of numbers, it will a) add the digits together b) send
the value back to the client, and c) will not exit unless the response is a single digit. This
process will be repeated until there is only one digit remaining and send it to client. Your
client program should also pass its credential and server will display the received senders
credentials. [10]

Q.8 What value will a big-endian client get in return if it sends the two short integer values 2
and 10, to a little-endian server and have them added there? Show your calculations. [4]

Q.9 Write client-server interactions on a TCP connection such that a SIGPIPE signal is
generated. [5]

Q.10 In TCP client-server interactions, how can a client know the termination of a server
process? [3]

Q.11 Explain how to set a timeout for 1 second and 20 nano seconds. [3]



**********

You might also like