diff --git a/arp.rkt b/arp.rkt index f3071a7..a6ab180 100644 --- a/arp.rkt +++ b/arp.rkt @@ -109,9 +109,10 @@ (sender-protocol-address0 :: binary bytes plen) (target-hardware-address0 :: binary bytes hlen) (target-protocol-address0 :: binary bytes plen) - (:: binary) ;; TODO: are the extra zeros coming from the - ;; router real, or an artifact of my - ;; packet-capture implementation? + (:: binary) ;; The extra zeros exist because ethernet packets + ;; have a minimum size. This is, in part, why + ;; IPv4 headers have a total-length field, so + ;; that the zero padding can be removed. ] (let () (define sender-protocol-address (bit-string->bytes sender-protocol-address0)) diff --git a/ip.rkt b/ip.rkt index 2f7d999..452662a 100644 --- a/ip.rkt +++ b/ip.rkt @@ -247,14 +247,16 @@ (source-ip0 :: binary bits 32) (destination-ip0 :: binary bits 32) (rest :: binary) ] - (let ((source-ip (bit-string->bytes source-ip0)) - (destination-ip (bit-string->bytes destination-ip0)) - (options-length (* 4 (- header-length IP-MINIMUM-HEADER-LENGTH)))) + (let* ((source-ip (bit-string->bytes source-ip0)) + (destination-ip (bit-string->bytes destination-ip0)) + (options-length (* 4 (- header-length IP-MINIMUM-HEADER-LENGTH))) + (data-length (- total-length (* 4 header-length)))) (if (and (>= header-length 5) (>= (bit-string-byte-count body) (* header-length 4))) (bit-string-case rest ([ (opts :: binary bytes options-length) - (data :: binary) ] + (data :: binary bytes data-length) + (:: binary) ] ;; Very short ethernet packets have a trailer of zeros (ip-packet interface-name (bit-string->bytes source-ip) (bit-string->bytes destination-ip)