From ae1fafd2d39b670407431a2cef7d6f9b3ee9a8e1 Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Wed, 4 Feb 2015 23:05:34 +0000 Subject: [PATCH] Expose universal IP adresse converters Should be merged with https://github.com/mirage/mirage/pull/361 --- lib/ipv4.ml | 5 +++++ lib/ipv6.ml | 7 +++++++ unix/ipv4_socket.ml | 4 ++++ unix/ipv6_socket.ml | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/lib/ipv4.ml b/lib/ipv4.ml index 3a9452c6c..7db21d4cc 100644 --- a/lib/ipv4.ml +++ b/lib/ipv4.ml @@ -230,4 +230,9 @@ module Make(Ethif : V1_LWT.ETHIF) = struct let get_source t ~dst:_ = t.ip + + type uipaddr = Ipaddr.t + let to_uipaddr ip = Ipaddr.V4 ip + let of_uipaddr = Ipaddr.to_v4 + end diff --git a/lib/ipv6.ml b/lib/ipv6.ml index 763edc44b..811341567 100644 --- a/lib/ipv6.ml +++ b/lib/ipv6.ml @@ -54,6 +54,8 @@ end module Ipv6_wire = Wire_structs.Ipv6_wire +module I = Ipaddr + (* This is temporary. See https://github.com/mirage/ocaml-ipaddr/pull/36 *) module Ipaddr = struct include Ipaddr.V6 @@ -950,4 +952,9 @@ module Make (E : V1_LWT.ETHIF) (T : V1_LWT.TIME) (C : V1.CLOCK) = struct let state = add_prefix ~now t.state pfx in t.state <- state; Lwt.return_unit + + type uipaddr = I.t + let to_uipaddr ip = I.V6 ip + let of_uipaddr ip = Some (I.to_v6 ip) + end diff --git a/unix/ipv4_socket.ml b/unix/ipv4_socket.ml index 27eb0ef5c..8e8318b8b 100644 --- a/unix/ipv4_socket.ml +++ b/unix/ipv4_socket.ml @@ -25,6 +25,10 @@ type prefix = Ipaddr.V4.t (* FIXME *) type ethif = unit type buffer = Cstruct.t type callback = src:ipaddr -> dst:ipaddr -> buffer -> unit io +type uipaddr = Ipaddr.t + +let to_uipaddr ip = Ipaddr.V4 ip +let of_uipaddr = Ipaddr.to_v4 let id _ = () let disconnect _ = return_unit diff --git a/unix/ipv6_socket.ml b/unix/ipv6_socket.ml index 5272f32df..cef8a0674 100644 --- a/unix/ipv6_socket.ml +++ b/unix/ipv6_socket.ml @@ -26,6 +26,10 @@ type ipaddr = Ipaddr.V6.t type ethif = unit type buffer = Cstruct.t type callback = src:ipaddr -> dst:ipaddr -> buffer -> unit io +type uipaddr = Ipaddr.t + +let to_uipaddr ip = Ipaddr.V6 ip +let of_uipaddr ip = Some (Ipaddr.to_v6 ip) let id _ = () let disconnect () = return_unit