Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Midterm Exam with 8 Questions - Network Programming | CP SC 360, Exams of Computer Science

Material Type: Exam; Class: NETWORK PROGRAMMING; Subject: COMPUTER SCIENCE; University: Clemson University; Term: Fall 2008;

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-763
koofers-user-763 🇺🇸

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CpSc 360, Section 1, Fall 2008, Midterm Exam
9:30PM ~ 10:45PM, Tuesday, September 30th
Close book, Close notes.
State all assumptions in your answers.
Ask question if you need clarification.
Clearly write your answers in white paper using pen or pencil.
Name:_________________________
Page 1 of 8
pf3
pf4
pf5
pf8

Partial preview of the text

Download Midterm Exam with 8 Questions - Network Programming | CP SC 360 and more Exams Computer Science in PDF only on Docsity!

CpSc 360, Section 1, Fall 2008, Midterm Exam

9:30PM ~ 10:45PM, Tuesday, September 30th

 Close book, Close notes.

 State all assumptions in your answers.

 Ask question if you need clarification.

 Clearly write your answers in white paper using pen or pencil.

Name:_________________________

Question #1 (30 points): Determine whether the following statements are true or false.

1. Peer processes use peer-to-peer protocols to communicate directly in a layered

communication model. ( F )

2. In client/server programming paradigm, server is a machine that waits for service

requests. ( F ).

3. Network byte order might be different in different computers. ( F )

4. Headers are needed in every layer of the network communication. ( F )

5. Every Ethernet interface has a unique 48 bit address. ( T )

6. TCP initial sequence number starts at 1. ( F )

7. socket() allocates resources needed for a communication endpoint and also deal with

endpoint addressing.. ( F )

8. bind() will fill the local and remote IP addresses of the file descriptor associated with the

specific socket. ( F ).

9. TCP client uses connect() to send its IP address and port to the server. ( T )

10. TCP server uses accept() fill the remote IP address and port fields of the file descriptor

structure opened by socket(). ( F )

11. Calling bind() is not necessary in a UDP client program. ( T )

12. Unlike a TCP program in which read() and write() are used to get data from the

communication channel, a UDP program must use sendto() and recvfrom().( F )

13. With nonblocking I/O, a process will chew up all available processor time. ( T )

14. Calling function select() will return when and only when one of the specified descriptors is ready

for I/O. ( F)

15. The function getaddrinfo() is protocol independent. (T)

Question #4 (10 points): List five I/O models and describe their difference in the two phases of

input operation.

Question #5 (10 points): Draw a diagram to demonstrate TCP 3-way handshake and the normal

close of a TCP connection.

Question #7 (10 points) Describe how to write a TCP client program and a TCP server program

respectively. You need only to tell what network related functions should be called and what

statement should be taken at the proper order.

int socket(int family,int type,int proto); int bind( mysock, (struct sockaddr) &myaddr, sizeof(myaddr) ); int listen( int sockfd, int backlog); int accept( int sockfd, struct sockaddr cliaddr, socklen_t *addrlen); int connect( int sockfd,const struct sockaddr *server, socklen_t addrlen); **int read( int fd, char buf, int max); int write( int fd, char buf, int num);

Question #8 (10 points): Read the following TCP server program. Point out the only one

problem in this program and explain why it is a problem. You also need to correct it.

#include <stdio.h> /* standard C i/o facilities / #include <unistd.h> / Unix System Calls / #include <sys/types.h> / system data type definitions / #include <sys/socket.h> / socket specific definitions / #include <netinet/in.h> / INET constants and stuff / #include <arpa/inet.h> / IP address conversion stuff */ int main() { int ld, sd, addrlen,length, n; struct sockaddr_in skaddr, from; char buff[100]; if ((ld = socket( PF_INET, SOCK_STREAM, 0 )) < 0) { perror("Problem creating socket\n"); exit(1); } skaddr.sin_family = AF_INET; skaddr.sin_addr.s_addr = htonl(INADDR_ANY); skaddr.sin_port = htons(0); if (bind(ld, (struct sockaddr *) &skaddr, sizeof(skaddr))<0) { exit(0); } length = sizeof( skaddr ); if (getsockname(ld, (struct sockaddr *) &skaddr, &length)<0) { exit(1); } if (listen(ld,5) < 0 ) { exit(1); } while (1) {

addrlen=sizeof(from); /* Missing statement */

if ( (sd = accept( ld, (struct sockaddr*) &from, &addrlen)) < 0) { exit(1); } length = sizeof( skaddr ); if (getsockname(sd, (struct sockaddr *) &skaddr, &length)<0) { exit(1); } while ((n=read(sd,buff,100))>0) { write(1,buff,n); } close(sd); } }