Ocaml-cstruct Fatal error: exception Not_found on Ubuntu 16.04 - Ocaml 4.06.0

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

A couple thoughts from someone that knows very little about Cstruct itself:

  • from the trace, the error seems to come from Sexplib
  • I don’t know if Sexplib is used by Cstruct internally, but that sounds unlikely to me, so I would try to see if there isn’t a problem with another part of the application (one that is related to serializing/deserializing data) rather than your use of Cstruct.
  • having a more complete trace would be helpful to know where the error is coming from, which could be achieved by adding the debug flag to your build (the -g flag for compilation and linking, which can be set in various ways depending on your build system)

Hi gasche,

Thank you for your analysis.

That was all the trace I got, but then I solved, the problem was that I used a List.find … without a try … with, inside an Uwt callback so for some reason the trace was putting me in the wrong direction.
Now that I use Lwt and used a try … with the problem was solved.

Thanks,
Gabriele