------------------------- Week 02 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) 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. The Internet is dumb. Some say you could implement it using two cans and a string. (Or carrier pigeons.) The intelligence is "at the edges". Encapsulation - Protocol Layering --------------------------------- http://en.wikipedia.org/wiki/Internet_protocol_suite - ISO seven layers - Internet four layers Your application data is passed to the computer's TCP/IP stack, which wraps an IP header around it (containing information such as source/destination address). That wrapped packet is passed down to the network hardware, which wraps your packet with hardware framing bits that will get it out your network card, onto the network, and into the next network card. Also: "2.2. Low level Nonsense and Network Theory" in http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html This "packetization" of your data across the Internet may be visible to your application. Packets may be dropped, arrive late, or arrive out-of-sequence (and no amount of money can change that). Dotted Quad (Dotted Decimal) structure -------------------------------------- http://www.ralphb.net/IPSubnet/ipaddr.html IP addresses are part network number and part host number depending on how you divide up the 32 bits, e.g. address 1.2.3.4 might be host number 4 on network 1.2.3 (a /24 network), or it might be host 3.4 on network 1.2 (a /16 network), or host 2.3.4 on network 1 (a /8 network). Some nice properties apply to a "network" of hosts, including limiting of traffic and being able to direct traffic to a large number of hosts by using just the network number: http://www.ralphb.net/IPSubnet/subnet.html In traditional routing, sub-networks and hosts are not allowed to use numbers that are either all-zeroes or all-ones. All-ones addresses are interpreted as broadcast addresses for their networks - packets sent to these addresses are processed by every node on the network. (All-zeroes used to be broadcast addresses 20 years ago.) Q: What happens if you send an ICMP echo "ping" to a network broadcast address? Q: Suppose you forged your IP source address and then sent a ping to a network broadcast address? http://www.webopedia.com/TERM/S/smurf.html IP Routing ---------- When an application's machine wants to send a packet on the network, the low-level network hardware (which knows nothing about IP addresses) needs to know "the next stop" hardware network interface for the packet. Either the packet is destined directly for a host on one of the attached networks (often a single network); or, the packet has to be sent off to the network card of a "gateway" machine on the local network, and the gateway machine will know where to forward it (to another hardwre network card on another network, and so on...). http://www.faqs.org/rfcs/rfc950.html - setion 2.2 shows code fragment used in IP routing and subnet routing - note that the IP address and IP mask are unique to each network interface Either way, your system has to send the IP packet, encapsulated for the local network hardware (e.g. Ethernet). That encapsulation - the finding out of the network card MAC (Media Access Control) address - is often assisted by a low-level networking protcol such as ARP (Address Resolution Protocol). http://en.wikipedia.org/wiki/MAC_address http://www.dcs.gla.ac.uk/~lewis/networkpages/m05s05IPForwarding.htm Q: What Linux command shows you your interfaces and their IP addresses and network masks? A: ifconfig (may be under /sbin or /usr/sbin) Q; What Linux command shows you your main IP routing tables? A: ip route (or: ip route list table main) Q: How does my computer know if an IP address is on the local network? Q: How does my machine know what to do with an IP packet if the packet IP address isn't on the local network? Q: Does my computer have routing tables for the Internet? Does my machine know how a packet will travel to Google.ca ? Subnetting ---------- http://www.bergen.org/ATC/Course/InfoTech/Coolip/ RFC: http://www.faqs.org/rfcs/rfc950.html Subnetting is the process of being handed a network address and being able to subdivide it into subnets, correctly deciding how many bits to use for the subnet and how many bits to leave for the host addresses. See the examples in: http://www.bergen.org/ATC/Course/InfoTech/Coolip/ Figure 14: "Notice how sequential subnet numbers do not appear to be sequential when expressed in dotted-decimal notation. This can cause a great deal of misunderstanding and confusion since everyone believes that dotted-decimal notation makes it much easier for human users to understand IP addressing. In this example, the dotted-decimal notation obscures rather than clarifies the subnet numbering scheme!" Q: Given an IP address and network mask, determine the network prefix (the /nn number), the network number, and the broadcast address. Q: Given an IP network address, apply subnetting to the address to supply a certain number of subnets, or a certain number of hosts. Q: What is the maximum number of hosts you can have (avoiding the all-zero and all-one networks and hosts) for a Class C address and a 4-bit subnet? (How many usable subnets are available with with four bits? How many usable hosts can reside on each of those sub-networks? Multiply.) Answer: 196 http://www.ralphb.net/IPSubnet/example.html http://www.ralphb.net/IPSubnet/restr.html Q: What is the next available subnet address after this one 192.168.1.0/24 ? Answer: 192.168.2.0 (/24) - add one to the network part of the 32-bit number Q: What is the next available subnet address after this one 192.168.1.0/25 ? Answer: 192.168.1.128 (/25) - add one to the network part of the 32-bit number Q: What is the lowest usable host address in the 192.168.1.128/25 network? Answer: 192.168.1.129 (/25) - avoid all-zero host addresses CIDR (supernetting) ------------------- http://www.bergen.org/ATC/Course/InfoTech/Coolip/ - diagrams of bits for traditional Class A,B,C networking http://tools.ietf.org/html/rfc1518 - the CIDR proposal http://www.ipprimer.com/addressing.cfm "Although RFC 1812 came out in June of 1995(!), most certification tests still test you on the RFC 950 rules, for (in my opinion) one of the following reasons: * Their software still follows RFC 950 rules (this is rare.) * Since RFC 1812 simplifies things significantly, there's not enough material to test on. Test items from RFC 950 are added as "filler". * They are ignorant of the fact that the material on their tests has been out of date for more than five years. * They are mean-spirited, perniciously forcing you to learn material that will never be relevant to your job." Originally, IP addresses were classified strictly as Class A, B, C depending on the size of the network part. Class A addresses used the top 8 bits for the network number; Class B used 16 bits; Class C used 24 bits. The top few bits of an IP address decided whether an address was A, B, or C. "Although the original intent of having Classes was to allow for flexible addressing, experience showed that the hard boundary of the three Classes actually made the addressing less flexible. For example, if a site connecting to the Internet needed to address 300 hosts, then a Class C network wouldn't be adequate and a Class B would need to be assigned. This resulted in poor utilization of the assigned address space and caused a faster-than-necessary rate of consumption of the available IP address space." http://www3.ietf.org/proceedings/99jul/I-D/draft-ietf-idr-aggregation-tutorial-01.txt When the number of IP numbers started to run scarce, the Internet changed to using an arbitrary number of bits: "CIDR removed the idea of Classes from IP. Instead of having networks with an implied number of bits referring to network/host, there are "prefixes" with an associated mask explicitly identifying which bits refer to network/host. For example, the prefix "38.245.76.0" with a mask of "255.255.255.0" has 24 bits of network and 8 bits of host (i.e., it can address the same number of hosts as a Class C network even though the prefix is in the Class A range). The CIDR paradigm prefers the term "prefix" over "network" because it's more clear that no Class is being implied. Another way to write this example prefix is "38.245.76.0/24", meaning that the mask contains 24 1s in the high-order portion of the mask." http://www3.ietf.org/proceedings/99jul/I-D/draft-ietf-idr-aggregation-tutorial-01.txt CIDR throws out all the traditional classes and subnetting: "The solution is simple: someone just issued an edict saying "forget everything you learned, we won't bother with those rules any more". There's even a command to tell the routers themselves that they should ignore the rules - "ip classless" When you break the rules like this, and allow netmasks that end in all 0's or all 1's, it's called "CIDR" - Classless InterDomain Routing." http://www.gtoal.com/subnet.html Client/Server programming ------------------------ Remember how to write Makefiles ? all: foo bar foo: foo.c gcc -Wall foo.c -o foo bar: bar.c gcc -Wall bar.c -o bar Use the select() system call to listen to multiple I/O descriptors all at the same time: "man select" Writes to sockets can be incomplete! The system may not write all the bytes you asked. You need to loop to send the remaining bytes. http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html#sendall