iproute-1.7.7: IP Routing Table

Safe Haskell | None
Language | Haskell2010

Data.IP

Contents

- IP data
  - IPv4
  - IPv6
  - Converters
- IP range data
- Address class

Description

Data structures to express IPv4, IPv6 and IP range.

Synopsis

- data IP
  - = IPv4 {
    - ipv4 :: IPv4
    }
  - | IPv6 {
    - ipv6 :: IPv6
    }
- data IPv4
- toIPv4 :: [Int] -> IPv4
- fromIPv4 :: IPv4 -> [Int]
- fromHostAddress :: HostAddress -> IPv4
- toHostAddress :: IPv4 -> HostAddress
- data IPv6
- toIPv6 :: [Int] -> IPv6
- toIPv6b :: [Int] -> IPv6
- fromIPv6 :: IPv6 -> [Int]
- fromIPv6b :: IPv6 -> [Int]
- fromHostAddress6 :: HostAddress6 -> IPv6
- toHostAddress6 :: IPv6 -> HostAddress6
- ipv4ToIPv6 :: IPv4 -> IPv6
- fromSockAddr :: SockAddr -> Maybe (IP, PortNumber)
- data IPRange
  - = IPv4Range {
    - ipv4range :: AddrRange IPv4
    }
  - | IPv6Range {
    - ipv6range :: AddrRange IPv6
    }
- data AddrRange a
- class Eq a => Addr a where
  - masked :: a -> a -> a
  - intToMask :: Int -> a
- makeAddrRange :: Addr a => a -> Int -> AddrRange a
- (>:>) :: Addr a => AddrRange a -> AddrRange a -> Bool
- isMatchedTo :: Addr a => a -> AddrRange a -> Bool
- addrRangePair :: Addr a => AddrRange a -> (a, Int)
- ipv4RangeToIPv6 :: AddrRange IPv4 -> AddrRange IPv6

# IP data

data IP Source #

A unified IP data for `IP` and `IP`. To create this, use the data constructors. Or use `read` `"192.0.2.1"` :: `IP`, for example. Also, `"192.0.2.1"` can be used as literal with OverloadedStrings.

    >>> (read "192.0.2.1" :: IP) == IPv4 (read "192.0.2.1" :: IPv4)
    True
    >>> (read "2001:db8:00:00:00:00:00:01" :: IP) == IPv6 (read "2001:db8:00:00:00:00:00:01" :: IPv6)
    True

Constructors

IPv4 |

Fields

- ipv4 :: IPv4

IPv6 |

Fields

- ipv6 :: IPv6

Instances

Enum IP Source # |
Instance details Defined in Data.IP.Addr Methods succ :: IP -> IP Source # pred :: IP -> IP Source # toEnum :: Int -> IP Source # fromEnum :: IP -> Int Source # enumFrom :: IP -> [IP] Source # enumFromThen :: IP -> IP -> [IP] Source # enumFromTo :: IP -> IP -> [IP] Source # enumFromThenTo :: IP -> IP -> IP -> [IP] Source #

Eq IP Source #

Equality over IP addresses. Correctly compare IPv4 and IPv4-embedded-in-IPv6 addresses.

    >>> (read "2001:db8:00:00:00:00:00:01" :: IP) == (read "2001:db8:00:00:00:00:00:01" :: IP)
    True
    >>> (read "2001:db8:00:00:00:00:00:01" :: IP) == (read "2001:db8:00:00:00:00:00:05" :: IP)
    False
    >>> (read "127.0.0.1" :: IP) == (read "127.0.0.1" :: IP)
    True
    >>> (read "127.0.0.1" :: IP) == (read "10.0.0.1" :: IP)
    False
    >>> (read "::ffff:127.0.0.1" :: IP) == (read "127.0.0.1" :: IP)
    True
    >>> (read "::ffff:127.0.0.1" :: IP) == (read "127.0.0.9" :: IP)
    False
    >>> (read "::ffff:127.0.0.1" :: IP) >= (read "127.0.0.1" :: IP)
    True
    >>> (read "::ffff:127.0.0.1" :: IP) <= (read "127.0.0.1" :: IP)
    True

