File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,21 @@ module Tcp = struct
202
202
let bits = Cstruct. shift bits sizeof_tcp in
203
203
Cstruct. blit pkt.payload 0 bits 0 (Cstruct. len pkt.payload)
204
204
205
+
206
+ let checksum (bits : Cstruct.t ) (src : nwAddr ) (dst : nwAddr ) (pkt : t ) =
207
+ (* XXX(seliopou): pseudo_header's allocated on every call. Would it be safe
208
+ * to allocate once and reuse? *)
209
+ let pseudo_header = Cstruct. create 12 in
210
+ Cstruct.BE. set_uint32 pseudo_header 0 src;
211
+ Cstruct.BE. set_uint32 pseudo_header 4 dst;
212
+ Cstruct. set_uint8 pseudo_header 8 0 ;
213
+ Cstruct. set_uint8 pseudo_header 9 0x6 ;
214
+ Cstruct.BE. set_uint16 pseudo_header 10 (len pkt);
215
+ set_tcp_chksum bits 0 ;
216
+ let chksum = Checksum. ones_complement_list
217
+ [pseudo_header; Cstruct. sub bits 0 (len pkt)] in
218
+ set_tcp_chksum bits chksum
219
+
205
220
end
206
221
207
222
module Udp = struct
@@ -883,7 +898,8 @@ module Ip = struct
883
898
let bits = Cstruct. shift bits header_len in
884
899
match pkt.tp with
885
900
| Tcp tcp ->
886
- Tcp. marshal bits tcp
901
+ Tcp. marshal bits tcp;
902
+ Tcp. checksum bits pkt.src pkt.dst tcp
887
903
| Udp udp ->
888
904
Udp. marshal bits udp
889
905
| Icmp icmp ->
You can’t perform that action at this time.
0 commit comments