------------------------- Week 02 Notes for CST8165 ------------------------- -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) The structure of your code matters! ---------------------------------- - see the opt_iocc files in the course notes: http://teaching.idallen.com/cst8165/07f/notes/indexcgi.cgi http://www.ioccc.org/years-spoiler.html What is the Internet? --------------------- http://en.wikipedia.org/wiki/Internet "The Internet is a worldwide, publicly accessible series of interconnected computer networks that transmit data by packet switching using the standard Internet Protocol (IP). It is a "network of networks" that consists of millions of smaller domestic, academic, business, and government networks, which together carry various information and services, such as electronic mail, online chat, file transfer, and the interlinked Web pages and other documents of the World Wide Web." - the Internet is not just the WWW (HTTP) - HTTP is just one of many, many Internet protocols! - but Algonquin College blocks most non-HTTP Internet traffic - in particular, the SMTP port (25) is blocked to external sites - blocks are "drop packet", not "refuse packet" types; they time out Is the Internet smart about content? ----------------------------------- - The Internet is dumb. It wasn't designed to give priority to different types of packet traffic. The intelligence is "at the edges" of the net. - some say you could implement the Internet using two cans and a string; or, even using carrier pigeons: - pigeons: http://tools.ietf.org/html/1149 (1 April 1990) - pigeons: http://www.blug.linux.no/rfc1149/ Role of Unix (now Linux or BSD) and the Internet: ------------------------------------------------ - WWW slashes are "forward" slashes because the WWW grew up on open-source Unix machines. (DOS/Windows came much later, and was closed-source.) - text-based Internet protocols pre-date XML - Unix was full of tools to deal with text and text files - an "ethereal" or "netcat" text dump of most Internet protocols is often very readable - Be aware of the history and importance of Open Source in the development of the Internet and its protocols (e.g. RFC). The Internet could not have evolved under a closed-source, pay-per-view business model. (Don't let it head that way!) - Internet development was Open Source: - "FLOSS": Free/Libre Open Source Software (or "FOSS" in the USA) - open-source discussions occur with source code samples The Internet - who owns it? who controls it? ------------ - Internet not developed as a pay-per-view or proprietary system - standards-based vs. product-based - based on defined protocols, not on vendor products or implementations - nobody pays license fees to use TCP/IP, SMTP, HTTP, etc. - Tim Berners-Lee doesn't get royalties for your web site - why do companies still write web pages that only work in one browser? - e.g. Algonquin Blackboard - http://www.anybrowser.org/campaign/ - the mistake of designing for a vendor's product, not for an international standard protocol - IP and port address space is coordinated by ICANN/IANA - Internet Corporation for Assigned Names and Numbers: icann.org - Internet Assigned Numbers Authority http://www.iana.org/ - Internet Engineering Task Force (IETF): "Rough consensus and running code." - Internet Engineering Task Force http://www.ietf.org/ "When I was studying Physics the quickest way to end an argument was to show the explanation in mathematics (albeit a lot of handwaving mathematics!). Most software developers on the otherhand do not grok math, however they surely do grok code. Therefore if you could explain your arguments through code then you would have improved your odds of getting your message through." http://www.manageability.org/blog/stuff/rest-explained-in-code/view "Be liberal in what you accept, and conservative in what you send" (Jon Postel, TCP/IP developer) * BUT: "If we were all conservative in what we do, then we wouldn't do much that is new, or different. This would seem to retard progress. Of course, the same would be true in protocols so perhaps we need a "where possible" qualifier." http://www.aaronsw.com/weblog/000776 - Internet standards: evolved from the ARPAnet Request for Comment - RFC http://tools.ietf.org/html/ IP: http://tools.ietf.org/html/791 (45 pages) SMTP: http://tools.ietf.org/html/2821 (79 pages) * Who controls handing out the IP numbers and port numbers? - the Internet Corporation for Assigned Names and Numbers (ICANN) through its operating unit the Internet Assigned Numbers Authority (IANA) "Dedicated to preserving the central coordinating functions of the global Internet for the public good." ICANN: http://www.icann.org/ IANA: http://www.iana.org/ - IANA delegates to a few Regional Internet Registries (RIRs) to distribute the large blocks of IP addresses http://www.iana.org/ipaddress/ip-addresses.htm http://www.iana.org/assignments/ipv4-address-space - e.g. ARIN IP address list http://www.arin.net/ - special addresses (historical and current) http://tools.ietf.org/html/3330 - note: hosts on this net: 0.0.0.0/8 - note: RFC1918 private address space: 10.0.0.0 - 10.255.255.255 (10/8 prefix) 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) "the Internet does not inherently protect against abuse of these addresses; if you expect (for instance) that all packets from the 10.0.0.0/8 block originate within your subnet, all border routers should filter such packets that originate from elsewhere. Attacks have been mounted that depend on the unexpected use of some of these addresses." - IANA TCP/UDP port list: http://www.iana.org/assignments/port-numbers - Well Known Ports are those from 0 through 1023 - Registered Ports are those from 1024 through 49151 - Dynamic and/or Private Ports are those from 49152 through 65535 - a shorter Unix/Linux specific copy of this file is kept in /etc/services - to register a new port, see [RFC4340], Section 19.9 http://tools.ietf.org/html/rfc4340#section-19.9 Net Neutrality - not for long? -------------- - Like the downtown streets at rush hour, the Internet doesn't (yet) pass traffic based on how much money you have. You can't get higher priority by paying more; though, this may change (on the Internet) in the next year or two if the backbone carries have their way. - http://www.digital-copyright.ca/taxonomy/term/396 * AT&T blocks Pearl Jam's Bush slam : Pearl Jam calls for Net Neutrality A Salon article discusses how AT&T unilaterally censored political speech at a Pearl Jam concert: The band says the company's actions highlight the need for action on "network neutrality" -- the fight for regulations prohibiting broadband firms from making decisions about what content is and is not allowed on their networks. AT&T is currently fighting network neutrality, helping the NSA spy on Americans, and developing a way for Hollywood to police the Internet. * Rogers Must Come Clean on Traffic Shaping: Michael Geist's weekly Law Bytes column (Toronto Star version, Homepage version) focuses on Rogers, a leading Canadian ISP, actively engaging in “traffic shaping”, a process that limits the amount of bandwidth available for certain applications. Although this was initially limited to peer-to-peer file sharing applications, there is mounting speculation that the practice may be affecting basic functionality such as email and the use of virtual private networks. ============================================================================ Q: Who is the ultimate authority on all IP addresses and ports? Give the full name. Q: Which organization is delegated to manage IP addresses in North America? Give the full name. Q: Give any two of the three RFC1918 private address space blocks and masks Q: Is 172.15.0.0 a RFC1918 private address? Q: Is 172.17.0.0 a RFC1918 private address? Q: What is the last (highest) private address in the RFC1918 10.0.0.0 block? Q: What is the last (highest) private address in the RFC1918 172.16.0.0 block? Q: What is the last (highest) private address in the RFC1918 192.168.0.0 block? Q: T/F Special address block 0.0.0.0 is reserved for hosts on your local network. [RFC3330] Q: T/F IP address 0.0.0.0 is not a valid address. Q: Name and give the port ranges of the three RFC4340 divisions of ports ( http://tools.ietf.org/html/rfc4340#section-19.9 ) Q: What Unix/Linux file is used to turn port name "smtp" into "25" when you do $ nc -v localhost smtp Client/Server programming ------------------------ Background: Know the low-level Unix system calls: - man 2 open (returns a small integer file descriptor) - unit 0 is already open in your program as standard input - unit 1 is already open in your program as standard output - unit 2 is already open in your program as standard error - unit 3 is usually the next integer returned by open() in your program - man 2 read - man 2 write - man 2 close The low level Unix system calls "open()", "read()", "write()", and "close()": - have no buffering (are not like stdio fopen/fgets/fread/fwrite/fclose) - return -1 on error and set errno (which can be used by perror()) - errno is only set after a system call *fails*, not when it succeeds You may (should) use perror() to print errno after a system call fails - man 3 perror - errno is only set after a system call *fails*, not when it succeeds - you must only call perror() if the system call *fails* A successful system call does *NOT* clear or set errno to zero! - you cannot test errno to know if a system call failed - errno is only set after a system call *fails*, not when it succeeds read() returns zero (zero bytes read) on end-of-file (EOF) - you must not use the descriptor after EOF - the contents of the read() buffer are undefined after EOF; don't use it - EOF is not an error - errno is not set - never call perror() after EOF ============================================================================== Q: T/F the output of perror() appears on standard error, not standard output Q: T/F after a successful system call, perror() prints nothing Q: T/F when most Unix syscalls fail, the return value is zero Q: T/F when most Unix syscalls fail, the external global errno is set to -1 Q: T/F on error, the open() syscall returns zero Q: T/F on error, the read() syscall returns zero Q: T/F on error, the write() syscall returns zero Q: T/F on EOF, perror() prints "end of file" Q: T/F after a successful fork() system call, the parent process receives a non-zero child pid Q: T/F after a successful fork() system call, the child process receives a non-zero parent pid