UDP 패킷 구조

UDP 는 header 와 data 로 구성되어 있다. 구성은 다음과 같다. 3번째 length는 header를 포함한 길이라고 한다.

그런데 checksum 계산을 할 때에는 앞에 덧붙는 값들이 있다. pseudo header 이다. udp에 해당하는 protocol 값은 17이다. udp length라는 항목이 새롭게 있는데 udp header의 length와 같은 값이다.

전체 구조는 다음과 같다.

다시 처음으로 돌아간다. RFC 0768에 checksum은 다음과 같이 정의한다.

Checksum is the 16-bit one's complement of the one's complement sum of a
pseudo header of information from the IP header, the UDP header, and the
data,  padded  with zero octets  at the end (if  necessary)  to  make  a
multiple of two octets.

일단 checksum을 구하기 위해서 pseudoheader를 포함한 전체 값이 있어야 한다. 초기 값에 대한 설명이 없는데, 0x0000으로 두고 계산한 다음 해당하는 위치에 그 값을 넣어준다고 한다.

마지막으로 checksum을 0x0000으로 하면 무시하도록 되어 있다.

If the computed  checksum  is zero,  it is transmitted  as all ones (the
equivalent  in one's complement  arithmetic).   An all zero  transmitted
checksum  value means that the transmitter  generated  no checksum  (for
debugging or for higher level protocols that don't care).