------------------------ Week 7 Notes for NET2003 ------------------------ -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Keep up on your readings (Course Outline: average 5 hours/week homework) The "nc" TCP/IP "Swiss Army Knife" program - a "pure" way to connect your keyboard with a remote TCP/IP daemon - similar to "telnet", except it doesn't try to auto-negotiate first - useful for connecting directly to many text-based Internet protocols: - no easy way to save the output, unless you run a "script" session SMTP: Simple Mail Transfer Protocol see Notes file smtp_session.txt RFC: http://www.faqs.org/rfcs/rfc2821.html POP3: Post Office Protocol Version 3 see course text ALN p.263 (ALN: course text "Advanced Linux Networking" by Roderick W. Smith) RFC: http://www.faqs.org/rfcs/rfc1939.html - try using this on your Algonquin account inmail.algonquincollege.com HTTP: Hyper Text Transfer Protocol see Notes file http_session.txt RFC: http://www.faqs.org/rfcs/rfc2616.html NNTP: Network News Transport Protocol see Notes file nntp_session.txt RFC: http://www.faqs.org/rfcs/rfc977.html *** C Language **** * C and C++ Program development Compiling programs: commands gcc and g++ with -o and -Wall Compile C Language: $ gcc -o prog -Wall prog.c Compile C++ Language: $ g++ -o prog -Wall prog.c++ - option -o sets the name of the output executable file - without -o, output file gets the traditional Unix name "a.out" - option -Wall turns on compiler warnings - can use any of these C++ suffixes: .c++ or .cpp or .C (upper-case C) See sample C and C++ programs under Notes buttons: argv.c.txt - Display the arguments on the command line (C) argv.c++.txt - Display the arguments on the command line (C++) stdxxx.c++.txt - Output on stdout and stderr, prompt and reads from stdin * Building programs: "Makefile" files and the "make" program - "make" is a program that reads a file named "Makefile" (or "makefile") and uses dependency information there to execute commands to rebuild a program - has many built-in defaults for how to build programs e.g. knows how to turn foo.c into foo.o - can specify what part of the build to to via make "targets" in the Makefile - common Makefile targets: make all, make clean - for X11 windowing programs, which require complex sets of libraries and header files, we have a special program that will create a Makefile for you: xmkmf - a Makefile maker (creates a Makefile for use by "make") New commands: gcc g++ make *** Compressed files *** Unix has three major types of compressed files. The suffix names used most commonly on these files are: .Z - compress (an old Unix format - do not use) .gz - gzip .bz2 - bzip2 The .Z format had patent issues that prevented its use in free software. "whereis bash" - see that man pages are kept compressed in bzip2 format Compressed files: $ gzip foo # creates foo.gz $ gunzip foo.gz # creates foo $ bzip2 foo # creates foo.bz2 $ bunzip2 foo.bz2 # creates foo gzip and bzip2 read standard input and write standard output if no files are given: $ cat foo bar | gzip >out.gz $ cat foo bar | bzip2 >out.bz2 The de-compression commands expect the proper suffix on file names. The gzip command can also de-compress the old .Z format files. *** SOFTWARE PACKAGING and INSTALLATION *** Unix multi-file archive files are in "tar" (tape archive) format, originally used to write to magnetic tape. This format is not a compressed format - files are stored without compression. Recent versions of "tar" have a compression option that compresses the whole tar archive file after all the files have been put inside. It does not compress files individually. Tar option letters traditionally appear without a leading dash, e.g. $ tar zcvf archive.tar.gz file1 file2 file3 The tar program has three main operations (pick only one letter): c - create a new archive (empty the old one) t - give a table of contents of the archive x - extract all (or some) of the files from the archive It also uses these useful options: z - use gzip compression or decompression on the tar archive v - show the names of the files, or the long listing of the files f - the next argument is the name of the tar archive to use The tar archiver can be used with or without "z" compression option: $ tar czvf archive.tar.gz input_files... $ tar tzvf archive.tar.gz $ tar xzvf archive.tar.gz $ tar cvf archive.tar input_files... $ tar tvf archive.tar $ tar xvf archive.tar You often must know to use the "z" option to list or extract files in a compressed tar archive: $ tar czf foo.tar.gz /etc/passwd tar: Removing leading `/' from member names $ tar tf foo.tar.gz tar: This does not look like a tar archive tar: Skipping to next header tar: Error exit delayed from previous errors Recent versions of "tar" can recognize compressed archives without using "z". You must *not* use the "z" (compressed) option if the archive is not compressed: $ gunzip foo.tar.gz $ tar tzf foo.tar gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error exit delayed from previous errors These two lines are equivalent (the second line does the compress afterward): $ tar zcf foo.tar.gz infile $ tar cf foo.tar infile && gzip foo.tar .tar - plain tar archive (no compression) .tar.gz - tar archive compressed with gzip .tgz - same as .tar.gz The tar command does not care about the suffix on a file name. You can use any name you want. New commands: tar gzip gunzip bzip2 bunzip2 Fetching a program and building it: $ wget ftp://ftp.x.org/contrib/games/tetris.3.2.1.tar.Z OR wget http://idallen.com/tetris.3.2.1.tar.Z $ file tetris.3.2.1.tar.Z $ tar tzf tetris.3.2.1.tar.Z $ tar xzf tetris.3.2.1.tar.Z $ cd tetris.3.2.1 $ less README $ xmkmf $ make $ man ./tetris.man $ ./tetris - note that it can't save the score file due to no permissions - can you fix it? *** Linux server initialization and start up *** Unix has two major ways to start servers as the system is booting. Originally (Berkeley Unix) servers were started by editing a large "rc.sysinit" file. System V Unix introduced a directory of individual start-up files; most Unix systems use this method. System-V style server start-up scripts (Debian, Mandrake, RedHat): See course text ALN Chapter 4 "Starting Servers" p.79-89 - chkconfig and ntsysv are not present under Knoppix - chkconfig is available on the course linux server Master run level directory: /etc/init.d/ or /etc/rc.d/init.d/ - contain scripts that will start/stop each service, given the appropriate command line argument of "start" or "stop" Run level directories: /etc/rc?.d/ or /etc/rc.d/rc?.d/ - contain symbolic links to scripts in /etc/init.d - numbers in the names determine order of script execution - script names starting with K will be called with "stop" when moving to that run level - script names starting with S will be called with "start" when moving to that run level. Study questions on ALN Chapter 4: [to be written] Starting the web server on Knoppix (*NOT* on the course linux server): 1) become root using "su" (Knoppix has no password by default) 2) as root on Knoppix, run: # /etc/init.d/apache start 3) test it on Knoppix using a browser and the URL: http://localhost/ 4) (optional) test it using "nc" on Knoppix: nc -v localhost http 5) change the start page file: vim /var/www/index.html - add your name to the page title or change the text and reload the page 6) to shut it down: # /etc/init.d/apache stop The /etc/inittab file lists the run levels defined on your system. Not all levels are always used. The keyword "initdefault" is associated with the default run level for your system.