Skip to content
Snippets Groups Projects
Commit 4eec0d35 authored by NGUYEN Do Duc Anh's avatar NGUYEN Do Duc Anh
Browse files

fix sending incorrect packet

parent 76411965
No related branches found
No related tags found
No related merge requests found
......@@ -270,19 +270,18 @@ module Main
let custom_opt = Custom_option.init in
Custom_option.add_entry custom_opt (Int32.of_int 0) 255 0;
let custom_opt_cs = Custom_option.of_cstruct custom_opt in
let len_option_cs = Cstruct.length custom_opt_cs in
let len_payload = Cstruct.length payload in
match Cstruct.length options with
| 0 -> (
let new_ipv4_hdr = {ipv4_hdr with options= custom_opt_cs} in
let len_new_ipv4_hdr = 20 + len_option_cs in
let new_packet = Ipv4_packet.Marshal.make_cstruct ~payload_len:len_new_ipv4_hdr new_ipv4_hdr in
let new_ipv4_hdr_cs = Ipv4_packet.Marshal.make_cstruct ~payload_len:len_payload new_ipv4_hdr in
let new_packet = Cstruct.append new_ipv4_hdr_cs payload in
output_ether_private4 header.Ethernet.Packet.source header.Ethernet.Packet.destination new_packet)
| _ -> (
let len_old_option_cs = Cstruct.length ipv4_hdr.options in
let len_new_ipv4_hdr = 20 + len_option_cs +len_old_option_cs in
let new_ipv4_hdr = {ipv4_hdr with options= Cstruct.append ipv4_hdr.options (Custom_option.of_cstruct custom_opt)} in
let new_packet = Ipv4_packet.Marshal.make_cstruct ~payload_len:len_new_ipv4_hdr new_ipv4_hdr in
let new_ipv4_hdr_cs = Ipv4_packet.Marshal.make_cstruct ~payload_len:len_payload new_ipv4_hdr in
let new_packet = Cstruct.append new_ipv4_hdr_cs payload in
output_ether_private4 header.Ethernet.Packet.source header.Ethernet.Packet.destination new_packet)
in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment