======================= Midterm Test #2 Answers ======================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Test #2 - Points: 68 (20 of 20%) 2. [Points: 2] Describe briefly two functions of ICMP on the Internet. Announce network errors, Announce network congestion, Assist Troubleshooting, Announce Timeouts, etc. 2. [Points: 1] What interior/internal routing protocol is replacing the old RIP protocol? OSPF 3. [Points: 1] The single 32-bit TCP header Acknowledgement number is not large enough to allow selective acknowledgement of packets, e.g. I got packets 1, 2, and 4 (but not 3): TRUE 4. [Points: 1] The IP packet header contains IP addresses and port numbers: FALSE 5. [Points: 1] When reading the ABNF rules given in RFC documents, quoted strings (e.g. "abc") are not case-sensitive: TRUE 6. [Points: 1] Why aren't the source and destination IP addresses given in the TCP/UDP header? They are in the IP header. 7. [Points: 1] When two systems attempt simultaneous TCP connections with each other, they end up with two distinct TCP streams: FALSE 8. [Points: 2] What changes were made to the ICMP "Datagram Too Big" message to accommodate PMTU (Path Maximum Transmission Unit) discovery? "a currently unused header field in the Datagram Too Big message be used to report the MTU of the constricting hop" 9. [Points: 2] What was the purpose of the "Requirements for Internet Hosts" documents RFC-1123 and 1124? give clarifications and examples of how the RFCs work; no new info 10. [Points: 3] Show, in order, the TCP flags used in the basic TCP three-way handshake. Clearly indicate which is server and which is client. C=SYN, S=SYN,ACK, C=ACK 11. [Points: 2] Describe briefly two reasons why IP packet fragmentation should be avoided. inefficient use of resources, degraded performance (in reassembly, fragment loss), lack of efficient reassembly 12. [Points: 2] What is the content and purpose of the TCP and UDP "pseudo-header"? (Why is it necessary?) "contains the source address, the destination address, the protocol, and the UDP length. This information gives protection against misrouted datagrams." 13. [Points: 1] SMTP protocol command words are case-sensitive: FALSE 14. [Points: 2] Why was EHLO added to SMTP, if SMTP already had HELO? Needed a way to indicate a new version of SMTP, one that could supply extensions. 15. [Points: 2] How are SMTP responses continued onto multiple lines? The status code of every line is followed by a dash; the last code is followed by a blank. 16. [Points: 2] How does SMTP escape message text so all lines can be sent safely after a DATA command? All lines starting with a dot have a second dot prepended when sending and removed when receiving. 17. [Points: 1] A standard SMTP client MUST wait for each server response before sending the next SMTP command; pipelining is not allowed by default: TRUE 18. [Points: 1] The include file contains approximately the same number of temporary and permanent program exit codes: FALSE 19. [Points: 30] In your exam booklet, write detailed PDL for the simplest non-forking single-process "echo"-style server that uses select() instead of fork(). (This PDL has exactly the same functionality as the original small program you first downloaded as selectserver.c at the start of Lab 5.) This simple server accepts client connections, reads data, and writes the data to all connected clients except the client from which the data was received. No enhancements to the basic selectserver.c functionality are needed. No IP address prefixing is needed. No private messages need to be handled. Your detailed PDL must use these variable names and items: listener=socket(...) (the name of the socket on which to receive new client connections), fdmax (the highest numbered socket descriptor seen so far), master (the master list of all socket descriptors), read_fds (the current list of socket descriptors with I/O pending, set on return from select()), select(fdmax+1,&read_fds,...) (the select() system call), clifd=accept(listener,...) (the name of the socket descriptor when accepting a new client connection). You will need these functions: FD_ZERO(&list) (a function to zero a descriptor list), FD_ISSET(fd,&list) (a function to check if a descriptor is in a list), FD_SET(fd,&list) (a function to put a descriptor in a list). Show how your simple server sets up and executes the select() call and then loops over all the known socket descriptors, looking for descriptors that have data waiting. Show how the data waiting from the original listener socket descriptor is treated differently from data waiting from all the other (client) socket descriptors. Show how a new connection from a client affects the master list of socket descriptors. Show what happens on EOF or error reading data from a client. Show the details of the loop that sends data from one client to all the other known clients but not back to the client itself. START selectserver FD_ZERO(&master) listener = socket(...) - check for error and print msg with perror() and exit non-zero bind(listener, ...port info...) - check for error and print msg with perror() and exit non-zero listen(listener, ...num connections...) - check for error and print msg with perror() and exit non-zero FD_SET(listener, &master) fdmax = listener // maximum descriptor used in master set LOOP read_fds = master // copy master fd set to temporary set CALL select(fdmax+1,&read_fds,...) on any connected fd from 0 to fdmax - check for error and print msg with perror() and exit non-zero FOR i=0 to fdmax IF FD_ISSET(i,&read_fds) IF i == listener clifd = accept(listener,...) IF error print error message ELSE FD_SET(clifd, &master) IF clifd > fdmax ) fdmax = clifd ENDIF ELSE nbytes = read from socket i into buf, sizeof(buf) IF error or EOF IF EOF print "hung up" message ELSE print error message ENDIF close socket i remove i from master list [e.g. FD_CLR(i, &master)] ELSE FOR j=0 to fdmax IF FD_ISSET(j, &master) AND j != listener AND j != i THEN send nbytes of data from buf to j - check for error and print msg with perror() and exit non-zero ENDIF ENDFOR ENDIF ENDIF ENDIF ENDFOR ENDLOOP END selectserver 20. [Points: 10] On a fresh page in your exam booklet, write the C code that implements just the loop from the preceding PDL that sends nbytes of data located in buffer buf to all connected clients except the client that originated the data. Use the same variable names listener, master, and fdmax that you used in the above PDL. Assume that the socket descriptor of the client that originated the data is stored in variable i, just at is was in the original selectserver.c program from Lab 5 and Lab 6. No enhancements to the basic selectserver.c functionality are needed. No IP address prefixing is needed. (The original loop code from selectserver.c was five lines long, plus two comments and four closing braces.) Error checking is required on the sending of the data. for(j = 0; j <= fdmax; j++) { if (FD_ISSET(j, &master)) { if (j != listener && j != i) { if (send(j, buf, nbytes, 0) == -1) { perror("send"); } } } } Test #2 20% CST8165 80 minutes