Instance details Defined in Data.IP.Addr Methods (==) :: IP -> IP -> Bool Source # (/=) :: IP -> IP -> Bool Source #
Data IP Source # |

Instance details

Defined in Data.IP.Addr

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IP -> c IP Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IP Source #

toConstr :: IP -> Constr Source #

dataTypeOf :: IP -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IP) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP) Source #

gmapT :: (forall b. Data b => b -> b) -> IP -> IP Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> IP -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IP -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IP -> m IP Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IP -> m IP Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IP -> m IP Source #

Ord IP Source # |
Instance details Defined in Data.IP.Addr Methods compare :: IP -> IP -> Ordering Source # (<) :: IP -> IP -> Bool Source # (<=) :: IP -> IP -> Bool Source # (>) :: IP -> IP -> Bool Source # (>=) :: IP -> IP -> Bool Source # max :: IP -> IP -> IP Source # min :: IP -> IP -> IP Source #
Read IP Source # |
Instance details Defined in Data.IP.Addr Methods readsPrec :: Int -> ReadS IP Source # readList :: ReadS [IP] Source # readPrec :: ReadPrec IP Source # readListPrec :: ReadPrec [IP] Source #
Show IP Source # |
Instance details Defined in Data.IP.Addr Methods showsPrec :: Int -> IP -> ShowS Source # show :: IP -> String Source # showList :: [IP] -> ShowS Source #
IsString IP Source # |
Instance details Defined in Data.IP.Addr Methods fromString :: String -> IP Source #
Generic IP Source # |
Instance details Defined in Data.IP.Addr Associated Types type Rep IP :: Type -> Type Source # Methods from :: IP -> Rep IP x Source # to :: Rep IP x -> IP Source #
type Rep IP Source # |
Instance details Defined in Data.IP.Addr type Rep IP = D1 (MetaData "IP" "Data.IP.Addr" "iproute-1.7.7-LDUpxpRFagGLoirhLLYKEm" False) (C1 (MetaCons "IPv4" PrefixI True) (S1 (MetaSel (Just "ipv4") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 IPv4)) :+: C1 (MetaCons "IPv6" PrefixI True) (S1 (MetaSel (Just "ipv6") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 IPv6)))

## IPv4

data IPv4 Source #

The abstract data type to express an IPv4 address. To create this, use `toIPv4`. Or use `read` `"192.0.2.1"` :: `IP`, for example. Also, `"192.0.2.1"` can be used as literal with OverloadedStrings.

    >>> read "192.0.2.1" :: IPv4
    192.0.2.1

Instances

Bounded IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods minBound :: IPv4 Source # maxBound :: IPv4 Source #
Enum IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods succ :: IPv4 -> IPv4 Source # pred :: IPv4 -> IPv4 Source # toEnum :: Int -> IPv4 Source # fromEnum :: IPv4 -> Int Source # enumFrom :: IPv4 -> [IPv4] Source # enumFromThen :: IPv4 -> IPv4 -> [IPv4] Source # enumFromTo :: IPv4 -> IPv4 -> [IPv4] Source # enumFromThenTo :: IPv4 -> IPv4 -> IPv4 -> [IPv4] Source #
Eq IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods (==) :: IPv4 -> IPv4 -> Bool Source # (/=) :: IPv4 -> IPv4 -> Bool Source #
Data IPv4 Source # |

Instance details

Defined in Data.IP.Addr

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IPv4 -> c IPv4 Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IPv4 Source #

toConstr :: IPv4 -> Constr Source #

dataTypeOf :: IPv4 -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IPv4) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPv4) Source #

gmapT :: (forall b. Data b => b -> b) -> IPv4 -> IPv4 Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IPv4 -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IPv4 -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> IPv4 -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IPv4 -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IPv4 -> m IPv4 Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IPv4 -> m IPv4 Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IPv4 -> m IPv4 Source #

