Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
(public_name rawlink.lowlevel)
(modules rawlink_lowlevel)
(libraries cstruct unix)
(preprocess (pps ppx_cstruct))
(foreign_stubs (language c) (names rawlink_stubs)))

(library
Expand Down
22 changes: 14 additions & 8 deletions lib/rawlink_lowlevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@

(* This module is supposed to be used internally only *)

[%%cstruct
type bpf_hdr = {
bh_sec: uint32_t;
bh_usec: uint32_t;
bh_caplen: uint32_t;
bh_datalen: uint32_t;
bh_hdrlen: uint16_t;
} [@@host_endian]]
(* Hand picked from:
[%%cstruct
type bpf_hdr = {
bh_sec: uint32_t;
bh_usec: uint32_t;
bh_caplen: uint32_t;
bh_datalen: uint32_t;
bh_hdrlen: uint16_t;
} [@@host_endian]]
*)
let get_bpf_hdr_bh_caplen v = Cstruct.HE.get_uint32 v 8
let get_bpf_hdr_bh_datalen v = Cstruct.HE.get_uint32 v 12
let get_bpf_hdr_bh_hdrlen v = Cstruct.HE.get_uint16 v 16
(* omitted: all setters, get_bpf_hdr_bh_sec, get_bpf_hdr_bh_usec, hexdump_bpf_hdr_to_buffer *)

type driver =
| AF_PACKET
Expand Down
13 changes: 13 additions & 0 deletions lib/rawlink_lowlevel.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type driver = AF_PACKET | BPF
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to not expose driver in the mli, but then the compiler warns that the constructors are never used to build values (warn 37). They are built in the C stubs. I guess we can unexpose it and silence the warning in the .ml file.

external opensock :
?filter:string -> ?promisc:bool -> string -> Unix.file_descr
= "caml_rawlink_open"
external dhcp_server_filter : unit -> string = "caml_dhcp_server_filter"
external dhcp_client_filter : unit -> string = "caml_dhcp_client_filter"
external driver : unit -> driver = "caml_driver"
external unix_bytes_read :
Unix.file_descr -> Cstruct.buffer -> int -> int -> int
= "caml_unix_bytes_read"
external bpf_align : int -> int -> int = "caml_bpf_align"
val bpf_split_buffer : Cstruct.t -> int -> Cstruct.t list
Comment on lines +7 to +12
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove bpf_align and bpf_split_buffer, and maybe driver as well from the interface.

val process_input : Cstruct.t -> int -> Cstruct.t list
1 change: 0 additions & 1 deletion rawlink.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ depends: [
"ocaml" {>= "4.09.0"}
"dune" {>= "3.2"}
"cstruct" {>= "6.1.0"}
"ppx_cstruct"
]
depexts: [
["linux-headers"] {os-distribution = "alpine"}
Expand Down