


destination mask cost interface next hop
N M 1 eth0 *
For example, if the IP address of various hosts was 128.1.2.3, 128.1.2.4,
128.1.2.5, and the network mask 255.255.255.0, then the entry would be
destination mask cost interface next hop 128.1.2.0 255.255.255.0 1 eth0 *Note that we cannot specify a single next hop in this case -- the router must have a convention for saying "the next hop is the address A that we are sending the packet to". For this example, I am using "*" to mean that.
We can also summarize the other routes, the ones to the entire rest of the internet. Here is an example:
destination mask cost interface next hop
0.0.0.0 2 eth0 R1
Here, the address mask is all zeros. If we perform our usual computation
to determine if the route matches, we will compare
Both numbers are the result of ANDing with zero, and hence both numbers are zero, and therefore the two numbers match, and this is a valid route. This is a valid route, no matter what the destination address! In other words, this is a default route, and R1 is a default router for this host.
Here is the complete routing table for host E:
destination mask cost interface next hop 128.1.2.0 255.255.255.0 1 eth0 * 0.0.0.0 0.0.0.0 2 eth0 R1We have entered an address of "0.0.0.0" as the destination of the second entry, but the actual number could be anything.
To summarize, when sending a packet to a host on the directly attached network, that host will have an IP address beginning with 128.1.2, and both routes will match. Since the first has lower cost, we will send the packet directly. When sending a packet to a host on a different network, only the second route will match, and we will send the packet to the default router.
We're almost there. Given any IP packet, we know where to send it to. The only question is, how do we send an IP packet on a directly attached network? In fact, if that network is an Ethernet, what Ethernet address do we send it to? If it is an ATM address, what ATM address do we send it to?

0x45 0x00 0x01 0x04 0x00 0x00 0x00 0x00 0x60 0x11 0x00 0x00 0x80 0xAB 0x0A 0xCE 0x80 0x01 0x02 0x03The little-endian way of writing the decimal value 260 would be0x04 0x01This is never used in the Internet protocols.
Writing big-endian values into a buffer
An incorrect way of writing a short to an IP buffer would be:*((short *) (b + 2)) = lengthA correct, more portable way of writing a short to an IP buffer would be:*((short *) (b + 2)) = htons(length)Note that in general we use a struct to represent the IP header, for example on uhunix2, struct ip in /usr/include/netinet/ip.h. But we will still need to use htons.
The protocol numbers used in IP are:
| 1 | ICMP |
| 6 | TCP |
| 17(0x11) | UDP |