------------------------- Week 03 Notes for CST8165 ------------------------- -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) Unix Tools ---------- Network tools (RTFM): - ifconfig, "ifconfig eth0" - show MAC, IP address, and network mask of each network interface - ip route (or netstat -r -n) - show IP routing tables, including route to default gateway - arp, "arp -a" - show known (cached) MAC addresses on local net - traceroute - using increasing small TTLs, find the route of an outgoing packet - may be blocked at Algonquin College - tcpdump (privileged under Linux - needs root permissions) - show the raw network activity on a network card - ethereal (privileged under Linux - needs root permissions) - show the raw network activity on a network card (GUI) OSI Seven Layers / TCP Four Layers ---------------------------------- Review the OSI network stack and Internet network stack: http://en.wikipedia.org/wiki/Internet_protocol_suite - encapsulation as data moves down the stack, de-encapsulation moving up - OSI has seven layers (name them) - Internet TCP/IP has four (name them) - give examples of programs/protocols/methods at each layer see Figure 1 in http://www.rfc-editor.org/rfc/rfc791.txt - with respect to the Internet protocol stack, what is the difference between an IP router and an Ethernet switch or hub? Q: Show how data from an application (e.g. TFTP) is encapsulated/de-encapsulated as it moves down the four-layer TCP/IP stack, gets shipped over an Ethernet, passes through a switch, passes through an IP router, and is finally delivered to another application. Getting a machine on the net ---------------------------- Your machine needs: - IP address - network mask or prefix length - IP address of gateway machine (if you want to talk off-network) - IP addresses of DNS servers (not essential but very useful) Network broadcast address can be calculated from IP and mask. You can program your machine with these things directly (static addressing); or, you can have your machine broadcast a request to see if some other machine on the network has its configuration info: DHCP, RARP Q: What Internet network access is possible without a DNS server? Q: What Internet network access is possible without a gateway machine? Q: What Internet network access is possible without a network mask? Client/Server Programming ------------------------- Diagram: http://community.borland.com/article/0,1410,26022,00.html Q: In one column list in flow-chart form the system calls made to set up a TCP/IP server that loops accepting clients, forking children that each read one packet, write one packet, and exit. In a parallel column list the system calls used in a TCP/IP client that sends one packet and receives one packet then exits. Connect the two columnts with arrows, showing the relationship of the system calls and the direction of data travel. A program can detect when a write() or send() call doesn't write all the bytes. It can loop until all the bytes are sent. How about the reverse? How does your program know that it has *read* all the bytes that the client has sent? Answer: It can't. The sending program has to send a count of the number of bytes (probably one of the very first things it sends) and the receiving program has to loop to make sure it reads that many bytes. Thus, your application has to "encapsulate" the data it sends with a header indicating how much data is being sent, or it needs to send some trailing flag in the data indicating the data is finished. (Note that if you send a header containing a size field, the receiving program may have to loop a bit to get all the bytes that make up the bytes of the number indicating the size, unless the size is just a single byte!) Pedantic Coding --------------- Review: http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html#bind and find the paragraph starting "If you are into noticing little things, you might have seen that I didn't put INADDR_ANY into Network Byte Order! Naughty me.". Read the fix; fix your own code. If you don't fix this, then when you later use some other value than INADDR_ANY here, your code will break. The code is wrong; fix it now! Routing Protocols ----------------- Ref: http://www.freesoft.org/CIE/Topics/116.htm Routing is a way of getting packets from one place to another Routing software determines the next hop for a datagram Specifically does 2 things 1. Determines the (optimal) path 2. Delivers the datagram Q: What is the purpose of network routing? Path Determination - http://www.freesoft.org/CIE/Topics/117.htm - http://www.freesoft.org/CIE/Topics/118.htm Algorithms use 'metrics' to determine path. Metrics - cost, length, etc Algorithms populate routing tables, tables are used for determination Can adjust routing tables according to network changes Router receives change notifications and recalculates its routing table Updates to a routing table triggers notifications sent out to other routers Minimalized human config required (setup) http://www.africonnect.com/tcpip_tut.htm "Rather than simply discarding all newly arriving packets, the routers are programmed discard packets in a random fashion to prevent buffer overflow. This is best implemented in a "fair" way so that the data stream having the largest volume suffers the largest number of dropped packets." Q: What happens to packets when the Internet gets overloaded? How do routers recover? Protocols needed to decide on global Internet routing tables: - http://www.freesoft.org/CIE/Topics/119.htm - http://www.freesoft.org/CIE/Topics/120.htm - BGP4 - Border Gateway Protocol (v4) - used between large nets http://www.freesoft.org/CIE/Topics/88.htm - RIP - Router Information Protocol (old) - used internally - OSPF - Open Shortest Path First - replaces RIP, used internally http://www.geocities.com/Heartland/4394/work/ospf.html http://www.freesoft.org/CIE/Topics/89.htm - Cisco protocols (IGRP, EIGRP) - etc. Q: What do BGP and OSPF stand for? What is each used for? Q: What interior/internal routing protocol is replacing the old RIP protocol? Q: T/F - Both BGP and OSPF are designed to work on a local network. Routing vs. Switching http://www.networkcomputing.com/netdesign/1122ippart2.html - routers forward based on IP address (OSI Layer 3) - must open up the Ethernet packet and look at the IP header - switches and hubs forward packets based on MAC address (OSI Layer 2) - don't look inside the Ethernet packets Tracing: traceroute, "traceroute -n" (RTFM) - lost or blocked packets print "*" Q: What do all the fields in the output of a traceroute mean? Local Routing tables: "ip route list" or just "ip route" - shows the known network interface routes - http://w3.cib.unibo.it/manuals/man_tcp/fguide.html "Indirect routing is used when the network numbers of the source and destination do not match. This is the case where the packet must be forwarded by a node that knows how to reach the destination (a router)." Q: T/F "ip route" will show the IP address of your gateway Domain Name System (DNS) ------------------------ DNS turns names into IP addresses. Not essential for a raw Internet connection; but, very, very useful. Important Fact: DNS uses (mostly) UDP, not TCP, for queries and responses. Q: What type of IP protocol does DNS use (most of the time)? Defining protocols - Request for Comment (RFC) ---------------------------------------------- IETF: Internet Engineering Task Force: "Rough concensus and running code" Q: What role do RFC documents play in the Internet? A: http://www.rfc-editor.org/ RFC documents lay out Internet protocols, e.g. for SMTP: http://www.rfc-editor.org/rfc/rfc2822.txt - Some words have specific meanings, see: http://www.rfc-editor.org/rfc/rfc2119.txt - Uses modified ABNF (Augmented Backus-Naur Form) to describe protocols, see: http://www.rfc-editor.org/rfc/rfc2234.txt Certain rules are predefined "CORE" rules, e.g. ALPHA, DIGIT, CHAR, etc. (from section 6.1) Q: True/False - strings ("abc") in ABNF are case-sensitive Q: give an ABNF rule that defines an Algonquin student email address (abcd0001@algonquincollege.com), using these definitions: ALPHA = %x41-5A / %x61-7A ; from CORE: A-Z upper and a-z lower DIGIT = %x30-39 ; from CORE: 0-9 atsign = "@" period = "." Note that ab000001 and abc00001 are also valid userids (must be eight characters); but, a0000001, ab0001, and abcd000001 are not. Hint: start with this and fix it to handle the other two valid cases: algemail = 4ALPHA 4DIGIT atsign "algonquincollege" period "com" Details on socket programming ----------------------------- Reference: http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html Q: Which port numbers are "reserved" for the super-user on Unix/Linux? Do all operating systems reserve these low-numbered ports? http://www.freesoft.org/CIE/RFC/1122/87.htm Q: Under what circumstances can one omit a call to bind() a socket? What happens when you connect() using such an unbound socket? Give an example of an application that does this. Ref: http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html#bind Q: What happens if you forget to call bind() before you call listen() in a server? Does your server program fail to start up? Can clients connect to such a server? (If so, how?) Q: True/False - after a call to accept() you have *two different* open socket file descriptors. Q: True/False - if you close the socket descriptor that is the return value from an accept(), you also close the original socket() descriptor (and vice-versa - they are the same descriptor). Q: You want a server to accept only a single client. True/False - after the accept() call, you can close the original socket file descriptor and use only the one from the accept() call.