-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUDP_Notes.txt
178 lines (155 loc) · 7.92 KB
/
UDP_Notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
User Datagram Protocol Notes
Notation:
---------
Bit structures shown below are ordered LSB-to-MSB left-to-right (i.e. bit 0 is on the left).
Literal numbers expressed in binary and hexadecimal are written with MSB on the left (e.g. 0x7A = 0b01111010)
IPv4:
-----
When a datagram is sent over IPv4, the full packet (at the "Internet Layer") is 20-bytes in length (or greater).
If the 'IHL' (see below) is > 5, the header length is 4*IHL bytes (octets) long.
See "IPv4_Notes.txt" for IPv4 packet details.
UDP Datagram Structure:
-----------------------
When the payload of an IP packet is a datagram (as in UDP), its contents are structured as a packet with its own header
structure.
| IP Header | Datagram |
_____________/\____
/ \
| UDP Header | Data |
___/\________________________________________________________________
/ \
| Source Port (16b) | Dest Port (16b) | Length (16b) | Checksum (16b) |
Field Name Length (bits) Description
-------------------------------------------
Source Port 16 Socket port number of source (optional; could also be 0x0000)
Dest Port 16 Socket port number of destination (mandatory)
Length 16 Length of datagram including header and data in octets. >= 8. Must be even number?
Checksum 16 16-bit one's complement of one's complement sum of pseudo-header (see below).
Pseudo-Header
-------------
In IPv4, the checksum is optional.
For checksum calculating purposes, the pseudo-header is the following:
| Source Addr (32b) | Dest Addr (32b) | 0x00 (8b) | Protocol (8b) | UDP Length (16b) |
Protocol = 17 (UDP protocol number defined by IETF in RFC768)
UDP Length is the same length in the UDP header Length field (length of UDP header and data)
Checksum:
---------
Recall that -N in one's complement can be found by simply negating each bit of +N (e.g. +9 = 0b01001, -9 = 0b10110)
In one's complement arithmetic, the carry bit (i.e. bit 17 in 16-bit arithmetic) is added in the LSb place (wraps).
The final sum is then one's complemented (negated) to yield the checksum value.
UDP-over-Ethernet Full Packet Diagram:
--------------------------------------
EtherType = IPv4
IP Header Length (IHL) = 5
(Byte-Offset, relative to Start of Frame)
===============
== Data Path ==
===============
(-8) | Layer 1 Packet (72-1530B) | Interpacket Gap (12B) |
\/
____________/\________________________________________________________
/ \
(-8) | Preamble (7B) | Start Frame (1B) | Layer 2 Ethernet Frame (64-1522B) |
\/
________________________________________________/\_______
/ \
(0) | Ethernet Header (14B) | Payload (46-1500B) | CRC32 (4B) |
\/
__________________________________/
/ \
(14) | IP Header (20B) | Datagram |
\/
____________________/\__
/ \
(34) | UDP Header (8B) | Data |
\/
__________________/\_________
/ \
(42) | Data (Application-Specific) |
==========================
== Ethernet Header Path ==
==========================
(-8) | Layer 1 Packet (72-1530B) | Interpacket Gap (12B) |
\/
____________/\________________________________________________________
/ \
(-8) | Preamble (7B) | Start Frame (1B) | Layer 2 Ethernet Frame (64-1522B) |
\/
________________________________________________/\_______
/ \
(0) | Ethernet Header (14B) | Payload (46-1500B) | CRC32 (4B) |
\/
_________/\____________________________________________________
/ \
(0) | Dest MAC (6B) | Src MAC (6B) | EtherType & 802.1Q Tag (2B/6B) |
====================
== IP Header Path ==
====================
(-8) | Layer 1 Packet (72-1530B) | Interpacket Gap (12B) |
\/
____________/\________________________________________________________
/ \
(-8) | Preamble (7B) | Start Frame (1B) | Layer 2 Ethernet Frame (64-1522B) |
\/
________________________________________________/\_______
/ \
(0) | Ethernet Header (14B) | Payload (46-1500B) | CRC32 (4B) |
\/
__________________________________/
/ \
(14) | IP Header (20B) | Datagram |
\/
____/\___________________________________________________________________________________________
/ \
(14) | Version (4b) | IHL (4b) | DSCP (6b) | ECN (2b) | Total Length (16b) | ID (16b) | Flags (3b) |
Fragment Offset (13b) | TTL (8b) | Protocol (8b) | Header Checksum (16b) | Source IP Addr (32b) |
Dest IP Addr (32b) |
=====================
== UDP Header Path ==
=====================
(-8) | Layer 1 Packet (72-1530B) | Interpacket Gap (12B) |
\/
____________/\________________________________________________________
/ \
(-8) | Preamble (7B) | Start Frame (1B) | Layer 2 Ethernet Frame (64-1522B) |
\/
________________________________________________/\_______
/ \
(0) | Ethernet Header (14B) | Payload (46-1500B) | CRC32 (4B) |
\/
__________________________________/
/ \
(14) | IP Header (20B) | Datagram |
\/
____________________/\__
/ \
(34) | UDP Header (8B) | Data |
\/
______/\_____________________________________________________________
/ \
(34) | Source Port (16b) | Dest Port (16b) | Length (16b) | Checksum (16b) |
Offsets to Useful Fields:
-------------------------
Field Offset (B) Length (B)
----------------------------------
Dest MAC 0 6
Src MAC 6 6
Protocol 23 1
Src IP 26 4
Dest IP 30 4
Src Port 34 2
Dest Port 36 2
UDP Length 38 2
UDP Checksum 40 2
UDP Data 42 (value at UDP Length field)
IPv6:
-----
When UDP is carried over IPv6, there are several differences.
UDP Datagram Structure:
-----------------------
Pseudo-Header
-------------
In IPv6, the checksum is mandatory.
For checksum calculating purposes, the pseudo-header is the following:
| Source Addr (128b) | Dest Addr (128b) | UDP Length (32b) | 0x000000 (24b) | Next Header = Protocol (8b) |
The value of the Next Header field is always 17 (UDP protocol number)