Ord IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods compare :: IPv4 -> IPv4 -> Ordering Source # (<) :: IPv4 -> IPv4 -> Bool Source # (<=) :: IPv4 -> IPv4 -> Bool Source # (>) :: IPv4 -> IPv4 -> Bool Source # (>=) :: IPv4 -> IPv4 -> Bool Source # max :: IPv4 -> IPv4 -> IPv4 Source # min :: IPv4 -> IPv4 -> IPv4 Source #
Read IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods readsPrec :: Int -> ReadS IPv4 Source # readList :: ReadS [IPv4] Source # readPrec :: ReadPrec IPv4 Source # readListPrec :: ReadPrec [IPv4] Source #
Show IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods showsPrec :: Int -> IPv4 -> ShowS Source # show :: IPv4 -> String Source # showList :: [IPv4] -> ShowS Source #
IsString IPv4 Source # |
Instance details Defined in Data.IP.Addr Methods fromString :: String -> IPv4 Source #
Generic IPv4 Source # |
Instance details Defined in Data.IP.Addr Associated Types type Rep IPv4 :: Type -> Type Source # Methods from :: IPv4 -> Rep IPv4 x Source # to :: Rep IPv4 x -> IPv4 Source #
Addr IPv4 Source # |
Instance details Defined in Data.IP.Op Methods masked :: IPv4 -> IPv4 -> IPv4 Source # intToMask :: Int -> IPv4 Source #
Routable IPv4 Source # |
Instance details Defined in Data.IP.RouteTable.Internal Methods intToTBit :: Int -> IPv4 Source # isZero :: IPv4 -> IPv4 -> Bool Source #
Read (AddrRange IPv4) Source # |
Instance details Defined in Data.IP.Range Methods readsPrec :: Int -> ReadS (AddrRange IPv4) Source # readList :: ReadS [AddrRange IPv4] Source # readPrec :: ReadPrec (AddrRange IPv4) Source # readListPrec :: ReadPrec [AddrRange IPv4] Source #
IsString (AddrRange IPv4) Source # |
Instance details Defined in Data.IP.Range Methods fromString :: String -> AddrRange IPv4 Source #
type Rep IPv4 Source # |
Instance details Defined in Data.IP.Addr type Rep IPv4 = D1 (MetaData "IPv4" "Data.IP.Addr" "iproute-1.7.7-LDUpxpRFagGLoirhLLYKEm" True) (C1 (MetaCons "IP4" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 IPv4Addr)))

toIPv4 :: [Int] -> IPv4 Source #

The `toIPv4` function takes a list of `Int` and returns `IP`.

    >>> toIPv4 [192,0,2,1]
    192.0.2.1

fromIPv4 :: IPv4 -> [Int] Source #

The `fromIPv4` function converts `IP` to a list of `Int`.

    >>> fromIPv4 (toIPv4 [192,0,2,1])
    [192,0,2,1]

fromHostAddress :: HostAddress -> IPv4 Source #

The `fromHostAddress` function converts `HostAddress` to `IP`.

toHostAddress :: IPv4 -> HostAddress Source #

The `toHostAddress` function converts `IP` to `HostAddress`.

## IPv6

data IPv6 Source #

The abstract data type to express an IPv6 address. To create this, use `toIPv6`. Or use `read` `"2001:DB8::1"` :: `IP`, for example. Also, `"2001:DB8::1"` can be used as literal with OverloadedStrings.

    >>> read "2001:db8:00:00:00:00:00:01" :: IPv6
    2001:db8::1
    >>> read "2001:db8:11e:c00::101" :: IPv6
    2001:db8:11e:c00::101
    >>> read "2001:db8:11e:c00:aa:bb:192.0.2.1" :: IPv6
    2001:db8:11e:c00:aa:bb:c000:201
    >>> read "2001:db8::192.0.2.1" :: IPv6
    2001:db8::c000:201
    >>> read "0::ffff:192.0.2.1" :: IPv6
    ::ffff:192.0.2.1
    >>> read "0::0:c000:201" :: IPv6
    ::192.0.2.1
    >>> read "::0.0.0.1" :: IPv6
    ::1

Instances

