Skip to content

Commit

Permalink
icmpv4_socket: correct the IPv4 total_length field
Browse files Browse the repository at this point in the history
On some OSes (particularly macOS) the IP header returned to userspace
has a bogus total length (e.g. 16384). This probably reflects an internal
kernel buffer size rather than the on-the-wire size of the original
packet.

This patch corrects the IPv4 header total length so that the IPv4 parser
can parse the result. Previously it would return an Error.

Signed-off-by: David Scott <[email protected]>
  • Loading branch information
djs55 committed Aug 8, 2017
1 parent e7fe08c commit e08cf5e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/stack-unix/icmpv4_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ let listen _t addr fn =
recvfrom' fd receive_buffer [] >>= fun (len, _sockaddr) ->
(* trim the buffer to the amount of data actually received *)
let receive_buffer = Cstruct.set_len receive_buffer len in
(* On macOS the IP length field is set to a very large value (16384) which
probably reflects some kernel datastructure size rather than the real
on-the-wire size. This confuses our IPv4 parser so we correct the size
here. *)
let len = Ipv4_wire.get_ipv4_len receive_buffer in
Ipv4_wire.set_ipv4_len receive_buffer (min len (Cstruct.len receive_buffer));
Lwt.async (fun () -> fn receive_buffer);
loop ()
in
Expand Down

0 comments on commit e08cf5e

Please sign in to comment.