Commits

jhwoodyatt  committed 9095881

Make the network subnet manipulation functions cope with networks that are
not unicast networks. (Yes, there are multicast ranges that can be treated
like subnets.)

  • Participants
  • Parent commits 15add66

Comments (0)

Files changed (2)

File cf/cf_ip4_addr.ml

             Cf_seq.P (addr, iterator_ ~dir ~lim (network_next_ addr dir))
     end
 
-type network_t = {
+type 'a network_t = {
     net_prefix_: int;
-    net_minimum_: unicast t;
-    net_maximum_: unicast t;
-    net_member_: unicast t -> bool;
-}
+    net_minimum_: 'a t;
+    net_maximum_: 'a t;
+    net_member_: 'a t -> bool;
+} constraint 'a = [> opaque ]
 
 let net_create ?subnet:s n =
-    let n = (n :> unicast t) in
     let p = match s with Some p -> p | None -> network_min_prefix_ n in {
         net_prefix_ = p;
         net_minimum_ = network_limit_ n p (-1);
         net_maximum_ = network_limit_ n p 1;
-        net_member_ = network_member_ n p;
+        net_member_ = fun x -> network_member_ n p x;
     }
 
-let net_number { net_minimum_ = min } = (min :> unicast t)
-let net_broadcast { net_maximum_ = max } = (max :> unicast t)
-let net_prefix { net_prefix_ = prefix } = prefix
-let net_member { net_member_ = member } x = member (x :> unicast t)
-let net_mask { net_prefix_ = prefix } = network_netmask_ prefix
+let net_number net = net.net_minimum_
+let net_broadcast net = net.net_maximum_
+let net_prefix net = net.net_prefix_
+let net_member net = net.net_member_
+let net_mask net = network_netmask_ net.net_prefix_
 
 let net_increasing net =
     iterator_ ~dir:1 ~lim:net.net_maximum_ net.net_minimum_

File cf/cf_ip4_addr.mli

 val ntop: [> opaque ] t -> string
 
 (** The type of an IPv4 network identifier. *)
-type network_t
+type 'a network_t constraint 'a = [> opaque ]
 
 (** Use [net_create ?subnet a] to create an IPv4 network identifier that
     contains the address [a] in its logical scope, optional constraining the
     network to subnetwork of width [subnet].
 *)
-val net_create: ?subnet:int -> [> unicast ] t -> network_t
+val net_create: ?subnet:int -> ([> opaque ] as 'a) t -> 'a network_t
 
 (** Use [net_number n] to produce the IPv4 address conventionally used to
     identify the network.
 *)
-val net_number: network_t -> unicast t
+val net_number: 'a network_t -> 'a t
 
 (** Use [net_broadcast n] to produce the IPv4 address conventionally used to
     identify the broadcast address for the network or subnet.
 *)
-val net_broadcast: network_t -> unicast t
+val net_broadcast: 'a network_t -> 'a t
 
 (** Use [net_prefix] to obtain the number of bits in the subnet mask. *)
-val net_prefix: network_t -> int
+val net_prefix: 'a network_t -> int
 
 (** Use [net_member n a] to test whether the address [a] is in the scope of the
     network [n].
 *)
-val net_member: network_t -> [> unicast ] t -> bool
+val net_member: 'a network_t -> 'a t -> bool
 
 (** Use [net_mask n] to return a string representation of the subnet mask for
     the network [n] in traditional dot-quad format.
 *)
-val net_mask: network_t -> string
+val net_mask: 'a network_t -> string
 
 (** Use [net_increasing n] to obtain the sequence of unicast IPv4 addresses
     belong to the network [n] in increasing order.
 *)
-val net_increasing: network_t -> unicast t Cf_seq.t
+val net_increasing: 'a network_t -> 'a t Cf_seq.t
 
 (** Use [net_decreasing n] to obtain the sequence of unicast IPv4 addresses
     belong to the network [n] in decreasing order.
 *)
-val net_decreasing: network_t -> unicast t Cf_seq.t
+val net_decreasing: 'a network_t -> 'a t Cf_seq.t
 
 (*--- End of File [ cf_ip4_addr.mli ] ---*)