======================= Midterm Test #1 Answers ======================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Test #1 Written Answer Section - Points: 50 (12 of 20%) Read both sides! Closed book. No aids. No electronic devices. 1. [Points: 1] Give the dotted-quad network mask for this subnet: 10.2.100.0/26 255.255.255.192 2. [Points: 2] What is the next sub-net address numerically greater than: 6.7.8.0/25? 6.7.8.128/25 3. [Points: 2] What is the next sub-net address numerically greater than: 2.3.4.0/24? 2.3.5.0/24 4. [Points: 1] Which Unix file name is used to map port name "smtp" into port number 25? /etc/services 5. [Points: 6] TCP/UDP port numbers are divided into named ranges by ICANN/IANA. Give the IANA name for each range and give the port start and end values of the range. see http://www.iana.org/assignments/port-numbers 6. [Points: 1] Correct this non-portable line of code: saddr.sin_port=portno; =htons(portno) 7. [Points: 1] Correct this non-portable line of code: serv_addr.sin_addr.s_addr=INADDR_ANY; =htonl(INADDR_ANY) 8. [Points: 4] Give any two of the three RFC1918 private address space blocks and masks. 10/8 255.0.0.0 172.16/12 255.240.0.0 192.168/16 255.255.0.0 9. [Points: 3] List in execution order the two major Unix/Linux network system call function names used in a TCP client (e.g. your client.c): socket,connect 10. [Points: 5] List in execution order the four major Unix/Linux network system call function names used in a TCP server (e.g. your server2.c): socket,bind,listen,accept 11. [Points: 1] Give a C library function call that will send a signal to terminate the program after 30 minutes (e.g. as used in server2.c): alarm(30*60) 12. [Points: 1] In a memory dump that shows bytes numbered in ascending order from left-to-right on the page, which Endian order shows multi-byte quantities as written "backwards" ? Little 13. [Points: 2] Give the dotted-quad form for the IP address represented by the bit pattern -1. 255.255.255.255 14. [Points: 1] What Unix command shows the MAC, IP address, and network mask of each network interface? ifconfig 15. [Points: 13] Write the detailed PDL for any process loop (just the loop!) that wishes to read data from one file descriptor and write it to another descriptor. WHILE 1 numread = READ some data from input unit into fixed buffer IF numread < 0 THEN print error message and break loop /* (1) */ IF numread == 0 THEN print EOF message and break loop /* (2) */ ASSERT( numread > 0 ) /* man 3 assert */ numwrite = WRITE numread bytes from buffer to output unit IF numwrite < 0 THEN print error message and break loop /* (3) */ END WHILE 16. [Points: 6] Explain in detail which conditions will terminate (break) the above loop. break on read error (nr < 0) from input descriptor break on EOF (nr == 0) from input descriptor break on write error (nw < 0) to output descriptor