Bounded IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods minBound :: IPv6 Source # maxBound :: IPv6 Source #
Enum IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods succ :: IPv6 -> IPv6 Source # pred :: IPv6 -> IPv6 Source # toEnum :: Int -> IPv6 Source # fromEnum :: IPv6 -> Int Source # enumFrom :: IPv6 -> [IPv6] Source # enumFromThen :: IPv6 -> IPv6 -> [IPv6] Source # enumFromTo :: IPv6 -> IPv6 -> [IPv6] Source # enumFromThenTo :: IPv6 -> IPv6 -> IPv6 -> [IPv6] Source #
Eq IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods (==) :: IPv6 -> IPv6 -> Bool Source # (/=) :: IPv6 -> IPv6 -> Bool Source #
Data IPv6 Source # |

Instance details

Defined in Data.IP.Addr

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IPv6 -> c IPv6 Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IPv6 Source #

toConstr :: IPv6 -> Constr Source #

dataTypeOf :: IPv6 -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IPv6) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPv6) Source #

gmapT :: (forall b. Data b => b -> b) -> IPv6 -> IPv6 Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IPv6 -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IPv6 -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> IPv6 -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IPv6 -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IPv6 -> m IPv6 Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IPv6 -> m IPv6 Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IPv6 -> m IPv6 Source #

Ord IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods compare :: IPv6 -> IPv6 -> Ordering Source # (<) :: IPv6 -> IPv6 -> Bool Source # (<=) :: IPv6 -> IPv6 -> Bool Source # (>) :: IPv6 -> IPv6 -> Bool Source # (>=) :: IPv6 -> IPv6 -> Bool Source # max :: IPv6 -> IPv6 -> IPv6 Source # min :: IPv6 -> IPv6 -> IPv6 Source #
Read IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods readsPrec :: Int -> ReadS IPv6 Source # readList :: ReadS [IPv6] Source # readPrec :: ReadPrec IPv6 Source # readListPrec :: ReadPrec [IPv6] Source #
Show IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods showsPrec :: Int -> IPv6 -> ShowS Source # show :: IPv6 -> String Source # showList :: [IPv6] -> ShowS Source #
IsString IPv6 Source # |
Instance details Defined in Data.IP.Addr Methods fromString :: String -> IPv6 Source #
Generic IPv6 Source # |
Instance details Defined in Data.IP.Addr Associated Types type Rep IPv6 :: Type -> Type Source # Methods from :: IPv6 -> Rep IPv6 x Source # to :: Rep IPv6 x -> IPv6 Source #
Addr IPv6 Source # |
Instance details Defined in Data.IP.Op Methods masked :: IPv6 -> IPv6 -> IPv6 Source # intToMask :: Int -> IPv6 Source #
Routable IPv6 Source # |
Instance details Defined in Data.IP.RouteTable.Internal Methods intToTBit :: Int -> IPv6 Source # isZero :: IPv6 -> IPv6 -> Bool Source #
Read (AddrRange IPv6) Source # |
Instance details Defined in Data.IP.Range Methods readsPrec :: Int -> ReadS (AddrRange IPv6) Source # readList :: ReadS [AddrRange IPv6] Source # readPrec :: ReadPrec (AddrRange IPv6) Source # readListPrec :: ReadPrec [AddrRange IPv6] Source #
IsString (AddrRange IPv6) Source # |
Instance details Defined in Data.IP.Range Methods fromString :: String -> AddrRange IPv6 Source #
type Rep IPv6 Source # |
Instance details Defined in Data.IP.Addr type Rep IPv6 = D1 (MetaData "IPv6" "Data.IP.Addr" "iproute-1.7.7-LDUpxpRFagGLoirhLLYKEm" True) (C1 (MetaCons "IP6" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 IPv6Addr)))

toIPv6 :: [Int] -> IPv6 Source #

The `toIPv6` function takes a list of `Int` and returns `IP`.

    >>> toIPv6 [0x2001,0xDB8,0,0,0,0,0,1]
    2001:db8::1

toIPv6b :: [Int] -> IPv6 Source #

The `toIPv6b` function takes a list of `Int` where each member repserents a single byte and returns `IP`.

    >>> toIPv6b [0x20,0x01,0xD,0xB8,0,0,0,0,0,0,0,0,0,0,0,1]
    2001:db8::1

fromIPv6 :: IPv6 -> [Int] Source #

