OSD Home

- # - Physical layers
  - # - Ethernet
  - # - SLIP
- # - Transport protocols
  - # - IP
  - # - IPX
  - # - AppleTalk
- # - Code snippets
- # - Links
- REPORT BUGS OR ERRORS IN THIS DOCUMENT

## Physical layers

#### Ethernet

Ethernet is also known as Carrier Sense, Multiple Access with Collision Detection (CSMA/CD). This describes the operation of Ethernet, in which a host waits until the transmission medium is quiet (carrier sense), begins transmitting a carrier, then transmits the packet. The host monitors its own transmission to detect if it becomes garbled because another host began transmitting at the exact same instant (collision detection). Collisions cause both hosts to stop transmitting, wait a random interval, then try again. Ethernet is probabilistic: there is no guarantee that the packet will be delivered. The collision rate skyrockets when the network is heavily loaded. Under normal circumstances, however, there are few collisions, and Ethernet is reliable and gives good performance. (xxx - this is especially true since cheap Ethernet switches -- which prevent most collisions -- became widely available)

'Multiple access' means that all Ethernet hosts are equals (peers). There are no masters or slaves, or hosts with different priorities or privileges.

A single Ethernet frame has a 14-byte header, 46 to 1500 bytes of data, and a 4-byte checksum, for a total frame size of 64-1518 bytes. If the data to be transmitted is shorter than 46 bytes, zero bytes must be added before the checksum as padding. The header is specified by IEEE standard 802.3:

- 6-byte (48-bit) destination Ethernet address
- 6-byte source Ethernet address
- 2-byte Ether Type. In older versions of Ethernet, this was used as a length field. In Ethernet II, this field is used to identify the higher-level protocol:

  Ether type
  hex | decimal | meaning
  --- | --- | ---
  0000-05DC | 0-1500 | Packet length field for 'raw' IEEE 802.3 packet
  0800 | 2048 | IP v4 (Ethernet II)
  0806 | 2054 | Address Resolution Protocol (ARP; Ethernet II)
  809B | 32923 | AppleTalk (Ethernet II)
  8137 | 33079 | Novell IPX (Ethernet II)

Multi-byte values in the Ethernet frame are big endian (network byte order).

Each Ethernet device has a unique address. Blocks of addresses are assigned by a central authority (the IEEE) to manufacturers, who then assign unique addresses from the blocks to each device they manufacture. The top 24 bits of the address indicate the vendor. From RFC-1700:

Top 24 bits of Ethernet address | Vendor
--- | ---
00000C | Cisco
0000BC | Allen-Bradley
00AA00 | Intel
02608C | 3Com
080009 | Hewlett-Packard
080020 | Sun

Ethernet supports broadcast packets, which will be received by all hosts. Such a packet has the destination address set to all ones (FF:FF:FF:FF:FF:FF).

#### SLIP

SLIP stands for Serial Line IP. It's an extremely simple standard for sending IP packets over a serial connection. SLIP is described in RFC-1055, which is a 12K text document.

## Transport protocols

#### IP

IP stands for Internetwork Protocol. All IP hosts are equals (peers). There are no masters or slaves, or hosts with different priorities or privileges.

An IP packet (or datagram) is a minimum of 20 bytes long, which is the minimum size of the IP header. All multi-byte values in the packet are big endian (network byte order).
xxx - packet details

IP addresses are 32 bits (for IP v4). Blocks of addresses on the Internet are assigned by a central authority (IANA). These blocks may contain 16 million addresses (Class A), 65,000 addresses (Class B), or 256 addresses (Class C). Because of concern over the depletion of the IPv4 address space, blocks of intermediate sizes are also being used.

Unlike Ethernet, individual IP v4 addresses may be assigned dynamically, to different hosts at different times.

xxx - lots more details...

#### IPX

xxx - to do
Obsolete? New NetWare uses IP as the default...

#### AppleTalk

xxx - to do

## Code snippets

