UDP

December 17, 2025

RFC 793에서의 Socket

socket
          An address which specifically includes a port identifier, that
          is, the concatenation of an Internet Address with a TCP port.

출처: Transmission Control Protocl Glossary socket

Socket은 각 OS 커널에서 제공하는 프로그래밍 인터페이스라고 생각했는데, RFC에서는 Socket을 IP주소와 Port를 결합한 주소라고 정의하고 있습니다.

프로세스가 사용하는 Socket API와 단순히 식별자로서의 Socket의 개념이 혼용되고 있는 것 같습니다.

UDP에서는 Connection이라는 개념이 없기 때문에, Transport layer는 (Destination IP, Destination Port)만 보고 Demultiplexing합니다. TCP에서 (Source IP, Source Port, Destination IP, Destination Port)로 Demultiplexing 하는 것과는 대조적입니다.

UDP Packet capture

Wireshark를 켜고 UDP로 필터링해서 아무 DNS 패킷이나 잡아봅니다.

No. Time Source Destination Protocol Length Info
28 2.459806 172.30.1.12 168.126.63.1 DNS 73 Standard query 0x2f33 HTTPS fp.msedge.net
30 2.489239 168.126.63.1 172.30.1.12 DNS 281 Standard query response 0x2f33 HTTPS fp.msedge.net CNAME 1.perf.msedge.net CNAME a-0019.a-msedge.net CNAME a-0019.a.dns.azurefd.net CNAME a-0019.standard.a-msedge.net SOA ns1.a-msedge.net
  1. Select the first UDP segment in your trace.

    • What is the packet number of this segment in the trace file?

      첫 번째 UDP Segment의 packet number는 28입니다.

    • What type of application-layer payload or protocol message is being carried in this UDP segment? Look at the details of this packet in Wireshark.

      UDP Payload는 DNS query입니다.

    User Datagram Protocol, Src Port: 56856, Dst Port: 53
    Source Port: 56856
    Destination Port: 53
    Length: 39
    Checksum: 0x94e2 [unverified]
    [Checksum Status: Unverified]
    [Stream index: 6]
    [Stream Packet Number: 1]
    [Timestamps]
    UDP payload (31 bytes)
    • How many fields there are in the UDP header? (You shouldn’t look in the textbook! Answer these questions directly from what you observe in the packet trace.)

    • What are the names of these fields?

      Header에 포함된 데이터는, Source Port, Destination Port, Length, Checksum 총 4개입니다.

  2. By consulting the displayed information in Wireshark’s packet content field for this packet (or by consulting the textbook), what is the length (in bytes) of each of the UDP header fields?

    각각 2바이트 씩 4개의 필드라서 총 8바이트 입니다.

  3. The value in the Length field is the length of what? (You can consult the text for this answer). Verify your claim with your captured UDP packet.

    0000   60 29 d5 41 ac 08 8c b8 7e db 15 05 08 00 45 00   `).A....~.....E.
    0010   00 3b 5c 18 00 00 80 11 00 00 ac 1e 01 0c a8 7e   .;\............~
    0020   3f 01 de 18 00 35 00 27 94 e2 2f 33 01 00 00 01   ?....5.'../3....
    0030   00 00 00 00 00 00 02 66 70 06 6d 73 65 64 67 65   .......fp.msedge
    0040   03 6e 65 74 00 00 41 00 01                        .net..A..

    Length field는 0x0026부터 2바이트로, 값은 0x0027입니다. 39 바이트입니다.

  4. What is the maximum number of bytes that can be included in a UDP payload? (Hint: the answer to this question can be determined by your answer to 2. above)

    Length field가 2 바이트이므로, 21612^{16} - 1이 최대 Length라고 추측할 수 있습니다. 그런데, Header가 8바이트이므로 UDP Payload는 655358=6552765535 - 8 = 65527바이트 입니다.

    그런데 IP의 Length 필드 제한도 2바이트라서 21612^{16} - 1크기가 최대입니다. 따라서 UDP Payload가 65527바이트더라도 IP Datagram에 들어가려면 IP 헤더 20바이트가 더 필요하므로 이론적인 제한은 65507바이트라고 생각할 수 있습니다. 출처

    추가적으로, 위 위키백과 문장을 읽고 상위 프로토콜의 현실적인 제한도 따질거라면 Ethernet에서 MTU까지 따져서 1500 바이트라고 해야한다고 생각했습니다. 그런데, IP의 제약은 프로토콜의 정의상 Datagram이 21612^{16} - 1바이트를 넘을 수 없는 것이고, Ethernet에는 Length와 같은 필드가 없어서 프로토콜적인 제약은 아니라는 것을 알았습니다. MTU는 실제로 보낼때 쪼개는 단위인 것 같습니다.

  5. What is the largest possible source port number? (Hint: see the hint in 4.)

    2바이트로 표현 가능해야 하므로 21612^{16} - 1입니다.

  6. What is the protocol number for UDP? Give your answer in decimal notation. To answer this question, you’ll need to look into the Protocol field of the IP datagram containing this UDP segment (see Figure 4.13 in the text, and the discussion of IP header fields).

    IP Header에서 Protocol field가 17로 나와있습니다.

  7. Examine the pair of UDP packets in which your host sends the first UDP packet and the second UDP packet is a reply to this first UDP packet. (Hint: for a second packet to be sent in response to a first packet, the sender of the first packet should be the destination of the second packet).

    • What is the packet number of the first of these two UDP segments in the trace file?

      28번 입니다.

    • What is the value in the source port field in this UDP segment?

      28번의 source port는 56856입니다.

    • What is the value in the destination port field in this UDP segment?

      28번의 destination port는 53입니다.

    • What is the packet number of the second of these two UDP segments in the trace file?

      30번입니다.

    • What is the value in the source port field in this second UDP segment?

      30번의 source port는 53입니다. 53은 DNS well known port입니다.

    • What is the value in the destination port field in this second UDP segment?

      30번의 destination port는 56856입니다.

    • Describe the relationship between the port numbers in the two packets.

      첫 패킷의 Source와 Destination Port가 서로 바뀌어 있습니다.