The `toIPv6` function converts `IP` to a list of `Int`.

    >>> fromIPv6 (toIPv6 [0x2001,0xDB8,0,0,0,0,0,1])
    [8193,3512,0,0,0,0,0,1]

fromIPv6b :: IPv6 -> [Int] Source #

The `fromIPv6b` function converts `IP` to a list of `Int` where each member represents a single byte.

    >>> fromIPv6b (toIPv6b [0x20,0x01,0xD,0xB8,0,0,0,0,0,0,0,0,0,0,0,1])
    [32,1,13,184,0,0,0,0,0,0,0,0,0,0,0,1]

fromHostAddress6 :: HostAddress6 -> IPv6 Source #

The `fromHostAddress6` function converts `HostAddress6` to `IP`.

toHostAddress6 :: IPv6 -> HostAddress6 Source #

The `toHostAddress6` function converts `IP` to `HostAddress6`.

## Converters

ipv4ToIPv6 :: IPv4 -> IPv6 Source #

Convert IPv4 address to IPv4-embedded-in-IPv6

fromSockAddr :: SockAddr -> Maybe (IP, PortNumber) Source #

Convert `SockAddr` to `IP`.

Since: 1.7.4.

# IP range data

data IPRange Source #

A unified data for `AddrRange` `IP` and `AddrRange` `IP`. To create this, use `read` `"192.0.2.0/24"` :: `IPRange`. Also, `"192.0.2.0/24"` can be used as literal with OverloadedStrings.

    >>> (read "192.0.2.1/24" :: IPRange) == IPv4Range (read "192.0.2.0/24" :: AddrRange IPv4)
    True
    >>> (read "2001:db8:00:00:00:00:00:01/48" :: IPRange) == IPv6Range (read "2001:db8:00:00:00:00:00:01/48" :: AddrRange IPv6)
    True

Constructors

IPv4Range |

Fields

- ipv4range :: AddrRange IPv4

IPv6Range |

Fields

- ipv6range :: AddrRange IPv6

Instances

Eq IPRange Source # |
Instance details Defined in Data.IP.Range Methods (==) :: IPRange -> IPRange -> Bool Source # (/=) :: IPRange -> IPRange -> Bool Source #
Data IPRange Source # |

Instance details

Defined in Data.IP.Range

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IPRange -> c IPRange Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IPRange Source #

toConstr :: IPRange -> Constr Source #

dataTypeOf :: IPRange -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c IPRange) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IPRange) Source #

gmapT :: (forall b. Data b => b -> b) -> IPRange -> IPRange Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IPRange -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IPRange -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> IPRange -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IPRange -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IPRange -> m IPRange Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IPRange -> m IPRange Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IPRange -> m IPRange Source #

Ord IPRange Source # |
Instance details Defined in Data.IP.Range Methods compare :: IPRange -> IPRange -> Ordering Source # (<) :: IPRange -> IPRange -> Bool Source # (<=) :: IPRange -> IPRange -> Bool Source # (>) :: IPRange -> IPRange -> Bool Source # (>=) :: IPRange -> IPRange -> Bool Source # max :: IPRange -> IPRange -> IPRange Source # min :: IPRange -> IPRange -> IPRange Source #
Read IPRange Source # |
Instance details Defined in Data.IP.Range Methods readsPrec :: Int -> ReadS IPRange Source # readList :: ReadS [IPRange] Source # readPrec :: ReadPrec IPRange Source # readListPrec :: ReadPrec [IPRange] Source #
Show IPRange Source # |
Instance details Defined in Data.IP.Range Methods showsPrec :: Int -> IPRange -> ShowS Source # show :: IPRange -> String Source # showList :: [IPRange] -> ShowS Source #
IsString IPRange Source # |
Instance details Defined in Data.IP.Range Methods fromString :: String -> IPRange Source #
Generic IPRange Source # |
Instance details Defined in Data.IP.Range Associated Types type Rep IPRange :: Type -> Type Source # Methods from :: IPRange -> Rep IPRange x Source # to :: Rep IPRange x -> IPRange Source #
type Rep IPRange Source # |

Instance details

Defined in Data.IP.Range

