Dec. 16, 2010, 7:34 a.m.
posted by vendetta
Analyzing Network Packets
The ability to watch an IP session and decode its meaning is a crucial skill for a network programmer. To fully understand the concepts behind network programming, you must first understand the IP protocol and how it moves data among network devices. Getting familiar with this information could save you countless hours of troubleshooting network programs that aren’t behaving the way you think they should.
The network packets that you capture contain several layers of information to help the data get transported between the two network devices. Each layer of information contains bytes arranged in a predetermined order, specifying parameters specific for the protocol layer. Most packets that you will use in IP network programming will contain three separate protocol layers of information, along with the actual data being transmitted between network devices. Figure illustrates the protocol hierarchy used for IP packets, as discussed in the sections that follow.
The Ethernet Layer
The first layer of the network packet shown in the Analyzer capture is called the Ethernet header. You may see three types of Ethernet protocol packets on your network: Ethernet 802.2, Ethernet 802.3, and Ethernet version 2.
The Ethernet 802.2 and 802.3 protocols are IEEE standard protocols defined for Ethernet layer traffic. Ethernet version 2 is a legacy protocol that is not a standard protocol per se, but it is the most common protocol used on Ethernet networks. Almost all devices (including Windows systems) use the Ethernet version 2 protocol to transmit IP packets by default. Take a look at the packet details frame in Figure.
The Ethernet version 2 header shows the Media Access Card (MAC) addresses that are used to identify individual devices on the Ethernet network, along with an Ethernet protocol number that identifies the next layer protocol contained in the Ethernet packet. Each Ethernet packet conforms to a predetermined layout:
-
A 6-byte destination Ethernet (or MAC) address
-
A 6-byte source Ethernet (or MAC) address
-
A 2-byte next-layer protocol identifier
-
A data payload of 46 to 1500 bytes
-
A 4-byte checksum
The data payload must contain a minimum of 46 bytes to ensure that the Ethernet packet is at least 64 bytes long. (This helps prevent collisions, because sending shorter packets could cause a collision on the network after the packet has been sent, and the sending device would never know.) If the data is not 46 bytes long, padding characters are added. The checksum value supplies a rudimentary error checking mechanism for the data on the network. If the packet becomes corrupt in transit, the checksum will not compute properly, and the packet is marked as bad.
Let’s take a closer look at the most important values in the Ethernet header that you will need to check: the Ethernet addresses and protocol identifier.
Ethernet Address
The Ethernet addresses of devices are assigned by the network card vendor and should not be changed (even though in some instances software allows you to override that address). Each device on an Ethernet network must have a unique MAC address. The MAC address consists of two parts:
-
A 3-byte vendor identifier, or Organizationally Unique Identifier (OUI)
-
A 3-byte device serial number unique to the vendor
The resulting 6-byte network address uniquely identifies the network card on the network, no matter how large the network is. The Internet Assigned Numbers Authority (IANA) assigns vendors MAC addresses to ensure there is no duplication. The assigned numbers are published in Internet Request For Comments (RFC) documents (the most recent Assigned Numbers RFC is RFC 1700). The IANA also maintains a web page (www.iana.org) that contains the most current Ethernet vendor information. Figure lists a few vendor identifiers for MAC addresses.
|
Identifier |
Vendor |
|---|---|
|
00000C |
Cisco |
|
00001D |
Cabletron |
|
00002A |
TRW |
|
00005E |
IANA |
|
000065 |
Network General |
|
0000A2 |
Wellfleet |
|
0000A6 |
Network General (internal assignment, not for products) |
|
0000A9 |
Network Systems |
|
0000AA |
Xerox machines |
|
0000C0 |
Western Digital |
|
0000E2 |
Acer Counterpoint |
|
0020AF |
3COM |
|
008064 |
Wyse Technology / Link Technologies |
|
0080C2 |
IEEE 802.1 Committee |
|
0080D3 |
Shiva |
|
00AA00 |
Intel |
|
00DD00 |
Ungermann-Bass |
|
Ungermann-Bass |
|
|
020701 |
Racal InterLan |
|
02608C |
3Com IBM PC; Imagen; Valid; Cisco |
|
080002 |
3Com (formerly Bridge) |
|
080009 |
Hewlett-Packard |
|
08000B |
Unisys |
|
080011 |
Tektronix, Inc. |
|
08001A |
Data General |
|
08001B |
Data General |
|
08001E |
Apollo |
|
080020 |
Sun machines |
|
08002B |
DEC |
|
08002F |
Prime Computer Prime 50-Series LHC300 |
|
080046 |
Sony |
|
080047 |
Sequent |
|
08004C |
Encore |
|
08005A |
IBM |
|
080069 |
Silicon Graphics |
|
800010 |
AT&T |
After the 3-byte vendor portion, a 3-byte unique serial number is added to produce the unique 6-byte address. You may see Ethernet addresses referenced in several ways; here are some of the traditional formats:
-
As a single value: 0020AFCCEC3
-
Using colons: 00:20:AF:BC:CE:C3
-
Using hyphens: 00-20-AF-BC-CE-C3
-
Using a single hyphen: 0020AF-BCCEC3 (as used by the Analyzer program)
In addition to individual device addresses, the Ethernet addressing scheme allows for broadcast and multicast addresses. In the broadcast address, all of the destination address bits are set to 1 (FFFFFFFFFFFF in hexadecimal). Every device on the Ethernet should accept packets addressed to the Ethernet broadcast address. This address is useful for protocols that must send a query packet to all devices on the network; ARP, for example, when a workstation is looking for a device that has a particular IP address.
Ethernet multicast addresses are a special form of Ethernet address; only a subset of the network devices will accept the packet. The Ethernet software on the network device must be configured to accept the particular type of multicast address. Figure is a list of some Ethernet multicast addresses.
|
Address |
Description |
|---|---|
|
01-80-C2-00-00-00 |
Spanning tree (for bridges) |
|
09-00-09-00-00-01 |
HP Probe |
|
09-00-09-00-00-01 |
HP Probe |
|
09-00-09-00-00-04 |
HP DTC |
|
09-00-2B-00-00-00 |
DEC MUMPS |
|
09-00-2B-00-00-01 |
DEC DSM/DTP |
|
09-00-2B-00-00-02 |
DEC VAXELN |
|
09-00-2B-00-00-03 |
DEC Lanbridge Traffic Monitor (LTM) |
|
09-00-2B-00-00-04 |
DEC MAP End System Hello |
|
09-00-2B-00-00-05 |
DEC MAP Intermediate System Hello |
|
09-00-2B-00-00-06 |
DEC CSMA/CD Encryption |
|
09-00-2B-00-00-07 |
DEC NetBios Emulator |
|
09-00-2B-00-00-0F |
DEC Local Area Transport (LAT) |
|
09-00-2B-00-00-1x |
DEC Experimental |
|
09-00-2B-01-00-00 |
DEC LanBridge Copy packets (all bridges) |
|
09-00-2B-02-00-00 |
DEC DNA Lev. 2 Routing Layer Routers |
|
09-00-2B-02-01-00 |
DEC DNA Naming Service Advertisement |
|
09-00-2B-02-01-01 |
DEC DNA Naming Service Solicitation |
|
09-00-2B-02-01-02 |
DEC DNA Time Service |
|
09-00-2B-03-xx-xx |
DEC default filtering by bridges |
|
09-00-2B-04-00-00 |
DEC Local Area System Transport (LAST) |
|
09-00-2B-23-00-00 |
DEC Argonaut Console |
|
09-00-4E-00-00-02 |
Novell IPX |
|
09-00-77-00-00-01 |
Retix spanning tree bridges |
|
09-00-7C-02-00-05 |
Vitalink diagnostics |
|
09-00-7C-05-00-01 |
Vitalink gateway |
|
0D-1E-15-BA-DD-06 |
HP |
|
CF-00-00-00-00-00 |
Ethernet Configuration Test protocol (Loopback) |
Ethernet Protocol Type
The other important part of the Ethernet header is the Protocol Type field. The difference between the Ethernet version 2 packet and the Ethernet 802.2 and 802.3 packets occurs in the Protocol Type field. The 802.2 and 802.3 packets both contain a 2-byte value in the same location of the packet, and they both use the value to indicate the total size of the Ethernet packet. The Ethernet version 2 protocol uses those same 2 bytes to define the protocol type used in the next level packet that is contained within the Ethernet packet (see Figure). This allows network applications to quickly identify the next layer protocol in the packet data.
Similar to the Ethernet vendor addresses are the IANA-assigned values for various protocols that can be identified within the Ethernet protocol type field. Figure lists some of the assigned protocol values.
|
Value |
Protocol |
|---|---|
|
0800 |
IP |
|
0806 |
ARP |
|
0BAD |
Banyan VINES |
|
8005 |
HP Probe |
|
8035 |
Reverse ARP |
|
809B |
AppleTalk |
|
80D5 |
IBM SNA |
|
8137 |
Novell |
|
8138 |
Novell |
|
814C |
Raw SNMP |
|
86DD |
IPv6 |
|
876B |
TCP/IP compression |
| Note |
Because this book deals with the subject of using IP to transport data across a network, you will see the 0800 value in the protocol type field of all captured packets in the book’s examples. This value identifies the protocol of the next layer as being IP. |
The IP Layer
The next protocol layer in the Analyzer capture packet is the IP packet. In Figure, the packet details frame shows the IP layer section of the Analyzer capture for a specific packet. As you can see, the IP protocol defines several additional fields of to the Ethernet protocol information. Figure describes the IP fields found in the Analyzer capture.
|
Field |
Bits |
Description |
|---|---|---|
|
Version |
4 |
IP header version format (current version is 4) |
|
Header Length |
4 |
The length of the header part of the IP packet, in octets |
|
Type of Service |
8 |
The Quality of Service (QoS) type desired for the packet |
|
Total Length |
16 |
The length of the total IP packet, in octets |
|
Identification |
16 |
An ID value that uniquely identifies the individual IP packet |
|
Flags |
3 |
Indicate whether the IP packet can be fragmented, or if there are more fragments |
|
Fragment offset |
13 |
Location of the fragment in the IP packet |
|
Time to Live (TTL) |
8 |
The maximum time the packet is allowed to remain in the network (in seconds) |
|
Protocol |
8 |
The protocol type of the next level data |
|
Header Checksum |
16 |
A checksum of the IP header data |
|
Source Address |
32 |
The IP address of the sending device |
|
Destination Address |
32 |
The IP address of the receiving device |
|
Options |
variable |
Optional fields that further define the IP packet characteristics |
The value of each field can be seen in the Analyzer packet details frame. Fields that contain more than one type of information, such as the Type of Service and Flags fields, can be expanded to show all of the values in the field.
The following sections describe some of the more important fields of the IP packet that you might have to watch for in your traces.
Address Fields
While Ethernet addresses are good for uniquely identifying devices on a LAN, they do not help at all for identifying remote devices. It is impossible to look at an Ethernet address and determine what network it is on. To help uniquely identify the devices on separate networks, the IP addressing scheme uses particular bits of the 32-bit address to identify address features. The IP address is divided into three parts:
-
A preset number of high bits used to identify the packet address scheme used
-
A predetermined network address
-
A device address on the network
From 1 to 4 high bits identify how the network and device addresses are determined within the total 32 bits of the IP address. The network address identifies the unique network where the device is located. Every network should have a unique IP network address assigned to it. IP routers can use the network address information to decide the routing of individual IP packets to the proper remote network, even when they are located across the Internet. The device address uniquely identifies the device within the network address. No two devices with the same network address can have the same device address.
By default the IP address specification uses the 4 high bits to define four classes of network addresses, as shown in Figure
|
High Bits |
Network Address |
Host Address |
Type |
|---|---|---|---|
|
0 |
7 bits |
24 bits |
Class A |
|
10 |
14 bits |
16 bits |
Class B |
|
110 |
21 bits |
8 bits |
Class C |
|
1110 |
0 bits |
28 bits |
Class D |
This may seem confusing, but in practice it is fairly straightforward. The 32-bit IP address is almost always broken down into four 8-bit (1 byte) segments, which can then be represented by decimal numbers with periods between them, called dotted decimal notation. This is the IP address format you are likely most used to seeing. The decimal numbers are ordered with the network address part on the left side and the host part on the right side.
Using the dotted decimal notation of the IP address, the network class ranges become as follows:
|
Class A |
0.x.x.x–127.x.x.x |
|
Class B |
128.x.x.x–191.x.x.x |
|
Class C |
192.x.x.x–223.x.x.x |
|
Class D |
224.x.x.x–254.x.x.x, which has been further divided into two sections: |
|
IP multicast addresses: 224.x.x.x–239.x.x.x |
|
|
Experimental networks: 240.x.x.x–255.x.x.x |
To complicate things even more, individual class networks can be further divided into other networks, or subnets. Each subnet must use a common network address scheme to identify it among the other subnets in the class network. To identify the network part of the IP address, a subnet mask is defined for a particular subnet. The subnet mask identifies the bits of the IP address that are used to define the network address part, and the bits used to define the host address.
Let’s clarify all this with an example. By default, a class B network address would have a subnet mask of 255.255.0.0, indicating that the upper 16 bits (or first two decimal numbers) are devoted to the network address. The lower 16 bits (or second two decimal numbers) are used to define individual host addresses on the network. Thus, in a default class B network, hosts 130.100.1.6 and 130.100.10.5 are on the same network. Using subnets, however, you can add extra bits to the network address to create subnets of the class B network. For example, if the class B network address 130.100. uses a subnet mask of 255.255.255.0, the third octet also becomes part of the network portion of the address. Thus the individual subnets become 130.100.x.0, where x can be anything from 0 to 255. This causes address 130.100.1.6 to be a separate network from address 130.100.10.5 because the third octets are different.
The hosts on the subnet network can have addresses ranging from 130.100.x.1 to 130 .100.x.254 (the host address of all 1s, 192.168.x.255, is reserved as a subnet broadcast address). This allows for a single class B address to contain up to 256 subnets, all supporting different networks. This technique is used most often for large building LANs as well as campus LANs to help divide the total number of devices on a network to a manageable number.
Fragmentation Flags
One of the many complexities of IP packets is their size. The maximum size of an IP packet can be 65,536 bytes. This is a huge amount of data for an individual packet. In fact, most lower-level transports (such as Ethernet) cannot support carrying a large IP packet in one piece (remember, the Ethernet data section can only be 1,500 bytes long). To compensate for this, IP packets employ fragmentation to divide the IP packet into smaller parts for transport to the destination. When the pieces arrive at the destination, the receiving software must have a way to recognize the fragmented packet and reassemble the pieces back into a single IP packet.
Fragmentation is accomplished using three fields of the IP packet, the fragmentation flags, the fragment offset, and the identification fields. The fragmentation flags consist of three 1-bit flags:
-
A reserved flag, which must be zero
-
A Don’t Fragment flag, which indicates that the IP packet may not be fragmented
-
A More Fragment flag, which indicates that this packet is an IP fragment and more fragments are on the way
The IP Identification field uniquely identifies each IP packet. All the fragments of any packet will have the same identification number. This tells the receiving software which packets need to be joined together to create the original IP packet. The fragment offset field indicates the location for the fragment in the original packet.
Type of Service Field
The Type of Service field identifies a Quality of Service (QoS) type for the IP packet, to mark an individual IP packet (or a stream of IP packets) as having a particular priority. In the past this field was not used much. However, recently there has been a push for using this field to prioritize real-time data such as video and audio streams. This will help routers and other network devices to give real-time data packets a higher priority of service to reduce the delay in their transmission. In most network traffic, the Type of Service field will be set to all zeros, indicating normal, routine data. However, with the increased use of IP for transporting real-time data, you may encounter applications that use the Type of Service field to prioritize packets.
The Type of Service (ToS) field contains 8 bits of information, divided into the following subfields:
-
3 bits used as a precedence field
-
1 bit used to denote normal or low delay
-
1 bit used for normal or high throughput
-
1 bit used for normal or high reliability
-
2 bits reserved for future use
The 3-bit precedence field allows for eight levels of packet priority, defined in Figure.
|
Bits |
Priority |
|---|---|
|
000 |
Routine |
|
001 |
Priority |
|
010 |
Immediate |
|
011 |
Flash |
|
100 |
Flash Override |
|
101 |
CRITIC/ECP |
|
110 |
Internetwork Control |
|
111 |
Network Control |
Protocol Field
The Protocol field is used to identify the next layer protocol contained in the IP packet. The IANA has defined 135 values for this field that can be used in IP packets, but in practice on a typical network you will see just a few. Figure defines some of the more popular values.
|
Value (Decimal) |
Description |
|---|---|
|
1 |
Internet Control Message (ICMP) |
|
2 |
Internet Group Message (IGP) |
|
6 |
Transmission Control (TCP) |
|
8 |
Exterior Gateway (EGP) |
|
9 |
Interior Gateway (Cisco IGP) |
|
17 |
User Datagram (UDP) |
|
88 |
Cisco EIGRP |
The two protocols in this table discussed in this book are TCP (protocol 6) and UDP (protocol 17). Most of the applications that you will code using C# will use one of these two higher-level protocols. They are described in the following two sections.
The TCP Layer
The Transmission Control Protocol (TCP) adds connection information to the data packet. This allows programs to create an end-to-end connection between two network devices, providing a consistent path for data to travel. TCP guarantees the data will reliably be delivered to the destination device or that the sender will receive indication that a network error occurred.
Because of this feature, TCP is called a connection-oriented protocol. Each TCP connection, or session, includes a certain amount of packet overhead related to establishing the connection between the two devices. Once the connection is established, data can be sent between the devices without the application having to check for lost or out-of-place data.
For a network programmer, it is a good idea to have a basic understanding of how TCP works, and especially how it moves data between devices on the network. Figure shows the Analyzer capture window with the TCP Header fields expanded in the packet details tree. These fields contain the information necessary for TCP to implement its advanced connection and data reliability features.
Each of the many fields in the TCP Header is associated with a particular function in the TCP session. The functions worth looking at are as follows:
-
The tracking of multiple connections between devices (source and destination ports)
-
The tracking of packet order and requests for retransmission of lost packets (sequence and acknowledgement numbers)
-
The opening and closing of connection streams between devices for data transmission (TCP flags)
The following sections describe these functions and their roles in network programming.
TCP Application Ports
The first two entries in the expanded TCP Header in the Analyzer capture window are the source and destination ports. TCP uses ports to identify individual TCP connections on a network device. The port value identifies a TCP endpoint on the device to be used for a particular application. To communicate with an application on a remote device, you must know two pieces of information:
-
The remote device’s IP address
-
The TCP port assigned to the remote application
For a TCP connection to be established, the remote device must accept incoming packets on the assigned port. Because there could be many applications running on a device that uses TCP, the device must allocate specific port numbers to specific applications. This tells the client which port to use for a particular application and tells the host which application an incoming packet should be forwarded to. Figure illustrates an example of how clients and servers use TCP ports to channel data between applications.
In Figure, network device A is running two server applications, waiting for incoming packets from remote devices. One application is assigned TCP port 8000 on the device, and the other is assigned port 9000. Network device B is a client that wants to connect to the applications on the server. For a device to send a packet to a remote device, it too must obtain a free TCP port from the operating system, which remains open for the duration of the session. The client TCP port number is usually not important and can be assigned to any available port on the device. The client forwards the packet from an available port on Device B to the application TCP ports on Device A.
The combination of an IP address and a port number defines an IP endpoint. A TCP session is defined as the combination of a local IP endpoint and a remote IP endpoint. Only one session can have both these properties the same. A single network application can use the same local IP endpoint, but each remote connection must have either a separate IP address or remote port number.
The IANA has defined a list of standard TCP ports assigned to specific applications. This ensures that any host running the specific application will accept connections on that TCP port for that application. Figure shows a partial listing of the many different assigned application port numbers.
|
Port |
Description |
|---|---|
|
7 |
Echo |
|
13 |
Daytime |
|
17 |
Quote of the day |
|
20 |
FTP (data channel) |
|
21 |
FTP (control channel) |
|
22 |
SSH |
|
23 |
Telnet |
|
25 |
SMTP |
|
37 |
Time |
|
80 |
HTTP |
|
110 |
POP3 |
|
119 |
NNTP |
|
123 |
Network Time Protocol (NTP) |
|
137 |
NETBIOS name service |
|
138 |
NETBIOS datagram service |
|
143 |
Internet Message Access Protocol (IMAP) |
|
389 |
Lightweight Directory Access Protocol (LDAP) |
|
443 |
Secure HTTP (HTTPS) |
|
993 |
Secure IMAP |
|
995 |
Secure POP3 |
Ports that are numbered from 0 to 1023 are called well-known ports because they are assigned to specific, common applications. If you are creating a new application, avoid assigning it to one of these ports to avoid confusion. In fact, if an application is already using a port, the system will not allow you to use that port. Ports numbered from 1024 to 65,535 are open for use by any application; even in this wide range, it is still possible to run into two applications that chose to use the same port. For this reason, many custom-made applications give users the choice of defining their own port number to use.
For the network programmer, TCP ports are crucial elements. All server applications must use a valid (and available) port on the network device. It is up to you to decide how to use the TCP port assignment for your application. As mentioned, it is always a good idea to give your customer the option of changing the TCP port number of your application. Just remember that if the server port number changes, the client application must know about this change, or it will never find the server application.
Ensuring Packet Reliability
After the ports, the next fields in the TCP header are the sequence and acknowledgement numbers. These values allow TCP to track packets and ensure they are received in the proper order from the network. If any packets are missing, the TCP system can request a retransmission of the missing packets and reassemble the data stream before passing it off to the application.
Each packet sent has a unique sequence number for the TCP session. A random number is chosen for the first packet sent in the session. Each subsequent packet sent by the device increases the sequence number by the number of TCP data bytes in the preceding packet. This ensures that each packet is uniquely identified within the TCP data stream.
The receiving device uses the acknowledgement field to acknowledge the last sequence number received from the remote device. The receiving device can receive multiple packets before sending an acknowledgement. The returned acknowledgement number should be the highest consecutive sequence number of data received. This technique is called a sliding window. Packets received out of order can be held in a buffer and placed in the right order when the other packets are successfully received, rather than being retransmitted. If a packet it dropped, the receiver will see the missing sequence number and send a lower acknowledgement number to request the missing packet. Without the sliding window each packet would have to be individually acknowledged, resulting in an increase of network traffic and delay.
When troubleshooting TCP problems, the sequence and acknowledgement numbers are often the most difficult part to debug. Often it is best to create a list of packet sequence numbers for each packet from each individual device. By comparing the TCP sequence numbers of each packet, you can determine if packets are being frequently retransmitted (repeated or overlapping sequence numbers in a TCP session). This could mean a network problem somewhere along the line.
Establishing a TCP Session
After the header length field, the TCP Header shows a Flags field that can be expanded to view the fields defined in Figure. The flags are used to control the TCP connection between the two devices.
|
Flag |
Description |
|---|---|
|
6 bits that are reserved |
Reserved for future use—always zero |
|
1-bit URG flag |
Marks the packet as containing urgent data |
|
1-bit ACK flag |
Acknowledges receiving a packet |
|
1-bit PUSH flag |
Indicates data is to be pushed to the application immediately |
|
1-bit RESET flag |
Resets the TCP connection to the initial state |
|
1-bit SYN flag |
Indicates a TCP synchronization packet (start-of-session) |
|
1-bit FIN flag |
Indicates a TCP end-of-session |
TCP uses connection states to determine the status of a connection between devices. A specific handshaking protocol is used to establish these connections and to monitor the status of the connection during the session. The TCP session has three phases:
-
Opening handshake
-
Session communication
-
Closing handshake
Each phase requires the flag bits to be set in a certain order. The opening handshake is often called the three-way handshake and requires three steps to establish the connection:
-
The originating host sends a SYN flag to indicate the start of a session.
-
The receiving host sends a both a SYN flag and an ACK flag in the same packet to indicate it accepts the start of the session.
-
The originating host sends an ACK flag to indicate the session is open and ready for packets.
After the session is established, you will see the ACK flag set on packets, indicating that the device is acknowledging the receipt of a packet with a particular sequence number. To close the session, another handshake is done using the FIN packets:
-
The initiating host sends an ACK flag to officially close the session.
Sometimes it helps to visualize these steps. Figure shows the TCP handshake protocol in action.
-
The remote host sends both an ACK flag and a FIN flag in the same packet to indicate it accepts the end of the session.
The phases of the TCP session are associated with connection state names. Each connection state indicates the session’s current position in the handshaking sequence. The connection states apply equally to clients as well as servers. Both devices in the TCP session follow the same TCP states. Figure lists the TCP connection states and describes their associated flags.
|
State |
Description |
|---|---|
|
CLOSED |
The session is not active. |
|
LISTEN |
The device is waiting for incoming data on a specific port. |
|
SYN-SENT |
The device sent a SYN flag to start a session and is waiting for the remote device to acknowledge and return a SYN flag. |
|
SYN-RECEIVED |
The device received a SYN flag, returned both a SYN flag and an ACK flag to complete the start of session, and is waiting for an ACK flag. |
|
ESTABLISHED |
Both devices completed the opening handshake and can pass data packets between each other. |
|
FIN-WAIT-1 |
The device sent a FIN flag to end the session. |
|
FIN-WAIT-2 |
The device received a FIN flag and returns FIN and ACK flags. |
|
LAST-ACK |
The device has sent a FIN flag in response to receiving a FIN flag and is waiting for the final ACK flag from the remote device. |
|
TIME-WAIT |
After the LAST-ACK state a device will wait a preset amount of time before officially closing the session port to ensure the remote device does not send additional data. |
The UDP Layer
The User Datagram Protocol (UDP) is another popular high-level protocol used in IP communications. After studying TCP, UDP will seem like a snap. Unlike TCP, UDP provides a connectionless path between network devices to transmit data, and thus does not need all of the overhead of session establishment flags and connection states. Each UDP “session” is nothing more than a single packet transmitted in one direction. Figure shows a sample UDP packet in the packet details frame of the Analyzer capture window.
The UDP header fields are pretty straightforward:
-
Source Port
-
Destination Port
-
Message Length
-
Checksum
-
Next Level Protocol
Like TCP, UDP tracks individual connections using port numbers and assigns port numbers from 0 to 1023 to reserved application ports. Ports 1024 to 65536 are available for you to use in your applications. Figure shows a list of some of the well-known UDP port numbers.
|
Port |
Description |
|---|---|
|
53 |
Domain Name System |
|
69 |
Trivial File Transfer Protocol |
|
111 |
Remote Procedure Call |
|
137 |
NetBIOS name service |
|
138 |
NetBIOS datagram |
|
161 |
Simple Network Management Protocol |
Many applications have both a TCP and a UDP port reserved for their use, even though in practice the application only uses one or the other. Either way, it is always safest to use port numbers that are above the reserved port number area to avoid possible conflicts in future protocol changes.
The next section of this chapter describes what you should know about how to use the TCP and UDP protocols for your programs.






