{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
module Data.IP.Range where
import Control.Monad
import Data.Bits
import Data.Data (Data)
import Data.IP.Addr
import Data.IP.Mask
import Data.String
import Data.Typeable (Typeable)
import Text.Appar.String
import GHC.Generics
data IPRange = IPv4Range { IPRange -> AddrRange IPv4
ipv4range :: AddrRange IPv4 }
| IPv6Range { IPRange -> AddrRange IPv6
ipv6range :: AddrRange IPv6 }
deriving (IPRange -> IPRange -> Bool
(IPRange -> IPRange -> Bool)
-> (IPRange -> IPRange -> Bool) -> Eq IPRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IPRange -> IPRange -> Bool
$c/= :: IPRange -> IPRange -> Bool
== :: IPRange -> IPRange -> Bool
$c== :: IPRange -> IPRange -> Bool
Eq, Eq IPRange
Eq IPRange
-> (IPRange -> IPRange -> Ordering)
-> (IPRange -> IPRange -> Bool)
-> (IPRange -> IPRange -> Bool)
-> (IPRange -> IPRange -> Bool)
-> (IPRange -> IPRange -> Bool)
-> (IPRange -> IPRange -> IPRange)
-> (IPRange -> IPRange -> IPRange)
-> Ord IPRange
IPRange -> IPRange -> Bool
IPRange -> IPRange -> Ordering
IPRange -> IPRange -> IPRange
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IPRange -> IPRange -> IPRange
$cmin :: IPRange -> IPRange -> IPRange
max :: IPRange -> IPRange -> IPRange
$cmax :: IPRange -> IPRange -> IPRange
>= :: IPRange -> IPRange -> Bool
$c>= :: IPRange -> IPRange -> Bool
> :: IPRange -> IPRange -> Bool
$c> :: IPRange -> IPRange -> Bool
<= :: IPRange -> IPRange -> Bool
$c<= :: IPRange -> IPRange -> Bool
< :: IPRange -> IPRange -> Bool
$c< :: IPRange -> IPRange -> Bool
compare :: IPRange -> IPRange -> Ordering
$ccompare :: IPRange -> IPRange -> Ordering
$cp1Ord :: Eq IPRange
Ord, Typeable IPRange
DataType
Constr
Typeable IPRange
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IPRange -> c IPRange)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IPRange)
-> (IPRange -> Constr)
-> (IPRange -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IPRange))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPRange))
-> ((forall b. Data b => b -> b) -> IPRange -> IPRange)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r)
-> (forall u. (forall d. Data d => d -> u) -> IPRange -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> IPRange -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange)
-> Data IPRange
IPRange -> DataType
IPRange -> Constr
(forall b. Data b => b -> b) -> IPRange -> IPRange
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IPRange -> c IPRange
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IPRange
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> IPRange -> u
forall u. (forall d. Data d => d -> u) -> IPRange -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IPRange
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IPRange -> c IPRange
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IPRange)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPRange)
$cIPv6Range :: Constr
$cIPv4Range :: Constr
$tIPRange :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> IPRange -> m IPRange
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange
gmapMp :: (forall d. Data d => d -> m d) -> IPRange -> m IPRange
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange
gmapM :: (forall d. Data d => d -> m d) -> IPRange -> m IPRange
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IPRange -> m IPRange
gmapQi :: Int -> (forall d. Data d => d -> u) -> IPRange -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IPRange -> u
gmapQ :: (forall d. Data d => d -> u) -> IPRange -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IPRange -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IPRange -> r
gmapT :: (forall b. Data b => b -> b) -> IPRange -> IPRange
$cgmapT :: (forall b. Data b => b -> b) -> IPRange -> IPRange
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPRange)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPRange)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c IPRange)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IPRange)
dataTypeOf :: IPRange -> DataType
$cdataTypeOf :: IPRange -> DataType
toConstr :: IPRange -> Constr
$ctoConstr :: IPRange -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IPRange
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IPRange
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IPRange -> c IPRange
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IPRange -> c IPRange
$cp1Data :: Typeable IPRange
Data, (forall x. IPRange -> Rep IPRange x)
-> (forall x. Rep IPRange x -> IPRange) -> Generic IPRange
forall x. Rep IPRange x -> IPRange
forall x. IPRange -> Rep IPRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IPRange x -> IPRange
$cfrom :: forall x. IPRange -> Rep IPRange x
Generic, Typeable)
data AddrRange a = AddrRange {
AddrRange a -> a
addr :: !a
, AddrRange a -> a
mask :: !a
, AddrRange a -> Int
mlen :: {-# UNPACK #-} !Int
}
deriving (AddrRange a -> AddrRange a -> Bool
(AddrRange a -> AddrRange a -> Bool)
-> (AddrRange a -> AddrRange a -> Bool) -> Eq (AddrRange a)
forall a. Eq a => AddrRange a -> AddrRange a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddrRange a -> AddrRange a -> Bool
$c/= :: forall a. Eq a => AddrRange a -> AddrRange a -> Bool
== :: AddrRange a -> AddrRange a -> Bool
$c== :: forall a. Eq a => AddrRange a -> AddrRange a -> Bool
Eq, Eq (AddrRange a)
Eq (AddrRange a)
-> (AddrRange a -> AddrRange a -> Ordering)
-> (AddrRange a -> AddrRange a -> Bool)
-> (AddrRange a -> AddrRange a -> Bool)
-> (AddrRange a -> AddrRange a -> Bool)
-> (AddrRange a -> AddrRange a -> Bool)
-> (AddrRange a -> AddrRange a -> AddrRange a)
-> (AddrRange a -> AddrRange a -> AddrRange a)
-> Ord (AddrRange a)
AddrRange a -> AddrRange a -> Bool
AddrRange a -> AddrRange a -> Ordering
AddrRange a -> AddrRange a -> AddrRange a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (AddrRange a)
forall a. Ord a => AddrRange a -> AddrRange a -> Bool
forall a. Ord a => AddrRange a -> AddrRange a -> Ordering
forall a. Ord a => AddrRange a -> AddrRange a -> AddrRange a
min :: AddrRange a -> AddrRange a -> AddrRange a
$cmin :: forall a. Ord a => AddrRange a -> AddrRange a -> AddrRange a
max :: AddrRange a -> AddrRange a -> AddrRange a
$cmax :: forall a. Ord a => AddrRange a -> AddrRange a -> AddrRange a
>= :: AddrRange a -> AddrRange a -> Bool
$c>= :: forall a. Ord a => AddrRange a -> AddrRange a -> Bool
> :: AddrRange a -> AddrRange a -> Bool
$c> :: forall a. Ord a => AddrRange a -> AddrRange a -> Bool
<= :: AddrRange a -> AddrRange a -> Bool
$c<= :: forall a. Ord a => AddrRange a -> AddrRange a -> Bool
< :: AddrRange a -> AddrRange a -> Bool
$c< :: forall a. Ord a => AddrRange a -> AddrRange a -> Bool
compare :: AddrRange a -> AddrRange a -> Ordering
$ccompare :: forall a. Ord a => AddrRange a -> AddrRange a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (AddrRange a)
Ord, Typeable (AddrRange a)
DataType
Constr
Typeable (AddrRange a)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AddrRange a))
-> (AddrRange a -> Constr)
-> (AddrRange a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (AddrRange a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AddrRange a)))
-> ((forall b. Data b => b -> b) -> AddrRange a -> AddrRange a)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r)
-> (forall u. (forall d. Data d => d -> u) -> AddrRange a -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> AddrRange a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a))
-> Data (AddrRange a)
AddrRange a -> DataType
AddrRange a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (AddrRange a))
(forall b. Data b => b -> b) -> AddrRange a -> AddrRange a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AddrRange a)
forall a. Data a => Typeable (AddrRange a)
forall a. Data a => AddrRange a -> DataType
forall a. Data a => AddrRange a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> AddrRange a -> AddrRange a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> AddrRange a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> AddrRange a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AddrRange a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (AddrRange a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AddrRange a))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> AddrRange a -> u
forall u. (forall d. Data d => d -> u) -> AddrRange a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AddrRange a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (AddrRange a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AddrRange a))
$cAddrRange :: Constr
$tAddrRange :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
gmapMp :: (forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
gmapM :: (forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> AddrRange a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> AddrRange a -> u
gmapQ :: (forall d. Data d => d -> u) -> AddrRange a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> AddrRange a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AddrRange a -> r
gmapT :: (forall b. Data b => b -> b) -> AddrRange a -> AddrRange a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> AddrRange a -> AddrRange a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AddrRange a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (AddrRange a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (AddrRange a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (AddrRange a))
dataTypeOf :: AddrRange a -> DataType
$cdataTypeOf :: forall a. Data a => AddrRange a -> DataType
toConstr :: AddrRange a -> Constr
$ctoConstr :: forall a. Data a => AddrRange a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AddrRange a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (AddrRange a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a)
$cp1Data :: forall a. Data a => Typeable (AddrRange a)
Data, (forall x. AddrRange a -> Rep (AddrRange a) x)
-> (forall x. Rep (AddrRange a) x -> AddrRange a)
-> Generic (AddrRange a)
forall x. Rep (AddrRange a) x -> AddrRange a
forall x. AddrRange a -> Rep (AddrRange a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (AddrRange a) x -> AddrRange a
forall a x. AddrRange a -> Rep (AddrRange a) x
$cto :: forall a x. Rep (AddrRange a) x -> AddrRange a
$cfrom :: forall a x. AddrRange a -> Rep (AddrRange a) x
Generic, Typeable)
instance Show a => Show (AddrRange a) where
show :: AddrRange a -> String
show AddrRange a
x = a -> String
forall a. Show a => a -> String
show (AddrRange a -> a
forall a. AddrRange a -> a
addr AddrRange a
x) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (AddrRange a -> Int
forall a. AddrRange a -> Int
mlen AddrRange a
x)
instance Show IPRange where
show :: IPRange -> String
show (IPv4Range AddrRange IPv4
ip) = AddrRange IPv4 -> String
forall a. Show a => a -> String
show AddrRange IPv4
ip
show (IPv6Range AddrRange IPv6
ip) = AddrRange IPv6 -> String
forall a. Show a => a -> String
show AddrRange IPv6
ip
instance Read IPRange where
readsPrec :: Int -> ReadS IPRange
readsPrec Int
_ = ReadS IPRange
parseIPRange
parseIPRange :: String -> [(IPRange,String)]
parseIPRange :: ReadS IPRange
parseIPRange String
cs = case MkParser String (AddrRange IPv4)
-> String -> (Maybe (AddrRange IPv4), String)
forall inp a. MkParser inp a -> inp -> (Maybe a, inp)
runParser MkParser String (AddrRange IPv4)
ip4range String
cs of
(Just AddrRange IPv4
ip,String
rest) -> [(AddrRange IPv4 -> IPRange
IPv4Range AddrRange IPv4
ip,String
rest)]
(Maybe (AddrRange IPv4)
Nothing,String
_) -> case MkParser String (AddrRange IPv6)
-> String -> (Maybe (AddrRange IPv6), String)
forall inp a. MkParser inp a -> inp -> (Maybe a, inp)
runParser MkParser String (AddrRange IPv6)
ip6range String
cs of
(Just AddrRange IPv6
ip,String
rest) -> [(AddrRange IPv6 -> IPRange
IPv6Range AddrRange IPv6
ip,String
rest)]
(Maybe (AddrRange IPv6)
Nothing,String
_) -> []
instance Read (AddrRange IPv4) where
readsPrec :: Int -> ReadS (AddrRange IPv4)
readsPrec Int
_ = ReadS (AddrRange IPv4)
parseIPv4Range
instance Read (AddrRange IPv6) where
readsPrec :: Int -> ReadS (AddrRange IPv6)
readsPrec Int
_ = ReadS (AddrRange IPv6)
parseIPv6Range
parseIPv4Range :: String -> [(AddrRange IPv4,String)]
parseIPv4Range :: ReadS (AddrRange IPv4)
parseIPv4Range String
cs = case MkParser String (AddrRange IPv4)
-> String -> (Maybe (AddrRange IPv4), String)
forall inp a. MkParser inp a -> inp -> (Maybe a, inp)
runParser MkParser String (AddrRange IPv4)
ip4range String
cs of
(Maybe (AddrRange IPv4)
Nothing,String
_) -> []
(Just AddrRange IPv4
a4,String
rest) -> [(AddrRange IPv4
a4,String
rest)]
parseIPv6Range :: String -> [(AddrRange IPv6,String)]
parseIPv6Range :: ReadS (AddrRange IPv6)
parseIPv6Range String
cs = case MkParser String (AddrRange IPv6)
-> String -> (Maybe (AddrRange IPv6), String)
forall inp a. MkParser inp a -> inp -> (Maybe a, inp)
runParser MkParser String (AddrRange IPv6)
ip6range String
cs of
(Maybe (AddrRange IPv6)
Nothing,String
_) -> []
(Just AddrRange IPv6
a6,String
rest) -> [(AddrRange IPv6
a6,String
rest)]
ip4range :: Parser (AddrRange IPv4)
ip4range :: MkParser String (AddrRange IPv4)
ip4range = do
IPv4
ip <- Parser IPv4
ip4
Int
len <- Int -> MkParser String Int -> MkParser String Int
forall a inp. a -> MkParser inp a -> MkParser inp a
option Int
32 (MkParser String Int -> MkParser String Int)
-> MkParser String Int -> MkParser String Int
forall a b. (a -> b) -> a -> b
$ Char -> MkParser String Char
forall inp. Input inp => Char -> MkParser inp Char
char Char
'/' MkParser String Char -> MkParser String Int -> MkParser String Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MkParser String Int
dig
Int -> MkParser String ()
forall (f :: * -> *) a. (Ord a, Num a, MonadFail f) => a -> f ()
check Int
len
let msk :: IPv4
msk = Int -> IPv4
maskIPv4 Int
len
adr :: IPv4
adr = IPv4
ip IPv4 -> IPv4 -> IPv4
`maskedIPv4` IPv4
msk
AddrRange IPv4 -> MkParser String (AddrRange IPv4)
forall (m :: * -> *) a. Monad m => a -> m a
return (AddrRange IPv4 -> MkParser String (AddrRange IPv4))
-> AddrRange IPv4 -> MkParser String (AddrRange IPv4)
forall a b. (a -> b) -> a -> b
$ IPv4 -> IPv4 -> Int -> AddrRange IPv4
forall a. a -> a -> Int -> AddrRange a
AddrRange IPv4
adr IPv4
msk Int
len
where
check :: a -> f ()
check a
len = Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (a
len a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
|| a
32 a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
len) (String -> f ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"IPv4 mask length")
maskedIPv4 :: IPv4 -> IPv4 -> IPv4
IP4 IPv4Addr
a maskedIPv4 :: IPv4 -> IPv4 -> IPv4
`maskedIPv4` IP4 IPv4Addr
m = IPv4Addr -> IPv4
IP4 (IPv4Addr
a IPv4Addr -> IPv4Addr -> IPv4Addr
forall a. Bits a => a -> a -> a
.&. IPv4Addr
m)
ip6range :: Parser (AddrRange IPv6)
ip6range :: MkParser String (AddrRange IPv6)
ip6range = do
IPv6
ip <- Parser IPv6
ip6
Int
len <- Int -> MkParser String Int -> MkParser String Int
forall a inp. a -> MkParser inp a -> MkParser inp a
option Int
128 (MkParser String Int -> MkParser String Int)
-> MkParser String Int -> MkParser String Int
forall a b. (a -> b) -> a -> b
$ Char -> MkParser String Char
forall inp. Input inp => Char -> MkParser inp Char
char Char
'/' MkParser String Char -> MkParser String Int -> MkParser String Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MkParser String Int
dig
Int -> MkParser String ()
forall (f :: * -> *) a.
(Ord a, Num a, MonadFail f, Show a) =>
a -> f ()
check Int
len
let msk :: IPv6
msk = Int -> IPv6
maskIPv6 Int
len
adr :: IPv6
adr = IPv6
ip IPv6 -> IPv6 -> IPv6
`maskedIPv6` IPv6
msk
AddrRange IPv6 -> MkParser String (AddrRange IPv6)
forall (m :: * -> *) a. Monad m => a -> m a
return (AddrRange IPv6 -> MkParser String (AddrRange IPv6))
-> AddrRange IPv6 -> MkParser String (AddrRange IPv6)
forall a b. (a -> b) -> a -> b
$ IPv6 -> IPv6 -> Int -> AddrRange IPv6
forall a. a -> a -> Int -> AddrRange a
AddrRange IPv6
adr IPv6
msk Int
len
where
check :: a -> f ()
check a
len = Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (a
len a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
|| a
128 a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
len) (String -> f ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"IPv6 mask length: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
len))
maskedIPv6 :: IPv6 -> IPv6 -> IPv6
IP6 (IPv4Addr
a1,IPv4Addr
a2,IPv4Addr
a3,IPv4Addr
a4) maskedIPv6 :: IPv6 -> IPv6 -> IPv6
`maskedIPv6` IP6 (IPv4Addr
m1,IPv4Addr
m2,IPv4Addr
m3,IPv4Addr
m4) = (IPv4Addr, IPv4Addr, IPv4Addr, IPv4Addr) -> IPv6
IP6 (IPv4Addr
a1IPv4Addr -> IPv4Addr -> IPv4Addr
forall a. Bits a => a -> a -> a
.&.IPv4Addr
m1,IPv4Addr
a2IPv4Addr -> IPv4Addr -> IPv4Addr
forall a. Bits a => a -> a -> a
.&.IPv4Addr
m2,IPv4Addr
a3IPv4Addr -> IPv4Addr -> IPv4Addr
forall a. Bits a => a -> a -> a
.&.IPv4Addr
m3,IPv4Addr
a4IPv4Addr -> IPv4Addr -> IPv4Addr
forall a. Bits a => a -> a -> a
.&.IPv4Addr
m4)
instance IsString IPRange where
fromString :: String -> IPRange
fromString = String -> IPRange
forall a. Read a => String -> a
read
instance IsString (AddrRange IPv4) where
fromString :: String -> AddrRange IPv4
fromString = String -> AddrRange IPv4
forall a. Read a => String -> a
read
instance IsString (AddrRange IPv6) where
fromString :: String -> AddrRange IPv6
fromString = String -> AddrRange IPv6
forall a. Read a => String -> a
read