UDP and Ports
UDP and Ports¶
Overview¶
This document covers UDP (User Datagram Protocol) and the concept of port numbers. You will understand UDP's characteristics in contrast to TCP and learn how ports are used in the transport layer.
Difficulty: ββ Estimated Learning Time: 2 hours Prerequisites: 10_TCP_Protocol.md
Table of Contents¶
- UDP Characteristics
- UDP Header Structure
- TCP vs UDP Comparison
- Port Number Concept
- Port Number Ranges
- Sockets
- Practice Problems
- Next Steps
- References
1. UDP Characteristics¶
1.1 UDP Basics¶
UDP (User Datagram Protocol) is a connectionless protocol for simple and fast transmission.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β UDP Characteristics β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. Connectionless β
β - No connection setup/teardown β
β - Sends data immediately without handshake β
β β
β 2. Unreliable β
β - No delivery guarantee β
β - No ordering guarantee β
β - No retransmission β
β β
β 3. Fast Transmission β
β - Minimal overhead β
β - No connection setup delay β
β β
β 4. Simple β
β - Small header (8 bytes) β
β - No state maintenance required β
β β
β 5. Broadcast/Multicast Support β
β - Can send to multiple recipients simultaneously β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1.2 UDP Operation¶
UDP Data Transmission
βββββββββββββββββββ βββββββββββββββββββ
β Sender β β Receiver β
β β β β
β Application β β Application β
β β β β β² β
β βΌ β β β β
β βββββββββββββ β β βββββββββββββ β
β β UDP β β Datagram 1 β β UDP β β
β β ββββΌβββββββββββββββββββββΌββΊβ β β
β β No state β β Datagram 2 β β No state β β
β β No ACK ββββΌβββββββββββββββββββββΌββΊβ No ACK β β
β β β β Datagram 3 β β β β
β β ββββΌβββββββββX (lost) β β β β
β βββββββββββββ β β βββββββββββββ β
β β β β
βββββββββββββββββββ βββββββββββββββββββ
Characteristics:
- Each datagram is independent
- No retransmission if lost
- Application handles reliability
1.3 UDP Use Cases¶
When UDP is Appropriate:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. Real-time Streaming β
β - Video, voice calls (VoIP) β
β - Delay is more problematic than some packet loss β
β β
β 2. Gaming β
β - Fast response is critical β
β - Old position data is meaningless β
β β
β 3. DNS Queries β
β - Single request/response β
β - Connection setup overhead unnecessary β
β β
β 4. DHCP β
β - Broadcast required β
β β
β 5. IoT / Sensor Data β
β - Large volume of small messages β
β - Some loss acceptable β
β β
β 6. SNMP (Network Management) β
β - Simple request/response β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1.4 UDP Advantages and Disadvantages¶
| Advantages | Disadvantages |
|---|---|
| Fast transmission speed | No delivery guarantee |
| Low overhead | No ordering guarantee |
| No connection setup needed | No congestion control |
| Multicast support | No flow control |
| Low server load | Security vulnerable (spoofing) |
2. UDP Header Structure¶
2.1 UDP Header Format¶
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Total Header Size: 8 bytes (64 bits)
2.2 Header Field Descriptions¶
| Field | Size | Description |
|---|---|---|
| Source Port | 16 bits | Sender port number (optional, can be 0) |
| Destination Port | 16 bits | Receiver port number |
| Length | 16 bits | Total length of UDP header + data (minimum 8) |
| Checksum | 16 bits | Error detection (optional in IPv4, mandatory in IPv6) |
2.3 UDP Checksum Calculation¶
UDP checksum is calculated including Pseudo Header
Pseudo Header (IPv4):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Source IP Address β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Destination IP Address β
ββββββββββββββββββ¬ββββββββββββββββββ¬βββββββββββββββββββββββββββββββ€
β Zero (8) β Protocol (17) β UDP Length β
ββββββββββββββββββ΄ββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
Checksum calculation range:
1. Pseudo Header
2. UDP Header
3. UDP Data
Purpose:
- Verify IP header address information hasn't been modified
- Data integrity verification
2.4 UDP vs TCP Header Comparison¶
TCP Header (20-60 bytes):
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Src PortβDst Portβ Seq Number β Ack Number βOffsetβFlags β
β Window βChecksumβUrgent Pointerβ Options β β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
UDP Header (8 bytes):
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Src PortβDst Portβ Length β Checksum β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Differences:
- TCP: Includes sequence number, ACK, flags, window, options, etc.
- UDP: Contains only minimal information (port, length, checksum)
3. TCP vs UDP Comparison¶
3.1 Detailed Comparison Table¶
| Characteristic | TCP | UDP |
|---|---|---|
| Connection Type | Connection-oriented (3-way handshake) | Connectionless |
| Reliability | Reliable (retransmission) | Unreliable (Best Effort) |
| Ordering | Ordering guaranteed (sequence number) | No ordering |
| Flow Control | Sliding window | None |
| Congestion Control | Slow Start, AIMD, etc. | None |
| Header Size | 20-60 bytes | 8 bytes |
| Transmission Unit | Segment | Datagram |
| Communication Pattern | 1:1 | 1:1, 1:N, N:N |
| Speed | Relatively slow | Fast |
| Overhead | High | Low |
3.2 Usage Scenario Comparison¶
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Protocol Selection Criteria β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Choose TCP: β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Data integrity is critical (file transfer, email) β β
β β β’ Ordering is important (web pages, databases) β β
β β β’ Connection state management needed β β
β β β’ Retransmission is essential β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Choose UDP: β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Real-time performance is critical (streaming, gaming) β β
β β β’ Some loss is acceptable β β
β β β’ Simple request/response (DNS) β β
β β β’ Broadcast/multicast required β β
β β β’ Custom reliability mechanism implemented β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
3.3 Main Usage Examples by Protocol¶
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TCP Usage β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ€
β HTTP/HTTPS (80/443) β Web browsing β
β FTP (20/21) β File transfer β
β SMTP (25) β Email sending β
β POP3 (110) / IMAP (143) β Email receiving β
β SSH (22) β Secure remote access β
β Telnet (23) β Remote access β
β MySQL (3306) β Database β
β PostgreSQL (5432) β Database β
βββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β UDP Usage β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ€
β DNS (53) β Domain lookup β
β DHCP (67/68) β IP automatic assignment β
β SNMP (161/162) β Network management β
β NTP (123) β Time synchronization β
β TFTP (69) β Simple file transfer β
β RTP β Real-time media streaming β
β VoIP (SIP) β Internet telephony β
β Online Gaming β Real-time game data β
βββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββ
3.4 Hybrid Approach¶
Using TCP and UDP Together:
1. Gaming
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TCP: Login, chat, inventory (reliability needed) β
β UDP: Character movement, real-time combat (speed needed) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
2. Streaming
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TCP: Control channel (play/pause/volume) β
β UDP: Media data transmission (RTP) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
3. QUIC (HTTP/3)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Reliability layer implemented on top of UDP β
β Advantages: Fast connection, solves HOL Blocking β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
4. Port Number Concept¶
4.1 Role of Ports¶
A port is a number that identifies a process running within a host.
Role of Ports
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Host β
β 192.168.1.100 β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β β
β β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β β
β β β Web β β SSH β β FTP β β MySQL β β β
β β β Server β β Server β β Server β β Server β β β
β β β β β β β β β β β β
β β ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ β β
β β β β β β β β
β β Port 80 Port 22 Port 21 Port 3306 β β
β β β β β β β β
β β ββββββββββββββ΄βββββββββββββ΄βββββββββββββ β β
β β β β β
β β ββββββββββββ΄βββββββββββ β β
β β β TCP/IP Stack β β β
β β ββββββββββββ¬βββββββββββ β β
β β β β β
β βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ β
β β β
β Network Interface β
β 192.168.1.100 β
βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β
Network
Checks destination port of each packet and forwards to corresponding process
4.2 Socket Address¶
In network communication, an endpoint is identified by a combination of IP address and port.
Socket Address
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β Socket Address = IP Address + Port Number β
β β
β Examples: β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β 192.168.1.100:80 (Web server) β β
β β 10.0.0.5:443 (HTTPS server) β β
β β 192.168.1.50:50000 (Client ephemeral port) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Unique identification of TCP connection: β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β (Source IP, Source Port, Dest IP, Dest Port, Protocol) β β
β β = 5-tuple β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
4.3 Port Number Notation¶
IPv4:
IP:Port format
Example: 192.168.1.100:80
IPv6:
[IP]:Port format (wrap IP address in brackets)
Example: [2001:db8::1]:80
[::1]:8080
In URLs:
http://example.com:8080/path
https://[2001:db8::1]:443/
5. Port Number Ranges¶
5.1 Port Range Classification¶
Port Number Range (0 - 65535)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Well-known Ports β β
β β 0 - 1023 β β
β β β’ System services and standard protocols β β
β β β’ Requires root/admin privileges β β
β β β’ Managed by IANA β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Registered Ports β β
β β 1024 - 49151 β β
β β β’ For specific applications/services β β
β β β’ Registered with IANA (not mandatory) β β
β β β’ Can be used by regular users β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Dynamic/Private Ports β β
β β 49152 - 65535 β β
β β β’ Ephemeral ports β β
β β β’ Automatically assigned for client connections β β
β β β’ Cannot be registered β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
5.2 Major Well-known Ports¶
| Port | Protocol | Service | Description |
|---|---|---|---|
| 20 | TCP | FTP-Data | FTP data transfer |
| 21 | TCP | FTP-Control | FTP control |
| 22 | TCP | SSH | Secure shell |
| 23 | TCP | Telnet | Remote access (unencrypted) |
| 25 | TCP | SMTP | Email sending |
| 53 | TCP/UDP | DNS | Domain Name Service |
| 67 | UDP | DHCP Server | IP automatic assignment (server) |
| 68 | UDP | DHCP Client | IP automatic assignment (client) |
| 69 | UDP | TFTP | Trivial file transfer |
| 80 | TCP | HTTP | Web (unencrypted) |
| 110 | TCP | POP3 | Email receiving |
| 123 | UDP | NTP | Time synchronization |
| 143 | TCP | IMAP | Email receiving |
| 161 | UDP | SNMP | Network management |
| 443 | TCP | HTTPS | Web (encrypted) |
| 445 | TCP | SMB | File sharing (Windows) |
| 465 | TCP | SMTPS | SMTP over SSL |
| 514 | UDP | Syslog | System logging |
| 993 | TCP | IMAPS | IMAP over SSL |
| 995 | TCP | POP3S | POP3 over SSL |
5.3 Major Registered Ports¶
| Port | Protocol | Service | Description |
|---|---|---|---|
| 1433 | TCP | MSSQL | Microsoft SQL Server |
| 1521 | TCP | Oracle | Oracle Database |
| 3306 | TCP | MySQL | MySQL Database |
| 3389 | TCP | RDP | Remote Desktop |
| 5432 | TCP | PostgreSQL | PostgreSQL Database |
| 5900 | TCP | VNC | Remote desktop |
| 6379 | TCP | Redis | Redis cache |
| 8080 | TCP | HTTP-Alt | Alternative HTTP port |
| 8443 | TCP | HTTPS-Alt | Alternative HTTPS port |
| 9000 | TCP | Various | PHP-FPM, etc. |
| 27017 | TCP | MongoDB | MongoDB Database |
5.4 Ephemeral Ports¶
Ephemeral port assignment during client connection
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β Client Server β
β (192.168.1.10) (10.0.0.5) β
β β
β βββββββββββββββ βββββββββββββββ β
β β Web Browser β β Web Server β β
β β Port: ? βββββββββββββββββββΊβ Port: 80 β β
β βββββββββββββββ βββββββββββββββ β
β β
β OS automatically assigns ephemeral port: β
β Example: 192.168.1.10:52431 β 10.0.0.5:80 β
β β
β Ephemeral port range by OS: β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Linux: 32768 - 60999 (net.ipv4.ip_local_port_range) β β
β β Windows: 49152 - 65535 β β
β β macOS: 49152 - 65535 β β
β β BSD: 1024 - 5000 (older versions) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
6. Sockets¶
6.1 Socket Concept¶
A socket is an abstraction of the endpoint for network communication.
Socket Communication Model
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β Application Application β
β β β β
β ββββββ΄βββββ ββββββ΄βββββ β
β β Socket β β Socket β β
β β API β β API β β
β ββββββ¬βββββ ββββββ¬βββββ β
β β β β
β ββββββ΄βββββ ββββββ΄βββββ β
β β Socket ββββββββββββββββββββββββββββ Socket β β
β β192.168. β TCP/UDP Connection β10.0.0.5 β β
β β1.10:5000β β:80 β β
β βββββββββββ βββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Socket = (Protocol, IP Address, Port Number)
6.2 Socket Types¶
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Socket Types β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β SOCK_STREAM (Stream Socket) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Uses TCP β β
β β β’ Connection-oriented β β
β β β’ Reliable bidirectional byte stream β β
β β β’ Ordering guaranteed β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β SOCK_DGRAM (Datagram Socket) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Uses UDP β β
β β β’ Connectionless β β
β β β’ Fixed-size messages β β
β β β’ No ordering/delivery guarantee β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β SOCK_RAW (Raw Socket) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Direct IP layer access β β
β β β’ Custom protocol implementation β β
β β β’ Requires root privileges β β
β β β’ Used for ping, traceroute, etc. β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
6.3 TCP Socket Programming Flow¶
TCP Server/Client Flow
Server Client
β β
socket() socket()
β β
bind() β
β β
listen() β
β β
accept() ββββββββ connect() ββββββββββββββ€
β (3-way handshake) β
β β
read() βββββββββ write() βββββββββββββββ€
β β
write() βββββββββΊ read() β
β β
close() βββββββββ close() βββββββββββββββ€
(4-way handshake)
Python Example (Server):
import socket
# Create socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind address
server.bind(('0.0.0.0', 8080))
# Listen for connections
server.listen(5)
# Accept client connection
client, addr = server.accept()
print(f"Connected: {addr}")
# Send/receive data
data = client.recv(1024)
client.send(b"Hello, Client!")
# Close connection
client.close()
server.close()
6.4 UDP Socket Programming Flow¶
UDP Server/Client Flow
Server Client
β β
socket() socket()
β β
bind() β
β β
recvfrom() βββββββ sendto() βββββββββββββββ€
β β
sendto() ββββββββββΊ recvfrom() β
β β
close() close()
Characteristics:
- No connect() needed (connectionless)
- Each message includes destination address
import socket
# UDP Server
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind(('0.0.0.0', 9999))
data, addr = server.recvfrom(1024)
print(f"From {addr}: {data}")
server.sendto(b"ACK", addr)
6.5 Checking Socket State¶
# Linux - Check socket state
ss -tuln # TCP/UDP listening sockets
ss -tan # All TCP connections
ss -tan state established # Established TCP only
# netstat (older version)
netstat -an | grep LISTEN
netstat -tunlp
# macOS
netstat -an | grep LISTEN
lsof -i -P | grep LISTEN
# Windows
netstat -an | findstr LISTEN
netstat -ano
7. Practice Problems¶
Problem 1: TCP vs UDP Selection¶
Choose the appropriate protocol for the following scenarios.
a) Banking transaction system b) Live streaming broadcast c) Email transmission d) Multiplayer game character position synchronization e) Large file download f) IoT sensor data collection (every second)
Problem 2: Port Number Matching¶
Match the following services with their default port numbers.
Service: Port:
a) HTTPS 1) 22
b) MySQL 2) 25
c) SMTP 3) 53
d) SSH 4) 443
e) DNS 5) 3306
Problem 3: UDP Header Analysis¶
Analyze the following UDP header (hexadecimal).
01 BB 00 35 00 1C 8A 7E
a) What is the Source Port? b) What is the Destination Port? (Which service?) c) What is the UDP Length? (Data size?) d) What is the Checksum?
Problem 4: Socket Identification¶
A server is handling the following requests simultaneously.
Client A: 192.168.1.10:50001 β Server: 10.0.0.5:80
Client B: 192.168.1.10:50002 β Server: 10.0.0.5:80
Client C: 192.168.1.20:50001 β Server: 10.0.0.5:80
a) How does the server distinguish these three connections? b) Express each connection using a 5-tuple.
Answers¶
Problem 1 Answers¶
a) Banking transaction β TCP (reliability required) b) Live streaming β UDP (real-time important, some loss acceptable) c) Email transmission β TCP (data integrity required) d) Game character position β UDP (real-time, only latest data meaningful) e) File download β TCP (complete data required) f) IoT sensor data β UDP (frequent small messages, some loss acceptable)
Problem 2 Answers¶
- a) HTTPS β 4) 443
- b) MySQL β 5) 3306
- c) SMTP β 2) 25
- d) SSH β 1) 22
- e) DNS β 3) 53
Problem 3 Answers¶
01 BB 00 35 00 1C 8A 7E
a) Source Port: 0x01BB = 443 (HTTPS)
b) Destination Port: 0x0035 = 53 (DNS)
c) UDP Length: 0x001C = 28 bytes
Data size: 28 - 8 = 20 bytes
d) Checksum: 0x8A7E
Problem 4 Answers¶
a) Server distinguishes each connection using 5-tuple: (Protocol, Src IP, Src Port, Dst IP, Dst Port)
b) 5-tuple representation: - Client A: (TCP, 192.168.1.10, 50001, 10.0.0.5, 80) - Client B: (TCP, 192.168.1.10, 50002, 10.0.0.5, 80) - Client C: (TCP, 192.168.1.20, 50001, 10.0.0.5, 80)
All three connections are uniquely identified because either Src IP or Src Port differs.
8. Next Steps¶
After understanding UDP and ports, learn about DNS.
Next Lesson¶
- 12_DNS.md - DNS operation principles, record types
Related Lessons¶
- 10_TCP_Protocol.md - TCP details
- 14_Other_Application_Protocols.md - DHCP, SNMP
Recommended Exercises¶
- Check open ports on your system using
ssornetstat - Capture and analyze UDP packets with Wireshark
- Implement a simple TCP/UDP echo server
9. References¶
RFC Documents¶
- RFC 768 - User Datagram Protocol
- RFC 793 - Transmission Control Protocol
- RFC 6335 - Internet Assigned Numbers Authority (IANA) Procedures
Command Reference¶
# Port checking (Linux)
ss -tuln # Listening ports
ss -tan state established # Established sockets
lsof -i :80 # Process using specific port
# Port checking (macOS)
netstat -an | grep LISTEN
lsof -iTCP -sTCP:LISTEN
# Port checking (Windows)
netstat -an | findstr LISTENING
netstat -ano | findstr :80
# Port scanning
nmap -p 1-1000 target_ip # TCP port scan
nmap -sU -p 53,67,123 target # UDP port scan
# UDP testing
nc -u target_ip 53 # UDP connection test
Learning Resources¶
- IANA Port Number Registry
- RFC 768 - UDP
- Unix Network Programming - W. Richard Stevens
Document Information - Last Modified: 2024 - Difficulty: ββ - Estimated Learning Time: 2 hours