From 3bff2f8dc289d0c9cc2747cd147c8b57cd16d57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Sun, 1 Oct 2023 12:50:26 +0200 Subject: [PATCH] Update Ipaddr_Cstruct.V6 with S128 changes Instead of going roundabout through integers we use strings directly. --- lib/ipaddr_cstruct.ml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/ipaddr_cstruct.ml b/lib/ipaddr_cstruct.ml index 8ba86c6..7444626 100644 --- a/lib/ipaddr_cstruct.ml +++ b/lib/ipaddr_cstruct.ml @@ -47,22 +47,14 @@ module V6 = struct let of_cstruct_exn cs = let len = Cstruct.length cs in if len < 16 then raise (need_more (Cstruct.to_string cs)); - let hihi = Cstruct.BE.get_uint32 cs 0 in - let hilo = Cstruct.BE.get_uint32 cs 4 in - let lohi = Cstruct.BE.get_uint32 cs 8 in - let lolo = Cstruct.BE.get_uint32 cs 12 in - of_int32 (hihi, hilo, lohi, lolo) + of_octets_exn (Cstruct.to_string ~len:16 cs) let of_cstruct cs = try_with_result of_cstruct_exn cs let write_cstruct_exn i cs = let len = Cstruct.length cs in if len < 16 then raise (need_more (Cstruct.to_string cs)); - let a, b, c, d = to_int32 i in - Cstruct.BE.set_uint32 cs 0 a; - Cstruct.BE.set_uint32 cs 4 b; - Cstruct.BE.set_uint32 cs 8 c; - Cstruct.BE.set_uint32 cs 12 d + Cstruct.blit_from_string (to_octets i) 0 cs 0 16 let to_cstruct ?(allocator = Cstruct.create) i = let cs = allocator 16 in