Hi all,
I’m starting playing with Cstruct, in particular I have to inspect a VxLAN Header, so I defined my struct like this:
[%%cstruct
type vxlan = {
flags: uint16_t;
group_policy_id: uint16_t;
vni: uint8_t [@len 3];
reserved: uint8_t;
} [@@big_endian]
]
And then I have:
let size_vxlan = 8
type t = {
flags : Cstruct.uint16;
group_policy_id : Cstruct.uint16;
vni : int;
reserved : Cstruct.uint8;
}
let of_cstruct pkt =
let open Vxlan_wire in
if Cstruct.len pkt < size_vxlan then
failwith "packet too short to contain a TCP packet of any size"
else
(
let policy_id = get_vxlan_group_policy_id pkt in
let flags = get_vxlan_flags pkt in
let vni = Vxlan_wire.get_vni pkt in
let res = get_vxlan_reserved pkt in
let data = Cstruct.shift pkt size_vxlan in
{flags = flags; group_policy_id = policy_id; vni = vni; reserved = res}
)
And in my code:
...
let vxlan_pkt = Vxlan_packet.of_cstruct pkt in
ignore @@ Core.printf "FLAGS %d POLICY ID %d VNI %d\n" vxlan_pkt.flags vxlan_pkt.group_policy_id vxlan_pkt.vni; Core.flush_all ();
...
on mac OS everything works ok, so I can ‘see’ in the header, but when I build under Ubuntu I got
Fatal error: exception Not_found
Raised at file "string.ml", line 118, characters 19-34
Called from file "sexp.ml", line 112, characters 13-47
At first received packet.
On macOS I have Ocaml 4.06.0, opam 1.2.2, cstruct 3.2.1, ppx_cstruct 3.2.1, same in Ubuntu
I think is a problem in my Ubuntu setup.
Any suggestion?
Thanks,
Gabriele