type Rep IPRange = D1 (MetaData "IPRange" "Data.IP.Range" "iproute-1.7.7-LDUpxpRFagGLoirhLLYKEm" False) (C1 (MetaCons "IPv4Range" PrefixI True) (S1 (MetaSel (Just "ipv4range") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (AddrRange IPv4))) :+: C1 (MetaCons "IPv6Range" PrefixI True) (S1 (MetaSel (Just "ipv6range") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (AddrRange IPv6))))

data AddrRange a Source #

The Addr range consists of an address, a contiguous mask, and mask length. The contiguous mask and the mask length are essentially same information but contained for pre calculation.

To create this, use `makeAddrRange` or `read` `"192.0.2.0/24"` :: `AddrRange` `IP`. Also, `"192.0.2.0/24"` can be used as literal with OverloadedStrings.

    >>> read "192.0.2.1/24" :: AddrRange IPv4
    192.0.2.0/24
    >>> read "2001:db8:00:00:00:00:00:01/48" :: AddrRange IPv6
    2001:db8::/48

Instances

Eq a => Eq (AddrRange a) Source # |
Instance details Defined in Data.IP.Range Methods (==) :: AddrRange a -> AddrRange a -> Bool Source # (/=) :: AddrRange a -> AddrRange a -> Bool Source #
Data a => Data (AddrRange a) Source # |

Instance details

