1 ;;;; Lysiane Bouchard - Vincent St-Amour
5 ;;; - operations on the packet
7 ;; note : there is always only one packet in the system
9 ;; TODO should we keep the current packet's length somewhere ?
14 ;; TODO is there a better way ? what about a slip back-end ?
16 (define ethernet-header 0)
17 (define ethernet-destination-mac 0)
18 (define ethernet-source-mac 6)
19 (define ethernet-frame-type 12)
20 (define ethernet-data 14)
23 (define arp-header 14)
24 (define arp-hardware-type 14)
25 (define arp-protocol-type 16)
26 (define arp-hardware-address-length 18)
27 (define arp-protocol-address-length 19)
28 (define arp-operation 20)
29 (define arp-source-hardware-address 22) ;; TODO remove address from the name ?
30 (define arp-source-ip 28)
31 (define arp-target-hardware-address 32)
32 (define arp-target-ip 28)
33 (define arp-length 28)
37 (define ip-version-and-header-length 14)
38 (define ip-service 15)
40 (define ip-identification 18)
41 (define ip-fragment-offset 20)
42 (define ip-time-to-live 22)
43 (define ip-protocol 23) ;; TODO pretty ambiguous name
44 (define ip-checksum 24)
45 (define ip-source-ip 26)
46 (define ip-destination-ip 30)
47 (define ip-options 34) ; not supported as of now
48 (define ip-header-length 20)
51 (define icmp-header 34)
54 (define icmp-checksum 36)
55 (define icmp-options 38)
57 (define icmp-header-length 8) ;; TODO do the same for other protocols ?
60 (define tcp-header 34)
61 (define tcp-source-portnum 34)
62 (define tcp-destination-portnum 36)
63 (define tcp-seqnum 38) ; TODO change name ?
64 (define tcp-acknum 42) ; TODO change name ?
65 (define tcp-header-length-offset 46)
67 (define tcp-window 48)
68 (define tcp-checksum 50)
69 (define tcp-urgent-data-pointer 52)
70 (define tcp-options 54)
72 (define tcp-header-length 20)
76 (define udp-header 34)
77 (define udp-source-portnum 34)
78 (define udp-destination-portnum 36)
79 (define udp-length 38)
80 (define udp-checksum 40)
84 ;; sets vect as the current packet
85 (define (whole-pkt-set! vect)
86 (u8vector-copy! vect 0 pkt 0 (u8vector-length vect)))
89 ;; integer value of a 2 bytes packet subfield
90 ;; TODO why do we return an integer, why not a field ? might be more intuitive, but might be more costly
91 ;; TODO have u8vector-ref-2 instead, maybe not, since integer refs on vectors is used on portnums, but I don't see where else
92 ;; TODO say in the name it returns an int
94 (+ (* 256 (u8vector-ref pkt i)) (u8vector-ref pkt (+ i 1))))
96 ;; copies an integer into n contiguous bytes of the packet
97 ;; warning : picobit has 24-bit integers, keep this in mind when n > 3
98 ;; TODO get rid of integer->subfield ? maybe have only one of the 2 ?
99 (define (integer->pkt val idx n)
101 (begin (u8vector-set! pkt (- (+ idx n) 1) (modulo val 256))
102 (integer->pkt (quotient n 256) idx (- n 1)))))
103 ;; TODO better name, that mentions integer, and a !