These snippets can be built with GCC for Linux, MinGW (GCC for Windows), Borland C 5.5 for Windows, Turbo C for DOS, or 16-bit Watcom C for DOS.

- Example stream (TCP) server, using HTTP (Screenshot)
- Example TCP client
- Example UDP (datagram) server
- Example UDP client
- DOS to Winsock VXD interface; lets DOS programs use Winsock from inside a Win95 DOS box. Incomplete:
  - Does not (yet) work correctly with Winsock 2 (Win98).
  - Does not (yet) work with 32-bit compilers like DJGPP.
  - Does not work with Windows NT/2k/XP.
  - No `gethostbyname()` call (yet).

## Links

TCP/IP and related network protocols are specified by the RFCs (Requests For Comment):
http://www.rfc-editor.org. Some of the more basic RFCs are:

RFC-791 | IP (Internetwork Protocol, version 4)
RFC-792 | ICMP (Internetwork Control Message Protocol)
RFC-826 | ARP (Address Resolution Protocol; for IP over Ethernet)
RFC-786 | UDP (User Datagram Protocol)
RFC-1025 | TCP/IP Bake-Off (testing of TCP/IP implementations)
RFC-1122 | Requirements for Internet hosts (1)
RFC-1123 | Requirements for Internet hosts (2)
RFC-1700 | Assigned Numbers

Roll Your Own Intranet: http://www.vijaymukhi.com/vmis/roll.htm (write your own TCP/IP stack)

Ethernet Encapsulation Cheat Sheet: http://www.cisco.com/warp/public/105/encheat.html

Small TCP/IP stacks:

- http://www.egnite.de/ethernut.de/en/ Seems to be for the AVR CPU only. ARP, IP, ICMP, UDP, TCP, DHCP, HTTP. No SLIP or PPP. License is BSD-ish.
- Liquorice: http://liquorice.sourceforge.net/ Scalable RTOS with networking, written mostly in C. AVR and 386 CPUs. LGPL-ish license. SLIP, PPP, ARP/Ethernet, ICMP, UDP and TCP.
- LWIP: http://www.sics.se/~adam/lwip/ IP, ICMP, UDP, TCP. Socket API. DJGPP, uC/OS, eCos, and Rabbit 2000 ports.
- UCIP: http://ucip.sourceforge.net/ BSD license.
- Watt-32: http://www.bgnett.no/~giva/
- Simple stack (PPP, SLIP, UDP, IP) for 8-bit 68HC08 CPU: http://e-www.motorola.com/brdata/PDFDB/docs/AN2120.pdf
- OpenTCP: http://www.opentcp.org/ Supposedly written in ANSI C. BSD-like license.
- Phil Karn's KA9Q TCP/IP code: http://www.ka9q.net/code/ka9qnos/ Various copyrights, but the PPP code is public domain.

Asm source code for 16-bit packet drivers: ftp://ftp.crynwr.com/drivers/00index.html

Spec sheet for National Semiconductor 8390 chip, used in NE2000 Ethernet board: http://www.national.com/pf/DP/DP8390D.html

## TO DO

    - only Ethernet II is described here. Other types of Ethernet:
      'raw' 802.3 (Ether type = packet length), 802.2 LLC, 802.2 LLC + SNAP
      (are these three obsolete?)
    - Service Access Point (SAP) codes for 802.2 LLC
    - IEEE 802.5 (Token Ring)?
    - details of IP packet: version, IHL, TOS, packet length, ID, flags,
      fragment offset, TTL, protocol, header checksum, src and dst adr
    - Other IP stuff: addressing, subnets, fragmentation, MaxTU, broadcasts
    - protocols that run atop IP: ICMP, UDP, TCP
    - protocols that run atop UDP: BOOTP, DHCP, TFTP, DNS
    - protocols that run atop TCP: HTTP, FTP, SMTP, POP, NNTP, FTP, Telnet
    - Berkeley socket API
    - IPX? AppleTalk? IP v6?
    - ARP

## REPORT BUGS OR ERRORS IN THIS DOCUMENT