Skip to content

Commit

Permalink
Merge pull request #7 from hannesm/next
Browse files Browse the repository at this point in the history
cstruct and rresult updates
  • Loading branch information
dinosaure authored Oct 21, 2021
2 parents c066a90 + 7b45a4c commit 5ce378b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v2.2.0 (2019-10-30)

* Adapt to mirage-net 3.0.0 and mirage-protocols 4.0.0 changes (#6 @hannesm)

### v2.1.0 (2019-07-15)

* Use ipaddr.4.0.0 interfaces (#5 @avsm)
Expand Down
11 changes: 3 additions & 8 deletions ethernet.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,22 @@ license: "ISC"
tags: ["org:mirage"]

build: [
["dune" "subst"] {pinned}
["dune" "subst"] {dev}
["dune" "build" "-p" name "-j" jobs]
]

depends: [
"dune"
"ocaml" {>= "4.06.0"}
"rresult" {>= "0.5.0"}
"cstruct" {>= "3.0.2"}
"ocaml" {>= "4.08.0"}
"cstruct" {>= "6.0.0"}
"ppx_cstruct"
"mirage-net" {>= "3.0.0"}
"mirage-protocols" {>= "4.0.0"}
"macaddr" {>= "4.0.0"}
"mirage-profile" {>= "0.5"}
"fmt"
"lwt" {>= "3.0.0"}
"logs" {>= "0.6.0"}
]
conflicts: [
"tcpip" {< "3.7.0"}
]
synopsis: "OCaml Ethernet (IEEE 802.3) layer, used in MirageOS"
description: """
`ethernet` provides an [Ethernet](https://en.wikipedia.org/wiki/Ethernet)
Expand Down
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name ethernet)
(public_name ethernet)
(libraries cstruct macaddr mirage-net mirage-protocols rresult logs mirage-profile)
(libraries cstruct macaddr mirage-net mirage-protocols logs lwt mirage-profile)
(preprocess (pps ppx_cstruct))
(wrapped false))
10 changes: 3 additions & 7 deletions src/ethernet_packet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Unmarshal = struct

let of_cstruct frame =
let open Ethernet_wire in
if Cstruct.len frame >= sizeof_ethernet then
if Cstruct.length frame >= sizeof_ethernet then
match get_ethernet_ethertype frame |> int_to_ethertype with
| None -> Error (Printf.sprintf "unknown ethertype 0x%x in frame"
(get_ethernet_ethertype frame))
Expand All @@ -34,10 +34,8 @@ module Unmarshal = struct
end

module Marshal = struct
open Rresult

let check_len buf =
if Ethernet_wire.sizeof_ethernet > Cstruct.len buf then
if Ethernet_wire.sizeof_ethernet > Cstruct.length buf then
Error "Not enough space for an Ethernet header"
else Ok ()

Expand All @@ -49,12 +47,10 @@ module Marshal = struct
()

let into_cstruct t buf =
check_len buf >>= fun () ->
Ok (unsafe_fill t buf)
Result.map (fun () -> unsafe_fill t buf) (check_len buf)

let make_cstruct t =
let buf = Cstruct.create Ethernet_wire.sizeof_ethernet in
Cstruct.memset buf 0x00; (* can be removed in the future *)
unsafe_fill t buf;
buf
end

0 comments on commit 5ce378b

Please sign in to comment.