----------------------- Lab #01 for CST8165 due September 10, 2007 (Week 2) ----------------------- -Ian! D. Allen - idallen@idallen.ca - www.idallen.com Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Global weight: 1% of your total mark this term. Due date: before 23h59 Monday September 10 The deliverables for this exercise are to be submitted online in the Linux Lab T127 using the "cstsubmit" method described in the exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty exercises that are submitted late but before 13h00 on Tuesday, September 11. After that late-submission date, the exercise is worth zero marks. Exercises submitted by the *due date* will be marked online and your marks will be sent to you by email after the late-submission date. Exercise Synopsis: Copy (with proper credit to the original author and source) a TCP server from the given sources. Modify them. Test them. Where to work: Submissions must compile and run cleanly in the T127 Linux Lab, though you are free to work on them anywhere you like. Recall that most any program or C function has a manual page: RTFM Coding client/server -------------------- 1) Find the Sockets Tutorial: http://www.cs.rpi.edu/courses/sysprog/sockets/sock.html (alternate: http://www.linuxhowtos.org/C_C++/socket.htm ) 2) Copy the code for the second C server "server2.c" from the section "Enhancements to the server code". Credit your code sources in comments in the code after you have copied it. (No plagiarism!) See "man wget" for an easy way to download any URL to your current directory. 3) Create a Makefile target "all" for this code that compiles server2.c into "server2" using gcc and these gcc required options: CFLAGS = -g -O -Wall -Wextra -Wshadow -Wstrict-prototypes \ -Wmissing-prototypes -Wmissing-declarations \ -Wdeclaration-after-statement -Wmissing-field-initializers \ -Wredundant-decls -Wunreachable-code -fstack-protector-all Strive for the minimal Makefile - don't include things that "make" will do for you automatically (such as build .o files from .c files). 4) Create a Makefile target "clean" that removes the compiled files, leaving only the source file. 5) Fix the compile warnings by adding the missing header files - use the man pages to find the missing header lines for each function - fix the warning about signed/unsigned use of int - make the error function static instead of global - you may still have one spurious "will never be executed" error on the line containing htons() that you can ignore 6) Add this line to main(): alarm(30*60); /* kill program after 30 minutes */ - this is in case you forget to kill the program yourself when you leave! - to see your background processes on Linux/Unix, use command: ps gx - note where is the correct place to put this line. 7) Add code to check the return code of "listen()" and handle any error. (Print a message on stderr if it fails and exit the program with a non-zero return code. Since listen() is a system call, you may use perror() to print the reason for the system call failure.) 8) Fix "The zombie problem" using the AIX-style fix from the Tutorial. (Use the AIX one-line fix, not the fix that uses a signal handler.) 9) Pick up the setsockopt SO_REUSEADDR code fragment from section 4.2 of http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html and add it to your server. This will make the server re-use socket ports nicely and avoid "Address already in use". - note what variables do you need to create to make this code work. - note where is the correct place to put this code. 10) Verify that your program works using the standard TCP client netcat: $ nc -v localhost e.g. you would start your server in the background and then connect: $ ./server2 55555 & $ nc -v localhost 55555 hi [...some server output prints here and netcat exits...] $ killall server2 The Tests --------- 11) Start a "script" session (man script) using my script cover and with output file "testing.txt": $ ~alleni/bin/script testing.txt This will save your terminal command lines and output into the given file name. Make sure you use my cover script, as shown above. Note: Your output file "testing.txt" will not contain the full results of your script session until you exit the subshell started by the script command. When you exit the subshell, script will tell you the name of the output file. See the next few steps: 12) Inside the script session, demonstrate that "make clean" followed by "make all" works. 13) Start your server in the background, as shown above. Use netcat ("man nc") to connect to your server and demonstrate that input from the keyboard goes to your server and returns. (See above.) Netcat will exit after one line is read. (The server only accepts one line per connection.) 14) After testing, kill your background server. (See above.) 15) Exit the script session subshell. Script will tell you the name of your script output file: $ exit Script done, file is testing.txt $ less testing.txt You may now examine your saved script session. 16) Submit the files using the exact file names given below. No added programming comments are needed in these source files (yet). Submission ---------- Submission Standards: A. At the top of each and every submitted file, as comments, create an Exterior Assignment Submission label following the example you will find under the "Assignment Standards" button on my teaching home page teaching.idallen.com . (The Teaching home page is not the same as the Course home page.) For full marks, follow the directions for the label exactly. The label has exactly 7 lines, plus an optional Comments line. The spelling of the label fields on the seven lines must be exactly as shown (machine readable). The spelling must be exact. Exact! B. For material you copy from other sources, credit the author and source. Failure to acknowledge the source of copied material and claiming you wrote it yourself will constitute academic fraud (plagiarism). C. Using the cstsubmit command: Reference Class Notes file: cstsubmit.txt Submit these files for marking as Exercise 01 using the following *single* cstsubmit command line: $ ~alleni/bin/cstsubmit 01 server2.c testing.txt Makefile All file names must be spelled *exactly* as given above. Incorrect submissions are worth zero marks. This "cstsubmit" program will copy the selected files to me for marking. Always submit *all* your files at the same time. Do not delete your copies; keep them. Verify that you submitted all your files, using this command line: $ ~alleni/bin/cstsubmit 01 -list Note that the digit '1' and the letter 'l' (lower-case 'L') are different. The digit '0' and the letter 'O' are also different. Do not confuse these characters on your screen. You may redo this exercise and re-submit your results as many times as you like; but, you must always submit *all* your exercise files every time. The "-delete" option of cstsubmit will delete the most recent submission you have made. I will mark only the most recent submission that is submitted before the final hand-in cutoff date. For Exercise 01, always use "01" as the first argument to "cstsubmit". Always submit *all* the files each time you submit an exercise. P.S. Did you spell all the assignment label fields and file names correctly?