Defined in Data.IP.Range

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AddrRange a -> c (AddrRange a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (AddrRange a) Source #

toConstr :: AddrRange a -> Constr Source #

dataTypeOf :: AddrRange a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (AddrRange a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (AddrRange a)) Source #

gmapT :: (forall b. Data b => b -> b) -> AddrRange a -> AddrRange a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AddrRange a -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AddrRange a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> AddrRange a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> AddrRange a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AddrRange a -> m (AddrRange a) Source #

Ord a => Ord (AddrRange a) Source # |

Instance details

Defined in Data.IP.Range

Methods

compare :: AddrRange a -> AddrRange a -> Ordering Source #

(<) :: AddrRange a -> AddrRange a -> Bool Source #

(<=) :: AddrRange a -> AddrRange a -> Bool Source #

(>) :: AddrRange a -> AddrRange a -> Bool Source #

(>=) :: AddrRange a -> AddrRange a -> Bool Source #

max :: AddrRange a -> AddrRange a -> AddrRange a Source #

min :: AddrRange a -> AddrRange a -> AddrRange a Source #

Read (AddrRange IPv6) Source # |
Instance details Defined in Data.IP.Range Methods readsPrec :: Int -> ReadS (AddrRange IPv6) Source # readList :: ReadS [AddrRange IPv6] Source # readPrec :: ReadPrec (AddrRange IPv6) Source # readListPrec :: ReadPrec [AddrRange IPv6] Source #
Read (AddrRange IPv4) Source # |
Instance details Defined in Data.IP.Range Methods readsPrec :: Int -> ReadS (AddrRange IPv4) Source # readList :: ReadS [AddrRange IPv4] Source # readPrec :: ReadPrec (AddrRange IPv4) Source # readListPrec :: ReadPrec [AddrRange IPv4] Source #
Show a => Show (AddrRange a) Source # |
Instance details Defined in Data.IP.Range Methods showsPrec :: Int -> AddrRange a -> ShowS Source # show :: AddrRange a -> String Source # showList :: [AddrRange a] -> ShowS Source #
IsString (AddrRange IPv6) Source # |
Instance details Defined in Data.IP.Range Methods fromString :: String -> AddrRange IPv6 Source #
IsString (AddrRange IPv4) Source # |
Instance details Defined in Data.IP.Range Methods fromString :: String -> AddrRange IPv4 Source #
Generic (AddrRange a) Source # |
Instance details Defined in Data.IP.Range Associated Types type Rep (AddrRange a) :: Type -> Type Source # Methods from :: AddrRange a -> Rep (AddrRange a) x Source # to :: Rep (AddrRange a) x -> AddrRange a Source #
type Rep (AddrRange a) Source # |

Instance details

Defined in Data.IP.Range

type Rep (AddrRange a) = D1 (MetaData "AddrRange" "Data.IP.Range" "iproute-1.7.7-LDUpxpRFagGLoirhLLYKEm" False) (C1 (MetaCons "AddrRange" PrefixI True) (S1 (MetaSel (Just "addr") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a) :*: (S1 (MetaSel (Just "mask") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a) :*: S1 (MetaSel (Just "mlen") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int))))

# Address class

class Eq a => Addr a where Source #

    >>> toIPv4 [127,0,2,1] `masked` intToMask 7
    126.0.0.0

Methods

masked :: a -> a -> a Source #

The `masked` function takes an `Addr` and a contiguous mask and returned a masked `Addr`.

intToMask :: Int -> a Source #

The `intToMask` function takes an `Int` representing the number of bits to be set in the returned contiguous mask. When this integer is positive the bits will be starting from the MSB and from the LSB otherwise.

    >>> intToMask 16 :: IPv4
    255.255.0.0

    >>> intToMask (-16) :: IPv4
    0.0.255.255

    >>> intToMask 16 :: IPv6
    ffff::

    >>> intToMask (-16) :: IPv6
    ::ffff

Instances

Addr IPv6 Source # |
Instance details Defined in Data.IP.Op Methods masked :: IPv6 -> IPv6 -> IPv6 Source # intToMask :: Int -> IPv6 Source #
Addr IPv4 Source # |
Instance details Defined in Data.IP.Op Methods masked :: IPv4 -> IPv4 -> IPv4 Source # intToMask :: Int -> IPv4 Source #

makeAddrRange :: Addr a => a -> Int -> AddrRange a Source #

The `makeAddrRange` functions takes an `Addr` address and a mask length. It creates a bit mask from the mask length and masks the `Addr` address, then returns `AddrRange` made of them.

    >>> makeAddrRange (toIPv4 [127,0,2,1]) 8
    127.0.0.0/8
    >>> makeAddrRange (toIPv6 [0x2001,0xDB8,0,0,0,0,0,1]) 8
    2000::/8

(>:>) :: Addr a => AddrRange a -> AddrRange a -> Bool Source #

The >:> operator takes two `AddrRange`. It returns `True` if the first `AddrRange` contains the second `AddrRange`. Otherwise, it returns `False`.

    >>> makeAddrRange ("127.0.2.1" :: IPv4) 8 >:> makeAddrRange "127.0.2.1" 24
    True
    >>> makeAddrRange ("127.0.2.1" :: IPv4) 24 >:> makeAddrRange "127.0.2.1" 8
    False
    >>> makeAddrRange ("2001:DB8::1" :: IPv6) 16 >:> makeAddrRange "2001:DB8::1" 32
    True
    >>> makeAddrRange ("2001:DB8::1" :: IPv6) 32 >:> makeAddrRange "2001:DB8::1" 16
    False

isMatchedTo :: Addr a => a -> AddrRange a -> Bool Source #

The `toMatchedTo` function take an `Addr` address and an `AddrRange`, and returns `True` if the range contains the address.

    >>> ("127.0.2.0" :: IPv4) `isMatchedTo` makeAddrRange "127.0.2.1" 24
    True
    >>> ("127.0.2.0" :: IPv4) `isMatchedTo` makeAddrRange "127.0.2.1" 32
    False
    >>> ("2001:DB8::1" :: IPv6) `isMatchedTo` makeAddrRange "2001:DB8::1" 32
    True
    >>> ("2001:DB8::" :: IPv6) `isMatchedTo` makeAddrRange "2001:DB8::1" 128
    False

addrRangePair :: Addr a => AddrRange a -> (a, Int) Source #

The `unmakeAddrRange` functions take a `AddrRange` and returns the network address and a mask length.

    >>> addrRangePair ("127.0.0.0/8" :: AddrRange IPv4)
    (127.0.0.0,8)
    >>> addrRangePair ("2000::/8" :: AddrRange IPv6)
    (2000::,8)

ipv4RangeToIPv6 :: AddrRange IPv4 -> AddrRange IPv6 Source #

Convert IPv4 range to IPV4-embedded-in-IPV6 range