{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Network.IP.Addr
(
IP4(..)
, anIP4
, ip4ToOctets
, ip4ToOctetList
, ip4FromOctets
, ip4FromOctetList
, anyIP4
, loopbackIP4
, broadcastIP4
, Range4(..)
, ip4Range
, IP6(..)
, anIP6
, ip6ToWords
, ip6ToWordList
, ip6FromWords
, ip6FromWordList
, anyIP6
, loopbackIP6
, Range6(..)
, ip6Range
, IP46(..)
, anIP46
, anIP46Of
, IP
, anIP
, IsNetAddr(..)
, Net4Addr
, Net6Addr
, NetAddr
, aNetAddr
, aNetAddrOf
, aNet4Addr
, aNet6Addr
, aNetAddrIP
, net4Addr
, net6Addr
, toNetAddr46
, fromNetAddr46
, printNetAddr
, net4Parser
, net6Parser
, netParser
, putNetAddr
, getNetAddr
, InetPort(..)
, anInetPort
, InetAddr(..)
, Inet4Addr
, Inet6Addr
, anInetAddr
, anInetAddrOf
, anInet4Addr
, anInet6Addr
, anInetAddrIP
, toInetAddr46
, fromInetAddr46
) where
import Prelude hiding (print)
import Data.Typeable (Typeable)
#if !MIN_VERSION_base(4,10,0)
import Data.Typeable (Typeable1)
#endif
import Data.Data (Data)
import Data.Word
import Data.Bits
import Data.DoubleWord (BinaryWord(..), DoubleWord(..), Word128)
import Data.Ix (Ix)
import Data.Endian
import Data.Default.Class
import Data.Hashable
import Data.Serializer (Serializer, Serializable, SizedSerializable)
import qualified Data.Serializer as S
import Data.Deserializer (Deserializer, Deserializable)
import qualified Data.Deserializer as D
import Text.Printer (Printer)
#if !MIN_VERSION_base(4,13,0)
import Text.Printer ((<>))
#endif
import qualified Text.Printer as P
import qualified Text.Printer.Integral as P
import Data.Textual
import Data.Textual.Integral hiding (Binary)
import Text.Parser.Combinators ((<?>), try)
import Text.Parser.Char (CharParsing)
import qualified Text.Parser.Char as PC
import Text.Printf (printf)
import Type.Hint
import Control.Applicative
import Control.Monad (void, when)
import Foreign.Ptr (castPtr)
import Foreign.Storable (Storable(..))
newtype IP4 = IP4 { IP4 -> Word32
unIP4 ∷ Word32 }
deriving (Typeable, Typeable IP4
Constr
DataType
Typeable IP4
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP4 -> c IP4)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP4)
-> (IP4 -> Constr)
-> (IP4 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IP4))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP4))
-> ((forall b. Data b => b -> b) -> IP4 -> IP4)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r)
-> (forall u. (forall d. Data d => d -> u) -> IP4 -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> IP4 -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4)
-> Data IP4
IP4 -> Constr
IP4 -> DataType
(forall b. Data b => b -> b) -> IP4 -> IP4
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP4 -> c IP4
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP4
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) -> IP4 -> u
forall u. (forall d. Data d => d -> u) -> IP4 -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP4
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP4 -> c IP4
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IP4)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP4)
$cIP4 :: Constr
$tIP4 :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> IP4 -> m IP4
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4
gmapMp :: (forall d. Data d => d -> m d) -> IP4 -> m IP4
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4
gmapM :: (forall d. Data d => d -> m d) -> IP4 -> m IP4
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP4 -> m IP4
gmapQi :: Int -> (forall d. Data d => d -> u) -> IP4 -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IP4 -> u
gmapQ :: (forall d. Data d => d -> u) -> IP4 -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IP4 -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP4 -> r
gmapT :: (forall b. Data b => b -> b) -> IP4 -> IP4
$cgmapT :: (forall b. Data b => b -> b) -> IP4 -> IP4
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP4)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP4)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c IP4)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IP4)
dataTypeOf :: IP4 -> DataType
$cdataTypeOf :: IP4 -> DataType
toConstr :: IP4 -> Constr
$ctoConstr :: IP4 -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP4
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP4
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP4 -> c IP4
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP4 -> c IP4
$cp1Data :: Typeable IP4
Data, IP4 -> IP4 -> Bool
(IP4 -> IP4 -> Bool) -> (IP4 -> IP4 -> Bool) -> Eq IP4
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IP4 -> IP4 -> Bool
$c/= :: IP4 -> IP4 -> Bool
== :: IP4 -> IP4 -> Bool
$c== :: IP4 -> IP4 -> Bool
Eq, Eq IP4
Eq IP4
-> (IP4 -> IP4 -> Ordering)
-> (IP4 -> IP4 -> Bool)
-> (IP4 -> IP4 -> Bool)
-> (IP4 -> IP4 -> Bool)
-> (IP4 -> IP4 -> Bool)
-> (IP4 -> IP4 -> IP4)
-> (IP4 -> IP4 -> IP4)
-> Ord IP4
IP4 -> IP4 -> Bool
IP4 -> IP4 -> Ordering
IP4 -> IP4 -> IP4
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 :: IP4 -> IP4 -> IP4
$cmin :: IP4 -> IP4 -> IP4
max :: IP4 -> IP4 -> IP4
$cmax :: IP4 -> IP4 -> IP4
>= :: IP4 -> IP4 -> Bool
$c>= :: IP4 -> IP4 -> Bool
> :: IP4 -> IP4 -> Bool
$c> :: IP4 -> IP4 -> Bool
<= :: IP4 -> IP4 -> Bool
$c<= :: IP4 -> IP4 -> Bool
< :: IP4 -> IP4 -> Bool
$c< :: IP4 -> IP4 -> Bool
compare :: IP4 -> IP4 -> Ordering
$ccompare :: IP4 -> IP4 -> Ordering
$cp1Ord :: Eq IP4
Ord, IP4
IP4 -> IP4 -> Bounded IP4
forall a. a -> a -> Bounded a
maxBound :: IP4
$cmaxBound :: IP4
minBound :: IP4
$cminBound :: IP4
Bounded, Int -> IP4
IP4 -> Int
IP4 -> [IP4]
IP4 -> IP4
IP4 -> IP4 -> [IP4]
IP4 -> IP4 -> IP4 -> [IP4]
(IP4 -> IP4)
-> (IP4 -> IP4)
-> (Int -> IP4)
-> (IP4 -> Int)
-> (IP4 -> [IP4])
-> (IP4 -> IP4 -> [IP4])
-> (IP4 -> IP4 -> [IP4])
-> (IP4 -> IP4 -> IP4 -> [IP4])
-> Enum IP4
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: IP4 -> IP4 -> IP4 -> [IP4]
$cenumFromThenTo :: IP4 -> IP4 -> IP4 -> [IP4]
enumFromTo :: IP4 -> IP4 -> [IP4]
$cenumFromTo :: IP4 -> IP4 -> [IP4]
enumFromThen :: IP4 -> IP4 -> [IP4]
$cenumFromThen :: IP4 -> IP4 -> [IP4]
enumFrom :: IP4 -> [IP4]
$cenumFrom :: IP4 -> [IP4]
fromEnum :: IP4 -> Int
$cfromEnum :: IP4 -> Int
toEnum :: Int -> IP4
$ctoEnum :: Int -> IP4
pred :: IP4 -> IP4
$cpred :: IP4 -> IP4
succ :: IP4 -> IP4
$csucc :: IP4 -> IP4
Enum, Ord IP4
Ord IP4
-> ((IP4, IP4) -> [IP4])
-> ((IP4, IP4) -> IP4 -> Int)
-> ((IP4, IP4) -> IP4 -> Int)
-> ((IP4, IP4) -> IP4 -> Bool)
-> ((IP4, IP4) -> Int)
-> ((IP4, IP4) -> Int)
-> Ix IP4
(IP4, IP4) -> Int
(IP4, IP4) -> [IP4]
(IP4, IP4) -> IP4 -> Bool
(IP4, IP4) -> IP4 -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (IP4, IP4) -> Int
$cunsafeRangeSize :: (IP4, IP4) -> Int
rangeSize :: (IP4, IP4) -> Int
$crangeSize :: (IP4, IP4) -> Int
inRange :: (IP4, IP4) -> IP4 -> Bool
$cinRange :: (IP4, IP4) -> IP4 -> Bool
unsafeIndex :: (IP4, IP4) -> IP4 -> Int
$cunsafeIndex :: (IP4, IP4) -> IP4 -> Int
index :: (IP4, IP4) -> IP4 -> Int
$cindex :: (IP4, IP4) -> IP4 -> Int
range :: (IP4, IP4) -> [IP4]
$crange :: (IP4, IP4) -> [IP4]
$cp1Ix :: Ord IP4
Ix, Integer -> IP4
IP4 -> IP4
IP4 -> IP4 -> IP4
(IP4 -> IP4 -> IP4)
-> (IP4 -> IP4 -> IP4)
-> (IP4 -> IP4 -> IP4)
-> (IP4 -> IP4)
-> (IP4 -> IP4)
-> (IP4 -> IP4)
-> (Integer -> IP4)
-> Num IP4
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> IP4
$cfromInteger :: Integer -> IP4
signum :: IP4 -> IP4
$csignum :: IP4 -> IP4
abs :: IP4 -> IP4
$cabs :: IP4 -> IP4
negate :: IP4 -> IP4
$cnegate :: IP4 -> IP4
* :: IP4 -> IP4 -> IP4
$c* :: IP4 -> IP4 -> IP4
- :: IP4 -> IP4 -> IP4
$c- :: IP4 -> IP4 -> IP4
+ :: IP4 -> IP4 -> IP4
$c+ :: IP4 -> IP4 -> IP4
Num, Eq IP4
IP4
Eq IP4
-> (IP4 -> IP4 -> IP4)
-> (IP4 -> IP4 -> IP4)
-> (IP4 -> IP4 -> IP4)
-> (IP4 -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> IP4
-> (Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> Bool)
-> (IP4 -> Maybe Int)
-> (IP4 -> Int)
-> (IP4 -> Bool)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int -> IP4)
-> (IP4 -> Int)
-> Bits IP4
Int -> IP4
IP4 -> Bool
IP4 -> Int
IP4 -> Maybe Int
IP4 -> IP4
IP4 -> Int -> Bool
IP4 -> Int -> IP4
IP4 -> IP4 -> IP4
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
popCount :: IP4 -> Int
$cpopCount :: IP4 -> Int
rotateR :: IP4 -> Int -> IP4
$crotateR :: IP4 -> Int -> IP4
rotateL :: IP4 -> Int -> IP4
$crotateL :: IP4 -> Int -> IP4
unsafeShiftR :: IP4 -> Int -> IP4
$cunsafeShiftR :: IP4 -> Int -> IP4
shiftR :: IP4 -> Int -> IP4
$cshiftR :: IP4 -> Int -> IP4
unsafeShiftL :: IP4 -> Int -> IP4
$cunsafeShiftL :: IP4 -> Int -> IP4
shiftL :: IP4 -> Int -> IP4
$cshiftL :: IP4 -> Int -> IP4
isSigned :: IP4 -> Bool
$cisSigned :: IP4 -> Bool
bitSize :: IP4 -> Int
$cbitSize :: IP4 -> Int
bitSizeMaybe :: IP4 -> Maybe Int
$cbitSizeMaybe :: IP4 -> Maybe Int
testBit :: IP4 -> Int -> Bool
$ctestBit :: IP4 -> Int -> Bool
complementBit :: IP4 -> Int -> IP4
$ccomplementBit :: IP4 -> Int -> IP4
clearBit :: IP4 -> Int -> IP4
$cclearBit :: IP4 -> Int -> IP4
setBit :: IP4 -> Int -> IP4
$csetBit :: IP4 -> Int -> IP4
bit :: Int -> IP4
$cbit :: Int -> IP4
zeroBits :: IP4
$czeroBits :: IP4
rotate :: IP4 -> Int -> IP4
$crotate :: IP4 -> Int -> IP4
shift :: IP4 -> Int -> IP4
$cshift :: IP4 -> Int -> IP4
complement :: IP4 -> IP4
$ccomplement :: IP4 -> IP4
xor :: IP4 -> IP4 -> IP4
$cxor :: IP4 -> IP4 -> IP4
.|. :: IP4 -> IP4 -> IP4
$c.|. :: IP4 -> IP4 -> IP4
.&. :: IP4 -> IP4 -> IP4
$c.&. :: IP4 -> IP4 -> IP4
$cp1Bits :: Eq IP4
Bits, Eq IP4
Eq IP4 -> (Int -> IP4 -> Int) -> (IP4 -> Int) -> Hashable IP4
Int -> IP4 -> Int
IP4 -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: IP4 -> Int
$chash :: IP4 -> Int
hashWithSalt :: Int -> IP4 -> Int
$chashWithSalt :: Int -> IP4 -> Int
$cp1Hashable :: Eq IP4
Hashable)
anIP4 ∷ Proxy IP4
anIP4 :: Proxy IP4
anIP4 = Proxy IP4
forall k (t :: k). Proxy t
Proxy
instance Show IP4 where
showsPrec :: Int -> IP4 -> ShowS
showsPrec Int
p IP4
a = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10)
(ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ip4FromOctets "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word8
o1
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word8
o2
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word8
o3
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word8
o4
where (Word8
o1, Word8
o2, Word8
o3, Word8
o4) = IP4 -> (Word8, Word8, Word8, Word8)
ip4ToOctets IP4
a
instance Read IP4 where
readsPrec :: Int -> ReadS IP4
readsPrec Int
p = Bool -> ReadS IP4 -> ReadS IP4
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS IP4 -> ReadS IP4) -> ReadS IP4 -> ReadS IP4
forall a b. (a -> b) -> a -> b
$ \String
i →
[ (Word8 -> Word8 -> Word8 -> Word8 -> IP4
ip4FromOctets Word8
o1 Word8
o2 Word8
o3 Word8
o4, String
i4)
| (String
"ip4FromOctets", String
i') ← ReadS String
lex String
i
, (Word8
o1, String
i1) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i'
, (Word8
o2, String
i2) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i1
, (Word8
o3, String
i3) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i2
, (Word8
o4, String
i4) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i3 ]
instance Printable IP4 where
print :: IP4 -> p
print = p -> [p] -> p
forall (f :: * -> *) p. (Foldable f, Printer p) => p -> f p -> p
P.fsep (Char -> p
forall p. Printer p => Char -> p
P.char7 Char
'.') ([p] -> p) -> (IP4 -> [p]) -> IP4 -> p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Decimal -> Word8 -> p
forall s α p.
(PositionalSystem s, Integral α, Printer p) =>
s -> α -> p
P.nonNegative Decimal
Decimal (Word8 -> p) -> [Word8] -> [p]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) ([Word8] -> [p]) -> (IP4 -> [Word8]) -> IP4 -> [p]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IP4 -> [Word8]
ip4ToOctetList
{-# INLINE print #-}
instance Textual IP4 where
textual :: μ IP4
textual = (μ IP4 -> String -> μ IP4
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv4 address")
(μ IP4 -> μ IP4) -> μ IP4 -> μ IP4
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> IP4
ip4FromOctets
(Word8 -> Word8 -> Word8 -> Word8 -> IP4)
-> μ Word8 -> μ (Word8 -> Word8 -> Word8 -> IP4)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (μ Word8
octet μ Word8 -> μ Char -> μ Word8
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'.')
μ (Word8 -> Word8 -> Word8 -> IP4)
-> μ Word8 -> μ (Word8 -> Word8 -> IP4)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (μ Word8
octet μ Word8 -> μ Char -> μ Word8
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'.')
μ (Word8 -> Word8 -> IP4) -> μ Word8 -> μ (Word8 -> IP4)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (μ Word8
octet μ Word8 -> μ Char -> μ Word8
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'.')
μ (Word8 -> IP4) -> μ Word8 -> μ IP4
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> μ Word8
octet
where octet :: μ Word8
octet = (μ Word8 -> String -> μ Word8
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv4 octet") (μ Word8 -> μ Word8) -> μ Word8 -> μ Word8
forall a b. (a -> b) -> a -> b
$ do
Int
o ← Decimal -> Int -> μ Int
forall s α (μ :: * -> *).
(PositionalSystem s, Num α, Monad μ, CharParsing μ) =>
s -> Int -> μ α
nnUpTo Decimal
Decimal Int
3
if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
255
then String -> μ Word8
forall (m :: * -> *) a. Parsing m => String -> m a
D.unexpected String
"out of bounds"
else Word8 -> μ Word8
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8 -> μ Word8) -> Word8 -> μ Word8
forall a b. (a -> b) -> a -> b
$ Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
o ∷ Int)
instance Storable IP4 where
alignment :: IP4 -> Int
alignment IP4
_ = Word32 -> Int
forall a. Storable a => a -> Int
alignment (Word32
forall a. HasCallStack => a
undefined ∷ Word32)
sizeOf :: IP4 -> Int
sizeOf IP4
_ = Int
4
peek :: Ptr IP4 -> IO IP4
peek Ptr IP4
p = Word32 -> IP4
IP4 (Word32 -> IP4) -> (Word32 -> Word32) -> Word32 -> IP4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Word32
forall α. EndianSensitive α => α -> α
fromBigEndian (Word32 -> IP4) -> IO Word32 -> IO IP4
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek (Ptr IP4 -> Ptr Word32
forall a b. Ptr a -> Ptr b
castPtr Ptr IP4
p)
poke :: Ptr IP4 -> IP4 -> IO ()
poke Ptr IP4
p = Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr IP4 -> Ptr Word32
forall a b. Ptr a -> Ptr b
castPtr Ptr IP4
p) (Word32 -> IO ()) -> (IP4 -> Word32) -> IP4 -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Word32
forall α. EndianSensitive α => α -> α
toBigEndian (Word32 -> Word32) -> (IP4 -> Word32) -> IP4 -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IP4 -> Word32
unIP4
instance Serializable IP4 where
put :: IP4 -> s
put = Word32 -> s
forall s. Serializer s => Word32 -> s
S.word32B (Word32 -> s) -> (IP4 -> Word32) -> IP4 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IP4 -> Word32
unIP4
{-# INLINE put #-}
instance SizedSerializable IP4 where
size :: Proxy IP4 -> Int
size Proxy IP4
_ = Int
4
{-# INLINE size #-}
instance Deserializable IP4 where
get :: μ IP4
get = Word32 -> IP4
IP4 (Word32 -> IP4) -> μ Word32 -> μ IP4
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ Word32
forall (μ :: * -> *). Deserializer μ => μ Word32
D.word32B μ IP4 -> String -> μ IP4
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv4 address"
{-# INLINE get #-}
ip4ToOctets ∷ IP4 → (Word8, Word8, Word8, Word8)
ip4ToOctets :: IP4 -> (Word8, Word8, Word8, Word8)
ip4ToOctets (IP4 Word32
w) = ( Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Word8) -> Word32 -> Word8
forall a b. (a -> b) -> a -> b
$ Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
24
, Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Word8) -> Word32 -> Word8
forall a b. (a -> b) -> a -> b
$ Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
16
, Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Word8) -> Word32 -> Word8
forall a b. (a -> b) -> a -> b
$ Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
8
, Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
w
)
{-# INLINABLE ip4ToOctets #-}
ip4ToOctetList ∷ IP4 → [Word8]
ip4ToOctetList :: IP4 -> [Word8]
ip4ToOctetList (IP4 Word32
w) = Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Word8) -> [Word32] -> [Word8]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
[Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
24, Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
16, Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
8, Word32
w]
{-# INLINABLE ip4ToOctetList #-}
ip4FromOctets ∷ Word8 → Word8 → Word8 → Word8 → IP4
ip4FromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IP4
ip4FromOctets Word8
o1 Word8
o2 Word8
o3 Word8
o4 =
Word32 -> IP4
IP4 (Word32 -> IP4) -> Word32 -> IP4
forall a b. (a -> b) -> a -> b
$ Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
o1 Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
24
Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|. Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
o2 Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
16
Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|. Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
o3 Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
8
Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|. Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
o4
{-# INLINABLE ip4FromOctets #-}
ip4FromOctetList ∷ [Word8] → Maybe IP4
ip4FromOctetList :: [Word8] -> Maybe IP4
ip4FromOctetList [Word8
o1, Word8
o2, Word8
o3, Word8
o4] = IP4 -> Maybe IP4
forall a. a -> Maybe a
Just (IP4 -> Maybe IP4) -> IP4 -> Maybe IP4
forall a b. (a -> b) -> a -> b
$ Word8 -> Word8 -> Word8 -> Word8 -> IP4
ip4FromOctets Word8
o1 Word8
o2 Word8
o3 Word8
o4
ip4FromOctetList [Word8]
_ = Maybe IP4
forall a. Maybe a
Nothing
{-# INLINABLE ip4FromOctetList #-}
anyIP4 ∷ IP4
anyIP4 :: IP4
anyIP4 = Word32 -> IP4
IP4 Word32
0
{-# INLINE anyIP4 #-}
instance Default IP4 where
def :: IP4
def = IP4
anyIP4
{-# INLINE def #-}
loopbackIP4 ∷ IP4
loopbackIP4 :: IP4
loopbackIP4 = Word32 -> IP4
IP4 Word32
0x7F000001
{-# INLINE loopbackIP4 #-}
broadcastIP4 ∷ IP4
broadcastIP4 :: IP4
broadcastIP4 = Word32 -> IP4
IP4 Word32
0xFFFFFFFF
{-# INLINE broadcastIP4 #-}
data Range4 = GeneralIP4
| ThisHostIP4
| PrivateUseIP4
| SharedSpaceIP4
| LoopbackIP4
| LinkLocalIP4
| ReservedIP4
| DSLiteIP4
| DocumentationIP4
| IP6To4IP4
| BenchmarkingIP4
| MulticastIP4
| FutureUseIP4
| BroadcastIP4
deriving (Typeable, Typeable Range4
Constr
DataType
Typeable Range4
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range4 -> c Range4)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range4)
-> (Range4 -> Constr)
-> (Range4 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Range4))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range4))
-> ((forall b. Data b => b -> b) -> Range4 -> Range4)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Range4 -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Range4 -> r)
-> (forall u. (forall d. Data d => d -> u) -> Range4 -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Range4 -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4)
-> Data Range4
Range4 -> Constr
Range4 -> DataType
(forall b. Data b => b -> b) -> Range4 -> Range4
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range4 -> c Range4
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range4
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) -> Range4 -> u
forall u. (forall d. Data d => d -> u) -> Range4 -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Range4 -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Range4 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range4
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range4 -> c Range4
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Range4)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range4)
$cBroadcastIP4 :: Constr
$cFutureUseIP4 :: Constr
$cMulticastIP4 :: Constr
$cBenchmarkingIP4 :: Constr
$cIP6To4IP4 :: Constr
$cDocumentationIP4 :: Constr
$cDSLiteIP4 :: Constr
$cReservedIP4 :: Constr
$cLinkLocalIP4 :: Constr
$cLoopbackIP4 :: Constr
$cSharedSpaceIP4 :: Constr
$cPrivateUseIP4 :: Constr
$cThisHostIP4 :: Constr
$cGeneralIP4 :: Constr
$tRange4 :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Range4 -> m Range4
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4
gmapMp :: (forall d. Data d => d -> m d) -> Range4 -> m Range4
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4
gmapM :: (forall d. Data d => d -> m d) -> Range4 -> m Range4
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Range4 -> m Range4
gmapQi :: Int -> (forall d. Data d => d -> u) -> Range4 -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Range4 -> u
gmapQ :: (forall d. Data d => d -> u) -> Range4 -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Range4 -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Range4 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Range4 -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Range4 -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Range4 -> r
gmapT :: (forall b. Data b => b -> b) -> Range4 -> Range4
$cgmapT :: (forall b. Data b => b -> b) -> Range4 -> Range4
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range4)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range4)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Range4)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Range4)
dataTypeOf :: Range4 -> DataType
$cdataTypeOf :: Range4 -> DataType
toConstr :: Range4 -> Constr
$ctoConstr :: Range4 -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range4
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range4
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range4 -> c Range4
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range4 -> c Range4
$cp1Data :: Typeable Range4
Data, Int -> Range4 -> ShowS
[Range4] -> ShowS
Range4 -> String
(Int -> Range4 -> ShowS)
-> (Range4 -> String) -> ([Range4] -> ShowS) -> Show Range4
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Range4] -> ShowS
$cshowList :: [Range4] -> ShowS
show :: Range4 -> String
$cshow :: Range4 -> String
showsPrec :: Int -> Range4 -> ShowS
$cshowsPrec :: Int -> Range4 -> ShowS
Show, ReadPrec [Range4]
ReadPrec Range4
Int -> ReadS Range4
ReadS [Range4]
(Int -> ReadS Range4)
-> ReadS [Range4]
-> ReadPrec Range4
-> ReadPrec [Range4]
-> Read Range4
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Range4]
$creadListPrec :: ReadPrec [Range4]
readPrec :: ReadPrec Range4
$creadPrec :: ReadPrec Range4
readList :: ReadS [Range4]
$creadList :: ReadS [Range4]
readsPrec :: Int -> ReadS Range4
$creadsPrec :: Int -> ReadS Range4
Read, Range4 -> Range4 -> Bool
(Range4 -> Range4 -> Bool)
-> (Range4 -> Range4 -> Bool) -> Eq Range4
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Range4 -> Range4 -> Bool
$c/= :: Range4 -> Range4 -> Bool
== :: Range4 -> Range4 -> Bool
$c== :: Range4 -> Range4 -> Bool
Eq, Eq Range4
Eq Range4
-> (Range4 -> Range4 -> Ordering)
-> (Range4 -> Range4 -> Bool)
-> (Range4 -> Range4 -> Bool)
-> (Range4 -> Range4 -> Bool)
-> (Range4 -> Range4 -> Bool)
-> (Range4 -> Range4 -> Range4)
-> (Range4 -> Range4 -> Range4)
-> Ord Range4
Range4 -> Range4 -> Bool
Range4 -> Range4 -> Ordering
Range4 -> Range4 -> Range4
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 :: Range4 -> Range4 -> Range4
$cmin :: Range4 -> Range4 -> Range4
max :: Range4 -> Range4 -> Range4
$cmax :: Range4 -> Range4 -> Range4
>= :: Range4 -> Range4 -> Bool
$c>= :: Range4 -> Range4 -> Bool
> :: Range4 -> Range4 -> Bool
$c> :: Range4 -> Range4 -> Bool
<= :: Range4 -> Range4 -> Bool
$c<= :: Range4 -> Range4 -> Bool
< :: Range4 -> Range4 -> Bool
$c< :: Range4 -> Range4 -> Bool
compare :: Range4 -> Range4 -> Ordering
$ccompare :: Range4 -> Range4 -> Ordering
$cp1Ord :: Eq Range4
Ord, Int -> Range4
Range4 -> Int
Range4 -> [Range4]
Range4 -> Range4
Range4 -> Range4 -> [Range4]
Range4 -> Range4 -> Range4 -> [Range4]
(Range4 -> Range4)
-> (Range4 -> Range4)
-> (Int -> Range4)
-> (Range4 -> Int)
-> (Range4 -> [Range4])
-> (Range4 -> Range4 -> [Range4])
-> (Range4 -> Range4 -> [Range4])
-> (Range4 -> Range4 -> Range4 -> [Range4])
-> Enum Range4
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Range4 -> Range4 -> Range4 -> [Range4]
$cenumFromThenTo :: Range4 -> Range4 -> Range4 -> [Range4]
enumFromTo :: Range4 -> Range4 -> [Range4]
$cenumFromTo :: Range4 -> Range4 -> [Range4]
enumFromThen :: Range4 -> Range4 -> [Range4]
$cenumFromThen :: Range4 -> Range4 -> [Range4]
enumFrom :: Range4 -> [Range4]
$cenumFrom :: Range4 -> [Range4]
fromEnum :: Range4 -> Int
$cfromEnum :: Range4 -> Int
toEnum :: Int -> Range4
$ctoEnum :: Int -> Range4
pred :: Range4 -> Range4
$cpred :: Range4 -> Range4
succ :: Range4 -> Range4
$csucc :: Range4 -> Range4
Enum)
ip4Range ∷ IP4 → Range4
ip4Range :: IP4 -> Range4
ip4Range IP4
addr = case Word8
w1 of
Word8
0 → Range4
ThisHostIP4
Word8
10 → Range4
PrivateUseIP4
Word8
100 → if Word8
w2 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0xC0 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
0x40 then Range4
SharedSpaceIP4 else Range4
GeneralIP4
Word8
127 → Range4
LoopbackIP4
Word8
169 → if Word8
w2 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
254 then Range4
LinkLocalIP4 else Range4
GeneralIP4
Word8
172 → if Word8
w2 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0xF0 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
0x10 then Range4
PrivateUseIP4 else Range4
GeneralIP4
Word8
192 → case Word8
w2 of
Word8
0 → case Word8
w3 of
Word8
0 → if Word8
w4 Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
7 then Range4
DSLiteIP4 else Range4
ReservedIP4
Word8
2 → Range4
DocumentationIP4
Word8
_ → Range4
GeneralIP4
Word8
88 → if Word8
w3 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
99 then Range4
IP6To4IP4 else Range4
GeneralIP4
Word8
168 → Range4
PrivateUseIP4
Word8
_ → Range4
GeneralIP4
Word8
198 → case Word8
w2 of
Word8
18 → Range4
BenchmarkingIP4
Word8
19 → Range4
BenchmarkingIP4
Word8
51 → if Word8
w3 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
100 then Range4
DocumentationIP4 else Range4
GeneralIP4
Word8
_ → Range4
GeneralIP4
Word8
203 → if Word8
w2 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
0 Bool -> Bool -> Bool
&& Word8
w3 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
113 then Range4
DocumentationIP4 else Range4
GeneralIP4
Word8
_ | IP4
addr IP4 -> IP4 -> Bool
forall a. Eq a => a -> a -> Bool
== IP4
broadcastIP4 → Range4
BroadcastIP4
Word8
_ → case Word8
w1 Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0xF0 of
Word8
224 → Range4
MulticastIP4
Word8
240 → Range4
FutureUseIP4
Word8
_ → Range4
GeneralIP4
where (Word8
w1, Word8
w2, Word8
w3, Word8
w4) = IP4 -> (Word8, Word8, Word8, Word8)
ip4ToOctets IP4
addr
newtype IP6 = IP6 { IP6 -> Word128
unIP6 ∷ Word128 }
deriving (Typeable, Typeable IP6
Constr
DataType
Typeable IP6
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP6 -> c IP6)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP6)
-> (IP6 -> Constr)
-> (IP6 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IP6))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP6))
-> ((forall b. Data b => b -> b) -> IP6 -> IP6)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r)
-> (forall u. (forall d. Data d => d -> u) -> IP6 -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> IP6 -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6)
-> Data IP6
IP6 -> Constr
IP6 -> DataType
(forall b. Data b => b -> b) -> IP6 -> IP6
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP6 -> c IP6
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP6
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) -> IP6 -> u
forall u. (forall d. Data d => d -> u) -> IP6 -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP6
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP6 -> c IP6
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IP6)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP6)
$cIP6 :: Constr
$tIP6 :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> IP6 -> m IP6
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6
gmapMp :: (forall d. Data d => d -> m d) -> IP6 -> m IP6
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6
gmapM :: (forall d. Data d => d -> m d) -> IP6 -> m IP6
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP6 -> m IP6
gmapQi :: Int -> (forall d. Data d => d -> u) -> IP6 -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IP6 -> u
gmapQ :: (forall d. Data d => d -> u) -> IP6 -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IP6 -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IP6 -> r
gmapT :: (forall b. Data b => b -> b) -> IP6 -> IP6
$cgmapT :: (forall b. Data b => b -> b) -> IP6 -> IP6
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP6)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IP6)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c IP6)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IP6)
dataTypeOf :: IP6 -> DataType
$cdataTypeOf :: IP6 -> DataType
toConstr :: IP6 -> Constr
$ctoConstr :: IP6 -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP6
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IP6
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP6 -> c IP6
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP6 -> c IP6
$cp1Data :: Typeable IP6
Data, IP6 -> IP6 -> Bool
(IP6 -> IP6 -> Bool) -> (IP6 -> IP6 -> Bool) -> Eq IP6
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IP6 -> IP6 -> Bool
$c/= :: IP6 -> IP6 -> Bool
== :: IP6 -> IP6 -> Bool
$c== :: IP6 -> IP6 -> Bool
Eq, Eq IP6
Eq IP6
-> (IP6 -> IP6 -> Ordering)
-> (IP6 -> IP6 -> Bool)
-> (IP6 -> IP6 -> Bool)
-> (IP6 -> IP6 -> Bool)
-> (IP6 -> IP6 -> Bool)
-> (IP6 -> IP6 -> IP6)
-> (IP6 -> IP6 -> IP6)
-> Ord IP6
IP6 -> IP6 -> Bool
IP6 -> IP6 -> Ordering
IP6 -> IP6 -> IP6
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 :: IP6 -> IP6 -> IP6
$cmin :: IP6 -> IP6 -> IP6
max :: IP6 -> IP6 -> IP6
$cmax :: IP6 -> IP6 -> IP6
>= :: IP6 -> IP6 -> Bool
$c>= :: IP6 -> IP6 -> Bool
> :: IP6 -> IP6 -> Bool
$c> :: IP6 -> IP6 -> Bool
<= :: IP6 -> IP6 -> Bool
$c<= :: IP6 -> IP6 -> Bool
< :: IP6 -> IP6 -> Bool
$c< :: IP6 -> IP6 -> Bool
compare :: IP6 -> IP6 -> Ordering
$ccompare :: IP6 -> IP6 -> Ordering
$cp1Ord :: Eq IP6
Ord, IP6
IP6 -> IP6 -> Bounded IP6
forall a. a -> a -> Bounded a
maxBound :: IP6
$cmaxBound :: IP6
minBound :: IP6
$cminBound :: IP6
Bounded, Int -> IP6
IP6 -> Int
IP6 -> [IP6]
IP6 -> IP6
IP6 -> IP6 -> [IP6]
IP6 -> IP6 -> IP6 -> [IP6]
(IP6 -> IP6)
-> (IP6 -> IP6)
-> (Int -> IP6)
-> (IP6 -> Int)
-> (IP6 -> [IP6])
-> (IP6 -> IP6 -> [IP6])
-> (IP6 -> IP6 -> [IP6])
-> (IP6 -> IP6 -> IP6 -> [IP6])
-> Enum IP6
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: IP6 -> IP6 -> IP6 -> [IP6]
$cenumFromThenTo :: IP6 -> IP6 -> IP6 -> [IP6]
enumFromTo :: IP6 -> IP6 -> [IP6]
$cenumFromTo :: IP6 -> IP6 -> [IP6]
enumFromThen :: IP6 -> IP6 -> [IP6]
$cenumFromThen :: IP6 -> IP6 -> [IP6]
enumFrom :: IP6 -> [IP6]
$cenumFrom :: IP6 -> [IP6]
fromEnum :: IP6 -> Int
$cfromEnum :: IP6 -> Int
toEnum :: Int -> IP6
$ctoEnum :: Int -> IP6
pred :: IP6 -> IP6
$cpred :: IP6 -> IP6
succ :: IP6 -> IP6
$csucc :: IP6 -> IP6
Enum, Ord IP6
Ord IP6
-> ((IP6, IP6) -> [IP6])
-> ((IP6, IP6) -> IP6 -> Int)
-> ((IP6, IP6) -> IP6 -> Int)
-> ((IP6, IP6) -> IP6 -> Bool)
-> ((IP6, IP6) -> Int)
-> ((IP6, IP6) -> Int)
-> Ix IP6
(IP6, IP6) -> Int
(IP6, IP6) -> [IP6]
(IP6, IP6) -> IP6 -> Bool
(IP6, IP6) -> IP6 -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (IP6, IP6) -> Int
$cunsafeRangeSize :: (IP6, IP6) -> Int
rangeSize :: (IP6, IP6) -> Int
$crangeSize :: (IP6, IP6) -> Int
inRange :: (IP6, IP6) -> IP6 -> Bool
$cinRange :: (IP6, IP6) -> IP6 -> Bool
unsafeIndex :: (IP6, IP6) -> IP6 -> Int
$cunsafeIndex :: (IP6, IP6) -> IP6 -> Int
index :: (IP6, IP6) -> IP6 -> Int
$cindex :: (IP6, IP6) -> IP6 -> Int
range :: (IP6, IP6) -> [IP6]
$crange :: (IP6, IP6) -> [IP6]
$cp1Ix :: Ord IP6
Ix, Integer -> IP6
IP6 -> IP6
IP6 -> IP6 -> IP6
(IP6 -> IP6 -> IP6)
-> (IP6 -> IP6 -> IP6)
-> (IP6 -> IP6 -> IP6)
-> (IP6 -> IP6)
-> (IP6 -> IP6)
-> (IP6 -> IP6)
-> (Integer -> IP6)
-> Num IP6
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> IP6
$cfromInteger :: Integer -> IP6
signum :: IP6 -> IP6
$csignum :: IP6 -> IP6
abs :: IP6 -> IP6
$cabs :: IP6 -> IP6
negate :: IP6 -> IP6
$cnegate :: IP6 -> IP6
* :: IP6 -> IP6 -> IP6
$c* :: IP6 -> IP6 -> IP6
- :: IP6 -> IP6 -> IP6
$c- :: IP6 -> IP6 -> IP6
+ :: IP6 -> IP6 -> IP6
$c+ :: IP6 -> IP6 -> IP6
Num, Eq IP6
IP6
Eq IP6
-> (IP6 -> IP6 -> IP6)
-> (IP6 -> IP6 -> IP6)
-> (IP6 -> IP6 -> IP6)
-> (IP6 -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> IP6
-> (Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> Bool)
-> (IP6 -> Maybe Int)
-> (IP6 -> Int)
-> (IP6 -> Bool)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int -> IP6)
-> (IP6 -> Int)
-> Bits IP6
Int -> IP6
IP6 -> Bool
IP6 -> Int
IP6 -> Maybe Int
IP6 -> IP6
IP6 -> Int -> Bool
IP6 -> Int -> IP6
IP6 -> IP6 -> IP6
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
popCount :: IP6 -> Int
$cpopCount :: IP6 -> Int
rotateR :: IP6 -> Int -> IP6
$crotateR :: IP6 -> Int -> IP6
rotateL :: IP6 -> Int -> IP6
$crotateL :: IP6 -> Int -> IP6
unsafeShiftR :: IP6 -> Int -> IP6
$cunsafeShiftR :: IP6 -> Int -> IP6
shiftR :: IP6 -> Int -> IP6
$cshiftR :: IP6 -> Int -> IP6
unsafeShiftL :: IP6 -> Int -> IP6
$cunsafeShiftL :: IP6 -> Int -> IP6
shiftL :: IP6 -> Int -> IP6
$cshiftL :: IP6 -> Int -> IP6
isSigned :: IP6 -> Bool
$cisSigned :: IP6 -> Bool
bitSize :: IP6 -> Int
$cbitSize :: IP6 -> Int
bitSizeMaybe :: IP6 -> Maybe Int
$cbitSizeMaybe :: IP6 -> Maybe Int
testBit :: IP6 -> Int -> Bool
$ctestBit :: IP6 -> Int -> Bool
complementBit :: IP6 -> Int -> IP6
$ccomplementBit :: IP6 -> Int -> IP6
clearBit :: IP6 -> Int -> IP6
$cclearBit :: IP6 -> Int -> IP6
setBit :: IP6 -> Int -> IP6
$csetBit :: IP6 -> Int -> IP6
bit :: Int -> IP6
$cbit :: Int -> IP6
zeroBits :: IP6
$czeroBits :: IP6
rotate :: IP6 -> Int -> IP6
$crotate :: IP6 -> Int -> IP6
shift :: IP6 -> Int -> IP6
$cshift :: IP6 -> Int -> IP6
complement :: IP6 -> IP6
$ccomplement :: IP6 -> IP6
xor :: IP6 -> IP6 -> IP6
$cxor :: IP6 -> IP6 -> IP6
.|. :: IP6 -> IP6 -> IP6
$c.|. :: IP6 -> IP6 -> IP6
.&. :: IP6 -> IP6 -> IP6
$c.&. :: IP6 -> IP6 -> IP6
$cp1Bits :: Eq IP6
Bits, Eq IP6
Eq IP6 -> (Int -> IP6 -> Int) -> (IP6 -> Int) -> Hashable IP6
Int -> IP6 -> Int
IP6 -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: IP6 -> Int
$chash :: IP6 -> Int
hashWithSalt :: Int -> IP6 -> Int
$chashWithSalt :: Int -> IP6 -> Int
$cp1Hashable :: Eq IP6
Hashable)
anIP6 ∷ Proxy IP6
anIP6 :: Proxy IP6
anIP6 = Proxy IP6
forall k (t :: k). Proxy t
Proxy
instance Show IP6 where
showsPrec :: Int -> IP6 -> ShowS
showsPrec Int
p IP6
a
= Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10)
(ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString
(String -> ShowS) -> String -> ShowS
forall a b. (a -> b) -> a -> b
$ String
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> String
forall r. PrintfType r => String -> r
printf String
"ip6FromWords 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x"
Word16
w1 Word16
w2 Word16
w3 Word16
w4 Word16
w5 Word16
w6 Word16
w7 Word16
w8
where
(Word16
w1, Word16
w2, Word16
w3, Word16
w4, Word16
w5, Word16
w6, Word16
w7, Word16
w8) = IP6
-> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
ip6ToWords IP6
a
instance Read IP6 where
readsPrec :: Int -> ReadS IP6
readsPrec Int
p = Bool -> ReadS IP6 -> ReadS IP6
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS IP6 -> ReadS IP6) -> ReadS IP6 -> ReadS IP6
forall a b. (a -> b) -> a -> b
$ \String
i →
[ (Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> IP6
ip6FromWords Word16
w1 Word16
w2 Word16
w3 Word16
w4 Word16
w5 Word16
w6 Word16
w7 Word16
w8, String
i8)
| (String
"ip6FromWords", String
i') ← ReadS String
lex String
i
, (Word16
w1, String
i1) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i'
, (Word16
w2, String
i2) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i1
, (Word16
w3, String
i3) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i2
, (Word16
w4, String
i4) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i3
, (Word16
w5, String
i5) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i4
, (Word16
w6, String
i6) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i5
, (Word16
w7, String
i7) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i6
, (Word16
w8, String
i8) ← Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i7 ]
instance Printable IP6 where
print :: IP6 -> p
print IP6
addr = case Maybe (Int, Int)
addrZeroes of
Maybe (Int, Int)
Nothing → p -> [p] -> p
forall (f :: * -> *) p. (Foldable f, Printer p) => p -> f p -> p
P.fsep (Char -> p
forall p. Printer p => Char -> p
P.char7 Char
':') ([p] -> p) -> [p] -> p
forall a b. (a -> b) -> a -> b
$ Word16 -> p
hex (Word16 -> p) -> [Word16] -> [p]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Word16]
addrWords
Just (Int
i, Int
n) → p -> [p] -> p
forall (f :: * -> *) p. (Foldable f, Printer p) => p -> f p -> p
P.fsep (Char -> p
forall p. Printer p => Char -> p
P.char7 Char
':') (Word16 -> p
hex (Word16 -> p) -> [Word16] -> [p]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [Word16] -> [Word16]
forall a. Int -> [a] -> [a]
take Int
i [Word16]
addrWords)
p -> p -> p
forall a. Semigroup a => a -> a -> a
<> String -> p
forall p. Printer p => String -> p
P.string7 String
"::"
p -> p -> p
forall a. Semigroup a => a -> a -> a
<> p -> [p] -> p
forall (f :: * -> *) p. (Foldable f, Printer p) => p -> f p -> p
P.fsep (Char -> p
forall p. Printer p => Char -> p
P.char7 Char
':') (Word16 -> p
hex (Word16 -> p) -> [Word16] -> [p]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [Word16] -> [Word16]
forall a. Int -> [a] -> [a]
drop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) [Word16]
addrWords)
where hex :: Word16 -> p
hex = LowHex -> Word16 -> p
forall s α p.
(PositionalSystem s, Integral α, Printer p) =>
s -> α -> p
P.nonNegative LowHex
LowHex
addrWords :: [Word16]
addrWords = IP6 -> [Word16]
ip6ToWordList IP6
addr
addrZeroes :: Maybe (Int, Int)
addrZeroes = Int -> Int -> Int -> [Word16] -> Maybe (Int, Int)
forall a a a.
(Ord a, Num a, Num a, Num a, Eq a) =>
a -> a -> a -> [a] -> Maybe (a, a)
go Int
0 Int
0 Int
0 [Word16]
addrWords
go :: a -> a -> a -> [a] -> Maybe (a, a)
go !a
i a
zi a
zn = \case
[] → if a
zn a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 then Maybe (a, a)
forall a. Maybe a
Nothing else (a, a) -> Maybe (a, a)
forall a. a -> Maybe a
Just (a
zi, a
zn)
(a
0 : [a]
words') → a -> a -> a -> a -> a -> [a] -> Maybe (a, a)
inZeroes (a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) a
zi a
zn a
i a
1 [a]
words'
(a
_ : [a]
words') → a -> a -> a -> [a] -> Maybe (a, a)
go (a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) a
zi a
zn [a]
words'
inZeroes :: a -> a -> a -> a -> a -> [a] -> Maybe (a, a)
inZeroes !a
i a
zi a
zn a
zi' !a
zn' = \case
[] | a
zn' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 → if a
zn a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 then Maybe (a, a)
forall a. Maybe a
Nothing else (a, a) -> Maybe (a, a)
forall a. a -> Maybe a
Just (a
zi, a
zn)
| a
zn a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 → (a, a) -> Maybe (a, a)
forall a. a -> Maybe a
Just (a
zi', a
zn')
| Bool
otherwise → (a, a) -> Maybe (a, a)
forall a. a -> Maybe a
Just ((a, a) -> Maybe (a, a)) -> (a, a) -> Maybe (a, a)
forall a b. (a -> b) -> a -> b
$ if a
zn a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
zn' then (a
zi, a
zn) else (a
zi', a
zn')
(a
0 : [a]
words') → a -> a -> a -> a -> a -> [a] -> Maybe (a, a)
inZeroes (a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) a
zi a
zn a
zi' (a
zn' a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) [a]
words'
(a
_ : [a]
words') | a
zn' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
zn → a -> a -> a -> [a] -> Maybe (a, a)
go (a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) a
zi' a
zn' [a]
words'
| Bool
otherwise → a -> a -> a -> [a] -> Maybe (a, a)
go (a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) a
zi a
zn [a]
words'
instance Textual IP6 where
textual :: μ IP6
textual = (μ IP6 -> String -> μ IP6
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv6 address") (μ IP6 -> μ IP6) -> μ IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ μ Char -> μ (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':') μ (Maybe Char) -> (Maybe Char -> μ IP6) -> μ IP6
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Char
_ → do
μ Char -> μ ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (μ Char -> μ ()) -> μ Char -> μ ()
forall a b. (a -> b) -> a -> b
$ Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':'
μ Word16 -> μ (Maybe Word16)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional μ Word16
word μ (Maybe Word16) -> (Maybe Word16 -> μ IP6) -> μ IP6
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Word16
w → Int -> Word128 -> Word128 -> μ IP6
after Int
6 Word128
0 (Word16 -> Word128
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)
Maybe Word16
Nothing → IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return IP6
anyIP6
Maybe Char
Nothing → do
Word16
w ← μ Word16
word
Int -> Word128 -> μ IP6
before Int
7 (Word16 -> Word128
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)
where
word :: μ Word16
word = Hexadecimal -> Int -> μ Word16
forall s α (μ :: * -> *).
(PositionalSystem s, Num α, Monad μ, CharParsing μ) =>
s -> Int -> μ α
nnUpTo Hexadecimal
Hexadecimal Int
4 μ Word16 -> Proxy Word16 -> μ Word16
forall (f :: * -> *) α (p :: * -> *). f α -> p α -> f α
`hintTypeArg` Proxy Word16
aWord16 μ Word16 -> String -> μ Word16
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"word"
before :: Int -> Word128 -> μ IP6
before Int
0 Word128
w = IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return (IP6 -> μ IP6) -> IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 Word128
w
before Int
1 Word128
w = do
μ Char -> μ ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (μ Char -> μ ()) -> μ Char -> μ ()
forall a b. (a -> b) -> a -> b
$ Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':'
μ Char -> μ (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':') μ (Maybe Char) -> (Maybe Char -> μ IP6) -> μ IP6
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Char
_ →
IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return (IP6 -> μ IP6) -> IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ Word128
w Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` Int
16
Maybe Char
Nothing → do
Word16
w' ← μ Word16
word
IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return (IP6 -> μ IP6) -> IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ (Word128
w Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` Int
16) Word128 -> Word128 -> Word128
forall a. Bits a => a -> a -> a
.|. Word16 -> Word128
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w'
before Int
upTo Word128
w = do
μ Char -> μ ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (μ Char -> μ ()) -> μ Char -> μ ()
forall a b. (a -> b) -> a -> b
$ Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':'
μ Char -> μ (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':') μ (Maybe Char) -> (Maybe Char -> μ IP6) -> μ IP6
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Char
_ → μ Word16 -> μ (Maybe Word16)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional μ Word16
word μ (Maybe Word16) -> (Maybe Word16 -> μ IP6) -> μ IP6
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Word16
w' →
Int -> Word128 -> Word128 -> μ IP6
after (Int
upTo Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2) (Word128
w Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` (Int
upTo Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
16)) (Word16 -> Word128
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w')
Maybe Word16
Nothing →
IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return (IP6 -> μ IP6) -> IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ Word128
w Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` (Int
upTo Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
16)
Maybe Char
Nothing → do
Word16
w' ← μ Word16
word
Int -> Word128 -> μ IP6
before (Int
upTo Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ((Word128
w Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` Int
16) Word128 -> Word128 -> Word128
forall a. Bits a => a -> a -> a
.|. Word16 -> Word128
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w')
after :: Int -> Word128 -> Word128 -> μ IP6
after Int
0 Word128
w1 Word128
w2 = IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return (IP6 -> μ IP6) -> IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ Word128
w1 Word128 -> Word128 -> Word128
forall a. Bits a => a -> a -> a
.|. Word128
w2
after Int
upTo Word128
w1 Word128
w2 = μ Char -> μ (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':') μ (Maybe Char) -> (Maybe Char -> μ IP6) -> μ IP6
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Char
_ → do
Word16
w ← μ Word16
word
Int -> Word128 -> Word128 -> μ IP6
after (Int
upTo Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Word128
w1 ((Word128
w2 Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` Int
16) Word128 -> Word128 -> Word128
forall a. Bits a => a -> a -> a
.|. Word16 -> Word128
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)
Maybe Char
Nothing →
IP6 -> μ IP6
forall (m :: * -> *) a. Monad m => a -> m a
return (IP6 -> μ IP6) -> IP6 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ Word128
w1 Word128 -> Word128 -> Word128
forall a. Bits a => a -> a -> a
.|. Word128
w2
instance Storable IP6 where
alignment :: IP6 -> Int
alignment IP6
_ = Word64 -> Int
forall a. Storable a => a -> Int
alignment (Word64
forall a. HasCallStack => a
undefined ∷ Word64)
sizeOf :: IP6 -> Int
sizeOf IP6
_ = Int
16
peek :: Ptr IP6 -> IO IP6
peek Ptr IP6
p = (Word128 -> IP6) -> IO Word128 -> IO IP6
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word128 -> IP6
IP6
(IO Word128 -> IO IP6) -> IO Word128 -> IO IP6
forall a b. (a -> b) -> a -> b
$ Word64 -> Word64 -> Word128
forall w. DoubleWord w => HiWord w -> LoWord w -> w
fromHiAndLo (Word64 -> Word64 -> Word128)
-> IO Word64 -> IO (Word64 -> Word128)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word64 -> Word64
forall α. EndianSensitive α => α -> α
fromBigEndian (Word64 -> Word64) -> IO Word64 -> IO Word64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek (Ptr IP6 -> Ptr Word64
forall a b. Ptr a -> Ptr b
castPtr Ptr IP6
p))
IO (Word64 -> Word128) -> IO Word64 -> IO Word128
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Word64 -> Word64
forall α. EndianSensitive α => α -> α
fromBigEndian (Word64 -> Word64) -> IO Word64 -> IO Word64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek (Ptr IP6 -> Ptr Word64
forall a b. Ptr a -> Ptr b
castPtr Ptr IP6
p))
poke :: Ptr IP6 -> IP6 -> IO ()
poke Ptr IP6
p (IP6 Word128
w) = do
Ptr Word64 -> Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr IP6 -> Ptr Word64
forall a b. Ptr a -> Ptr b
castPtr Ptr IP6
p) (Word64 -> IO ()) -> Word64 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word64 -> Word64
forall α. EndianSensitive α => α -> α
toBigEndian (Word64 -> Word64) -> Word64 -> Word64
forall a b. (a -> b) -> a -> b
$ Word128 -> HiWord Word128
forall w. DoubleWord w => w -> HiWord w
hiWord Word128
w
Ptr Word64 -> Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr IP6 -> Ptr Word64
forall a b. Ptr a -> Ptr b
castPtr Ptr IP6
p) (Word64 -> IO ()) -> Word64 -> IO ()
forall a b. (a -> b) -> a -> b
$ Word64 -> Word64
forall α. EndianSensitive α => α -> α
toBigEndian (Word64 -> Word64) -> Word64 -> Word64
forall a b. (a -> b) -> a -> b
$ Word128 -> LoWord Word128
forall w. DoubleWord w => w -> LoWord w
loWord Word128
w
instance Serializable IP6 where
put :: IP6 -> s
put (IP6 Word128
w) = Word64 -> s
forall s. Serializer s => Word64 -> s
S.word64B (Word128 -> HiWord Word128
forall w. DoubleWord w => w -> HiWord w
hiWord Word128
w) s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word64 -> s
forall s. Serializer s => Word64 -> s
S.word64B (Word128 -> LoWord Word128
forall w. DoubleWord w => w -> LoWord w
loWord Word128
w)
{-# INLINE put #-}
instance SizedSerializable IP6 where
size :: Proxy IP6 -> Int
size Proxy IP6
_ = Int
16
{-# INLINE size #-}
instance Deserializable IP6 where
get :: μ IP6
get = (Word128 -> IP6) -> μ Word128 -> μ IP6
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word128 -> IP6
IP6 (μ Word128 -> μ IP6) -> μ Word128 -> μ IP6
forall a b. (a -> b) -> a -> b
$ Word64 -> Word64 -> Word128
forall w. DoubleWord w => HiWord w -> LoWord w -> w
fromHiAndLo (Word64 -> Word64 -> Word128) -> μ Word64 -> μ (Word64 -> Word128)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ Word64
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get μ (Word64 -> Word128) -> μ Word64 -> μ Word128
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> μ Word64
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get μ Word128 -> String -> μ Word128
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv6 address"
ip6ToWords ∷ IP6 → (Word16, Word16, Word16, Word16,
Word16, Word16, Word16, Word16)
ip6ToWords :: IP6
-> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
ip6ToWords (IP6 Word128
w) =
( Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> Word64 -> Word16
forall a b. (a -> b) -> a -> b
$ Word64
HiWord Word128
hi Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
48
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> Word64 -> Word16
forall a b. (a -> b) -> a -> b
$ Word64
HiWord Word128
hi Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
32
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> Word64 -> Word16
forall a b. (a -> b) -> a -> b
$ Word64
HiWord Word128
hi Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
16
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
HiWord Word128
hi
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> Word64 -> Word16
forall a b. (a -> b) -> a -> b
$ Word64
LoWord Word128
lo Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
48
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> Word64 -> Word16
forall a b. (a -> b) -> a -> b
$ Word64
LoWord Word128
lo Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
32
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> Word64 -> Word16
forall a b. (a -> b) -> a -> b
$ Word64
LoWord Word128
lo Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
16
, Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
LoWord Word128
lo
)
where hi :: HiWord Word128
hi = Word128 -> HiWord Word128
forall w. DoubleWord w => w -> HiWord w
hiWord Word128
w
lo :: LoWord Word128
lo = Word128 -> LoWord Word128
forall w. DoubleWord w => w -> LoWord w
loWord Word128
w
{-# INLINABLE ip6ToWords #-}
ip6ToWordList ∷ IP6 → [Word16]
ip6ToWordList :: IP6 -> [Word16]
ip6ToWordList (IP6 Word128
w) = Word64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word16) -> [Word64] -> [Word16]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
[ Word64
HiWord Word128
hi Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
48
, Word64
HiWord Word128
hi Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
32
, Word64
HiWord Word128
hi Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
16
, Word64
HiWord Word128
hi
, Word64
LoWord Word128
lo Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
48
, Word64
LoWord Word128
lo Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
32
, Word64
LoWord Word128
lo Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
16
, Word64
LoWord Word128
lo
]
where hi :: HiWord Word128
hi = Word128 -> HiWord Word128
forall w. DoubleWord w => w -> HiWord w
hiWord Word128
w
lo :: LoWord Word128
lo = Word128 -> LoWord Word128
forall w. DoubleWord w => w -> LoWord w
loWord Word128
w
{-# INLINABLE ip6ToWordList #-}
ip6FromWords ∷ Word16 → Word16 → Word16 → Word16
→ Word16 → Word16 → Word16 → Word16
→ IP6
ip6FromWords :: Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> IP6
ip6FromWords Word16
w1 Word16
w2 Word16
w3 Word16
w4 Word16
w5 Word16
w6 Word16
w7 Word16
w8 = Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ HiWord Word128 -> LoWord Word128 -> Word128
forall w. DoubleWord w => HiWord w -> LoWord w -> w
fromHiAndLo Word64
HiWord Word128
hi Word64
LoWord Word128
lo
where hi :: Word64
hi = Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w1 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
48
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w2 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
32
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w3 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
16
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w4
lo :: Word64
lo = Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w5 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
48
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w6 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
32
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w7 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
16
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w8
{-# INLINABLE ip6FromWords #-}
ip6FromWordList ∷ [Word16] → Maybe IP6
ip6FromWordList :: [Word16] -> Maybe IP6
ip6FromWordList [Word16
w1, Word16
w2, Word16
w3, Word16
w4, Word16
w5, Word16
w6, Word16
w7, Word16
w8] =
IP6 -> Maybe IP6
forall a. a -> Maybe a
Just (IP6 -> Maybe IP6) -> IP6 -> Maybe IP6
forall a b. (a -> b) -> a -> b
$ Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> Word16
-> IP6
ip6FromWords Word16
w1 Word16
w2 Word16
w3 Word16
w4 Word16
w5 Word16
w6 Word16
w7 Word16
w8
ip6FromWordList [Word16]
_ = Maybe IP6
forall a. Maybe a
Nothing
{-# INLINABLE ip6FromWordList #-}
anyIP6 ∷ IP6
anyIP6 :: IP6
anyIP6 = Word128 -> IP6
IP6 Word128
0
{-# INLINE anyIP6 #-}
instance Default IP6 where
def :: IP6
def = IP6
anyIP6
{-# INLINE def #-}
loopbackIP6 ∷ IP6
loopbackIP6 :: IP6
loopbackIP6 = Word128 -> IP6
IP6 Word128
1
data Range6 = GeneralIP6
| AnyIP6
| LoopbackIP6
| IP4MappedIP6
| IP4EmbeddedIP6
| DiscardIP6
| ReservedIP6
| TeredoIP6
| BenchmarkingIP6
| DocumentationIP6
| OrchidIP6
| IP6To4IP6
| UniqueLocalIP6
| LinkLocalIP6
| MulticastIP6
deriving (Typeable, Typeable Range6
Constr
DataType
Typeable Range6
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range6 -> c Range6)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range6)
-> (Range6 -> Constr)
-> (Range6 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Range6))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range6))
-> ((forall b. Data b => b -> b) -> Range6 -> Range6)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Range6 -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Range6 -> r)
-> (forall u. (forall d. Data d => d -> u) -> Range6 -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Range6 -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6)
-> Data Range6
Range6 -> Constr
Range6 -> DataType
(forall b. Data b => b -> b) -> Range6 -> Range6
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range6 -> c Range6
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range6
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) -> Range6 -> u
forall u. (forall d. Data d => d -> u) -> Range6 -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Range6 -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Range6 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range6
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range6 -> c Range6
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Range6)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range6)
$cMulticastIP6 :: Constr
$cLinkLocalIP6 :: Constr
$cUniqueLocalIP6 :: Constr
$cIP6To4IP6 :: Constr
$cOrchidIP6 :: Constr
$cDocumentationIP6 :: Constr
$cBenchmarkingIP6 :: Constr
$cTeredoIP6 :: Constr
$cReservedIP6 :: Constr
$cDiscardIP6 :: Constr
$cIP4EmbeddedIP6 :: Constr
$cIP4MappedIP6 :: Constr
$cLoopbackIP6 :: Constr
$cAnyIP6 :: Constr
$cGeneralIP6 :: Constr
$tRange6 :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Range6 -> m Range6
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6
gmapMp :: (forall d. Data d => d -> m d) -> Range6 -> m Range6
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6
gmapM :: (forall d. Data d => d -> m d) -> Range6 -> m Range6
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Range6 -> m Range6
gmapQi :: Int -> (forall d. Data d => d -> u) -> Range6 -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Range6 -> u
gmapQ :: (forall d. Data d => d -> u) -> Range6 -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Range6 -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Range6 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Range6 -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Range6 -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Range6 -> r
gmapT :: (forall b. Data b => b -> b) -> Range6 -> Range6
$cgmapT :: (forall b. Data b => b -> b) -> Range6 -> Range6
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range6)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Range6)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Range6)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Range6)
dataTypeOf :: Range6 -> DataType
$cdataTypeOf :: Range6 -> DataType
toConstr :: Range6 -> Constr
$ctoConstr :: Range6 -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range6
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Range6
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range6 -> c Range6
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Range6 -> c Range6
$cp1Data :: Typeable Range6
Data, Int -> Range6 -> ShowS
[Range6] -> ShowS
Range6 -> String
(Int -> Range6 -> ShowS)
-> (Range6 -> String) -> ([Range6] -> ShowS) -> Show Range6
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Range6] -> ShowS
$cshowList :: [Range6] -> ShowS
show :: Range6 -> String
$cshow :: Range6 -> String
showsPrec :: Int -> Range6 -> ShowS
$cshowsPrec :: Int -> Range6 -> ShowS
Show, ReadPrec [Range6]
ReadPrec Range6
Int -> ReadS Range6
ReadS [Range6]
(Int -> ReadS Range6)
-> ReadS [Range6]
-> ReadPrec Range6
-> ReadPrec [Range6]
-> Read Range6
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Range6]
$creadListPrec :: ReadPrec [Range6]
readPrec :: ReadPrec Range6
$creadPrec :: ReadPrec Range6
readList :: ReadS [Range6]
$creadList :: ReadS [Range6]
readsPrec :: Int -> ReadS Range6
$creadsPrec :: Int -> ReadS Range6
Read, Range6 -> Range6 -> Bool
(Range6 -> Range6 -> Bool)
-> (Range6 -> Range6 -> Bool) -> Eq Range6
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Range6 -> Range6 -> Bool
$c/= :: Range6 -> Range6 -> Bool
== :: Range6 -> Range6 -> Bool
$c== :: Range6 -> Range6 -> Bool
Eq, Eq Range6
Eq Range6
-> (Range6 -> Range6 -> Ordering)
-> (Range6 -> Range6 -> Bool)
-> (Range6 -> Range6 -> Bool)
-> (Range6 -> Range6 -> Bool)
-> (Range6 -> Range6 -> Bool)
-> (Range6 -> Range6 -> Range6)
-> (Range6 -> Range6 -> Range6)
-> Ord Range6
Range6 -> Range6 -> Bool
Range6 -> Range6 -> Ordering
Range6 -> Range6 -> Range6
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 :: Range6 -> Range6 -> Range6
$cmin :: Range6 -> Range6 -> Range6
max :: Range6 -> Range6 -> Range6
$cmax :: Range6 -> Range6 -> Range6
>= :: Range6 -> Range6 -> Bool
$c>= :: Range6 -> Range6 -> Bool
> :: Range6 -> Range6 -> Bool
$c> :: Range6 -> Range6 -> Bool
<= :: Range6 -> Range6 -> Bool
$c<= :: Range6 -> Range6 -> Bool
< :: Range6 -> Range6 -> Bool
$c< :: Range6 -> Range6 -> Bool
compare :: Range6 -> Range6 -> Ordering
$ccompare :: Range6 -> Range6 -> Ordering
$cp1Ord :: Eq Range6
Ord, Int -> Range6
Range6 -> Int
Range6 -> [Range6]
Range6 -> Range6
Range6 -> Range6 -> [Range6]
Range6 -> Range6 -> Range6 -> [Range6]
(Range6 -> Range6)
-> (Range6 -> Range6)
-> (Int -> Range6)
-> (Range6 -> Int)
-> (Range6 -> [Range6])
-> (Range6 -> Range6 -> [Range6])
-> (Range6 -> Range6 -> [Range6])
-> (Range6 -> Range6 -> Range6 -> [Range6])
-> Enum Range6
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Range6 -> Range6 -> Range6 -> [Range6]
$cenumFromThenTo :: Range6 -> Range6 -> Range6 -> [Range6]
enumFromTo :: Range6 -> Range6 -> [Range6]
$cenumFromTo :: Range6 -> Range6 -> [Range6]
enumFromThen :: Range6 -> Range6 -> [Range6]
$cenumFromThen :: Range6 -> Range6 -> [Range6]
enumFrom :: Range6 -> [Range6]
$cenumFrom :: Range6 -> [Range6]
fromEnum :: Range6 -> Int
$cfromEnum :: Range6 -> Int
toEnum :: Int -> Range6
$ctoEnum :: Int -> Range6
pred :: Range6 -> Range6
$cpred :: Range6 -> Range6
succ :: Range6 -> Range6
$csucc :: Range6 -> Range6
Enum)
ip6Range ∷ IP6 → Range6
ip6Range :: IP6 -> Range6
ip6Range (IP6 Word128
w) = case HiWord Word128
hi of
HiWord Word128
0 → case LoWord Word128
lo of
LoWord Word128
0 → Range6
AnyIP6
LoWord Word128
1 → Range6
LoopbackIP6
LoWord Word128
_ → Range6
GeneralIP6
HiWord Word128
0x000000000000FFFF → if Word32
HiWord Word64
q3 Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0 then Range6
IP4MappedIP6 else Range6
GeneralIP6
HiWord Word128
0x0064FF9B00000000 → if Word32
HiWord Word64
q3 Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
0 then Range6
IP4EmbeddedIP6 else Range6
GeneralIP6
HiWord Word128
0x0100000000000000 → Range6
DiscardIP6
HiWord Word128
_ → case HiWord Word32
w1 of
HiWord Word32
0x2001 → case LoWord Word32
w2 of
LoWord Word32
0 → Range6
TeredoIP6
LoWord Word32
2 → if Word16
HiWord Word32
w3 Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
0 then Range6
BenchmarkingIP6 else Range6
GeneralIP6
LoWord Word32
0xDB8 → Range6
DocumentationIP6
LoWord Word32
_ | Word16
LoWord Word32
w2 Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0xFFF0 Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
0x10 → Range6
OrchidIP6
| Word16
LoWord Word32
w2 Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0xFE00 Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
0 → Range6
ReservedIP6
| Bool
otherwise → Range6
GeneralIP6
HiWord Word32
0x2002 → Range6
IP6To4IP6
HiWord Word32
_ | Word16
HiWord Word32
w1 Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0xFE00 Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
0xFC00 → Range6
UniqueLocalIP6
| Word16
HiWord Word32
w1 Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0xFFC0 Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
0xFE80 → Range6
LinkLocalIP6
| Word16
HiWord Word32
w1 Word16 -> Word16 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word16
0xFF00 → Range6
MulticastIP6
| Bool
otherwise → Range6
GeneralIP6
where hi :: HiWord Word128
hi = Word128 -> HiWord Word128
forall w. DoubleWord w => w -> HiWord w
hiWord Word128
w
lo :: LoWord Word128
lo = Word128 -> LoWord Word128
forall w. DoubleWord w => w -> LoWord w
loWord Word128
w
q1 :: HiWord Word64
q1 = Word64 -> HiWord Word64
forall w. DoubleWord w => w -> HiWord w
hiWord Word64
HiWord Word128
hi
q2 :: LoWord Word64
q2 = Word64 -> LoWord Word64
forall w. DoubleWord w => w -> LoWord w
loWord Word64
HiWord Word128
hi
q3 :: HiWord Word64
q3 = Word64 -> HiWord Word64
forall w. DoubleWord w => w -> HiWord w
hiWord Word64
LoWord Word128
lo
w1 :: HiWord Word32
w1 = Word32 -> HiWord Word32
forall w. DoubleWord w => w -> HiWord w
hiWord Word32
HiWord Word64
q1
w2 :: LoWord Word32
w2 = Word32 -> LoWord Word32
forall w. DoubleWord w => w -> LoWord w
loWord Word32
HiWord Word64
q1
w3 :: HiWord Word32
w3 = Word32 -> HiWord Word32
forall w. DoubleWord w => w -> HiWord w
hiWord Word32
LoWord Word64
q2
data IP46 t₄ t₆ = IPv4 t₄
| IPv6 t₆
deriving (Typeable, Typeable (IP46 t₄ t₆)
Constr
DataType
Typeable (IP46 t₄ t₆)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP46 t₄ t₆ -> c (IP46 t₄ t₆))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IP46 t₄ t₆))
-> (IP46 t₄ t₆ -> Constr)
-> (IP46 t₄ t₆ -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (IP46 t₄ t₆)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IP46 t₄ t₆)))
-> ((forall b. Data b => b -> b) -> IP46 t₄ t₆ -> IP46 t₄ t₆)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r)
-> (forall u. (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆))
-> Data (IP46 t₄ t₆)
IP46 t₄ t₆ -> Constr
IP46 t₄ t₆ -> DataType
(forall b. Data b => b -> b) -> IP46 t₄ t₆ -> IP46 t₄ t₆
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP46 t₄ t₆ -> c (IP46 t₄ t₆)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IP46 t₄ t₆)
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IP46 t₄ t₆))
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) -> IP46 t₄ t₆ -> u
forall u. (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> [u]
forall t₄ t₆. (Data t₄, Data t₆) => Typeable (IP46 t₄ t₆)
forall t₄ t₆. (Data t₄, Data t₆) => IP46 t₄ t₆ -> Constr
forall t₄ t₆. (Data t₄, Data t₆) => IP46 t₄ t₆ -> DataType
forall t₄ t₆.
(Data t₄, Data t₆) =>
(forall b. Data b => b -> b) -> IP46 t₄ t₆ -> IP46 t₄ t₆
forall t₄ t₆ u.
(Data t₄, Data t₆) =>
Int -> (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> u
forall t₄ t₆ u.
(Data t₄, Data t₆) =>
(forall d. Data d => d -> u) -> IP46 t₄ t₆ -> [u]
forall t₄ t₆ r r'.
(Data t₄, Data t₆) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
forall t₄ t₆ r r'.
(Data t₄, Data t₆) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
forall t₄ t₆ (m :: * -> *).
(Data t₄, Data t₆, Monad m) =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
forall t₄ t₆ (m :: * -> *).
(Data t₄, Data t₆, MonadPlus m) =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
forall t₄ t₆ (c :: * -> *).
(Data t₄, Data t₆) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IP46 t₄ t₆)
forall t₄ t₆ (c :: * -> *).
(Data t₄, Data t₆) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP46 t₄ t₆ -> c (IP46 t₄ t₆)
forall t₄ t₆ (t :: * -> *) (c :: * -> *).
(Data t₄, Data t₆, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (IP46 t₄ t₆))
forall t₄ t₆ (t :: * -> * -> *) (c :: * -> *).
(Data t₄, Data t₆, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IP46 t₄ t₆))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IP46 t₄ t₆)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP46 t₄ t₆ -> c (IP46 t₄ t₆)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (IP46 t₄ t₆))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IP46 t₄ t₆))
$cIPv6 :: Constr
$cIPv4 :: Constr
$tIP46 :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
$cgmapMo :: forall t₄ t₆ (m :: * -> *).
(Data t₄, Data t₆, MonadPlus m) =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
gmapMp :: (forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
$cgmapMp :: forall t₄ t₆ (m :: * -> *).
(Data t₄, Data t₆, MonadPlus m) =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
gmapM :: (forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
$cgmapM :: forall t₄ t₆ (m :: * -> *).
(Data t₄, Data t₆, Monad m) =>
(forall d. Data d => d -> m d) -> IP46 t₄ t₆ -> m (IP46 t₄ t₆)
gmapQi :: Int -> (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> u
$cgmapQi :: forall t₄ t₆ u.
(Data t₄, Data t₆) =>
Int -> (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> u
gmapQ :: (forall d. Data d => d -> u) -> IP46 t₄ t₆ -> [u]
$cgmapQ :: forall t₄ t₆ u.
(Data t₄, Data t₆) =>
(forall d. Data d => d -> u) -> IP46 t₄ t₆ -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
$cgmapQr :: forall t₄ t₆ r r'.
(Data t₄, Data t₆) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
$cgmapQl :: forall t₄ t₆ r r'.
(Data t₄, Data t₆) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IP46 t₄ t₆ -> r
gmapT :: (forall b. Data b => b -> b) -> IP46 t₄ t₆ -> IP46 t₄ t₆
$cgmapT :: forall t₄ t₆.
(Data t₄, Data t₆) =>
(forall b. Data b => b -> b) -> IP46 t₄ t₆ -> IP46 t₄ t₆
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IP46 t₄ t₆))
$cdataCast2 :: forall t₄ t₆ (t :: * -> * -> *) (c :: * -> *).
(Data t₄, Data t₆, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IP46 t₄ t₆))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (IP46 t₄ t₆))
$cdataCast1 :: forall t₄ t₆ (t :: * -> *) (c :: * -> *).
(Data t₄, Data t₆, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (IP46 t₄ t₆))
dataTypeOf :: IP46 t₄ t₆ -> DataType
$cdataTypeOf :: forall t₄ t₆. (Data t₄, Data t₆) => IP46 t₄ t₆ -> DataType
toConstr :: IP46 t₄ t₆ -> Constr
$ctoConstr :: forall t₄ t₆. (Data t₄, Data t₆) => IP46 t₄ t₆ -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IP46 t₄ t₆)
$cgunfold :: forall t₄ t₆ (c :: * -> *).
(Data t₄, Data t₆) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IP46 t₄ t₆)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP46 t₄ t₆ -> c (IP46 t₄ t₆)
$cgfoldl :: forall t₄ t₆ (c :: * -> *).
(Data t₄, Data t₆) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IP46 t₄ t₆ -> c (IP46 t₄ t₆)
$cp1Data :: forall t₄ t₆. (Data t₄, Data t₆) => Typeable (IP46 t₄ t₆)
Data, IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
(IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool) -> Eq (IP46 t₄ t₆)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall t₄ t₆. (Eq t₄, Eq t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
/= :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
$c/= :: forall t₄ t₆. (Eq t₄, Eq t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
== :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
$c== :: forall t₄ t₆. (Eq t₄, Eq t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
Eq, Eq (IP46 t₄ t₆)
Eq (IP46 t₄ t₆)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> Ordering)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆)
-> (IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆)
-> Ord (IP46 t₄ t₆)
IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
IP46 t₄ t₆ -> IP46 t₄ t₆ -> Ordering
IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆
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 t₄ t₆. (Ord t₄, Ord t₆) => Eq (IP46 t₄ t₆)
forall t₄ t₆. (Ord t₄, Ord t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
forall t₄ t₆.
(Ord t₄, Ord t₆) =>
IP46 t₄ t₆ -> IP46 t₄ t₆ -> Ordering
forall t₄ t₆.
(Ord t₄, Ord t₆) =>
IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆
min :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆
$cmin :: forall t₄ t₆.
(Ord t₄, Ord t₆) =>
IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆
max :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆
$cmax :: forall t₄ t₆.
(Ord t₄, Ord t₆) =>
IP46 t₄ t₆ -> IP46 t₄ t₆ -> IP46 t₄ t₆
>= :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
$c>= :: forall t₄ t₆. (Ord t₄, Ord t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
> :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
$c> :: forall t₄ t₆. (Ord t₄, Ord t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
<= :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
$c<= :: forall t₄ t₆. (Ord t₄, Ord t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
< :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
$c< :: forall t₄ t₆. (Ord t₄, Ord t₆) => IP46 t₄ t₆ -> IP46 t₄ t₆ -> Bool
compare :: IP46 t₄ t₆ -> IP46 t₄ t₆ -> Ordering
$ccompare :: forall t₄ t₆.
(Ord t₄, Ord t₆) =>
IP46 t₄ t₆ -> IP46 t₄ t₆ -> Ordering
$cp1Ord :: forall t₄ t₆. (Ord t₄, Ord t₆) => Eq (IP46 t₄ t₆)
Ord, Int -> IP46 t₄ t₆ -> ShowS
[IP46 t₄ t₆] -> ShowS
IP46 t₄ t₆ -> String
(Int -> IP46 t₄ t₆ -> ShowS)
-> (IP46 t₄ t₆ -> String)
-> ([IP46 t₄ t₆] -> ShowS)
-> Show (IP46 t₄ t₆)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall t₄ t₆. (Show t₄, Show t₆) => Int -> IP46 t₄ t₆ -> ShowS
forall t₄ t₆. (Show t₄, Show t₆) => [IP46 t₄ t₆] -> ShowS
forall t₄ t₆. (Show t₄, Show t₆) => IP46 t₄ t₆ -> String
showList :: [IP46 t₄ t₆] -> ShowS
$cshowList :: forall t₄ t₆. (Show t₄, Show t₆) => [IP46 t₄ t₆] -> ShowS
show :: IP46 t₄ t₆ -> String
$cshow :: forall t₄ t₆. (Show t₄, Show t₆) => IP46 t₄ t₆ -> String
showsPrec :: Int -> IP46 t₄ t₆ -> ShowS
$cshowsPrec :: forall t₄ t₆. (Show t₄, Show t₆) => Int -> IP46 t₄ t₆ -> ShowS
Show, ReadPrec [IP46 t₄ t₆]
ReadPrec (IP46 t₄ t₆)
Int -> ReadS (IP46 t₄ t₆)
ReadS [IP46 t₄ t₆]
(Int -> ReadS (IP46 t₄ t₆))
-> ReadS [IP46 t₄ t₆]
-> ReadPrec (IP46 t₄ t₆)
-> ReadPrec [IP46 t₄ t₆]
-> Read (IP46 t₄ t₆)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall t₄ t₆. (Read t₄, Read t₆) => ReadPrec [IP46 t₄ t₆]
forall t₄ t₆. (Read t₄, Read t₆) => ReadPrec (IP46 t₄ t₆)
forall t₄ t₆. (Read t₄, Read t₆) => Int -> ReadS (IP46 t₄ t₆)
forall t₄ t₆. (Read t₄, Read t₆) => ReadS [IP46 t₄ t₆]
readListPrec :: ReadPrec [IP46 t₄ t₆]
$creadListPrec :: forall t₄ t₆. (Read t₄, Read t₆) => ReadPrec [IP46 t₄ t₆]
readPrec :: ReadPrec (IP46 t₄ t₆)
$creadPrec :: forall t₄ t₆. (Read t₄, Read t₆) => ReadPrec (IP46 t₄ t₆)
readList :: ReadS [IP46 t₄ t₆]
$creadList :: forall t₄ t₆. (Read t₄, Read t₆) => ReadS [IP46 t₄ t₆]
readsPrec :: Int -> ReadS (IP46 t₄ t₆)
$creadsPrec :: forall t₄ t₆. (Read t₄, Read t₆) => Int -> ReadS (IP46 t₄ t₆)
Read)
anIP46 ∷ Proxy IP46
anIP46 :: Proxy IP46
anIP46 = Proxy IP46
forall k (t :: k). Proxy t
Proxy
anIP46Of ∷ Proxy t₄ → Proxy t₆ → Proxy (IP46 t₄ t₆)
anIP46Of :: Proxy t₄ -> Proxy t₆ -> Proxy (IP46 t₄ t₆)
anIP46Of Proxy t₄
_ Proxy t₆
_ = Proxy (IP46 t₄ t₆)
forall k (t :: k). Proxy t
Proxy
type IP = IP46 IP4 IP6
anIP ∷ Proxy IP
anIP :: Proxy IP
anIP = Proxy IP
forall k (t :: k). Proxy t
Proxy
instance Printable IP where
print :: IP -> p
print (IPv4 IP4
a) = IP4 -> p
forall α p. (Printable α, Printer p) => α -> p
print IP4
a
print (IPv6 IP6
a) = IP6 -> p
forall α p. (Printable α, Printer p) => α -> p
print IP6
a
{-# INLINABLE print #-}
instance Textual IP where
textual :: μ IP
textual = μ IP -> μ IP
forall (m :: * -> *) a. Parsing m => m a -> m a
try (IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> IP) -> μ IP4 -> μ IP
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP4
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual) μ IP -> μ IP -> μ IP
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> IP) -> μ IP6 -> μ IP
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP6
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual)
{-# INLINABLE textual #-}
instance Serializable IP where
put :: IP -> s
put (IPv4 IP4
a) = Either IP4 IP6 -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put (IP4 -> Either IP4 IP6
forall a b. a -> Either a b
Left IP4
a ∷ Either IP4 IP6)
put (IPv6 IP6
a) = Either IP4 IP6 -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put (IP6 -> Either IP4 IP6
forall a b. b -> Either a b
Right IP6
a ∷ Either IP4 IP6)
instance Deserializable IP where
get :: μ IP
get = μ (Either IP4 IP6)
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get μ (Either IP4 IP6) -> (Either IP4 IP6 -> μ IP) -> μ IP
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IP -> μ IP
forall (m :: * -> *) a. Monad m => a -> m a
return (IP -> μ IP) -> (Either IP4 IP6 -> IP) -> Either IP4 IP6 -> μ IP
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IP4 -> IP) -> (IP6 -> IP) -> Either IP4 IP6 -> IP
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 μ IP -> String -> μ IP
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IP address"
class IsNetAddr n where
type NetHost n
netHost ∷ n → NetHost n
netHostIx ∷ n → NetHost n
netPrefix ∷ n → NetHost n
netMask ∷ n → NetHost n
netLength ∷ n → Word8
netAddr ∷ NetHost n
→ Word8
→ n
inNetwork ∷ NetHost n
→ n
→ Bool
data NetAddr a = NetAddr a {-# UNPACK #-} !Word8
deriving NetAddr a -> NetAddr a -> Bool
(NetAddr a -> NetAddr a -> Bool)
-> (NetAddr a -> NetAddr a -> Bool) -> Eq (NetAddr a)
forall a. Eq a => NetAddr a -> NetAddr a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetAddr a -> NetAddr a -> Bool
$c/= :: forall a. Eq a => NetAddr a -> NetAddr a -> Bool
== :: NetAddr a -> NetAddr a -> Bool
$c== :: forall a. Eq a => NetAddr a -> NetAddr a -> Bool
Eq
#if !MIN_VERSION_base(4,10,0)
deriving instance Typeable1 NetAddr
#endif
deriving instance Data a ⇒ Data (NetAddr a)
type Net4Addr = NetAddr IP4
type Net6Addr = NetAddr IP6
aNetAddr ∷ Proxy NetAddr
aNetAddr :: Proxy NetAddr
aNetAddr = Proxy NetAddr
forall k (t :: k). Proxy t
Proxy
aNetAddrOf ∷ Proxy a → Proxy (NetAddr a)
aNetAddrOf :: Proxy a -> Proxy (NetAddr a)
aNetAddrOf Proxy a
_ = Proxy (NetAddr a)
forall k (t :: k). Proxy t
Proxy
aNet4Addr ∷ Proxy Net4Addr
aNet4Addr :: Proxy Net4Addr
aNet4Addr = Proxy Net4Addr
forall k (t :: k). Proxy t
Proxy
aNet6Addr ∷ Proxy Net6Addr
aNet6Addr :: Proxy Net6Addr
aNet6Addr = Proxy Net6Addr
forall k (t :: k). Proxy t
Proxy
aNetAddrIP ∷ Proxy (NetAddr IP)
aNetAddrIP :: Proxy (NetAddr IP)
aNetAddrIP = Proxy (NetAddr IP)
forall k (t :: k). Proxy t
Proxy
instance Show a ⇒ Show (NetAddr a) where
showsPrec :: Int -> NetAddr a -> ShowS
showsPrec Int
p (NetAddr a
a Word8
w) = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10)
(ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"netAddr "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
a
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word8
w
instance Read Net4Addr where
readsPrec :: Int -> ReadS Net4Addr
readsPrec Int
p = Bool -> ReadS Net4Addr -> ReadS Net4Addr
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS Net4Addr -> ReadS Net4Addr)
-> ReadS Net4Addr -> ReadS Net4Addr
forall a b. (a -> b) -> a -> b
$ \String
i →
[ (NetHost Net4Addr -> Word8 -> Net4Addr
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr NetHost Net4Addr
IP4
a Word8
w, String
i2)
| (String
"netAddr", String
i') ← ReadS String
lex String
i
, (IP4
a, String
i1) ← Int -> ReadS IP4
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i'
, (Word8
w, String
i2) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i1 ]
instance Read Net6Addr where
readsPrec :: Int -> ReadS Net6Addr
readsPrec Int
p = Bool -> ReadS Net6Addr -> ReadS Net6Addr
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS Net6Addr -> ReadS Net6Addr)
-> ReadS Net6Addr -> ReadS Net6Addr
forall a b. (a -> b) -> a -> b
$ \String
i →
[ (NetHost Net6Addr -> Word8 -> Net6Addr
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr NetHost Net6Addr
IP6
a Word8
w, String
i2)
| (String
"netAddr", String
i') ← ReadS String
lex String
i
, (IP6
a, String
i1) ← Int -> ReadS IP6
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i'
, (Word8
w, String
i2) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i1 ]
instance Read (NetAddr IP) where
readsPrec :: Int -> ReadS (NetAddr IP)
readsPrec Int
p = Bool -> ReadS (NetAddr IP) -> ReadS (NetAddr IP)
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS (NetAddr IP) -> ReadS (NetAddr IP))
-> ReadS (NetAddr IP) -> ReadS (NetAddr IP)
forall a b. (a -> b) -> a -> b
$ \String
i →
[ (NetHost (NetAddr IP) -> Word8 -> NetAddr IP
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr NetHost (NetAddr IP)
IP
a Word8
w, String
i2)
| (String
"netAddr", String
i') ← ReadS String
lex String
i
, (IP
a, String
i1) ← Int -> ReadS IP
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i'
, (Word8
w, String
i2) ← Int -> ReadS Word8
forall a. Read a => Int -> ReadS a
readsPrec Int
11 String
i1 ]
instance Printable a ⇒ Printable (NetAddr a) where
print :: NetAddr a -> p
print (NetAddr a
a Word8
m) = a -> p
forall α p. (Printable α, Printer p) => α -> p
print a
a p -> p -> p
forall a. Semigroup a => a -> a -> a
<> Char -> p
forall p. Printer p => Char -> p
P.char7 Char
'/' p -> p -> p
forall a. Semigroup a => a -> a -> a
<> Word8 -> p
forall α p. (Printable α, Printer p) => α -> p
print Word8
m
{-# INLINE print #-}
instance Textual Net4Addr where
textual :: μ Net4Addr
textual = μ Net4Addr
forall (μ :: * -> *) n.
(CharParsing μ, Monad μ, IsNetAddr n, NetHost n ~ IP4) =>
μ n
net4Parser
{-# INLINE textual #-}
instance Textual Net6Addr where
textual :: μ Net6Addr
textual = μ Net6Addr
forall (μ :: * -> *) n.
(CharParsing μ, Monad μ, IsNetAddr n, NetHost n ~ IP6) =>
μ n
net6Parser
{-# INLINE textual #-}
instance Textual (NetAddr IP) where
textual :: μ (NetAddr IP)
textual = μ (NetAddr IP)
forall n (μ :: * -> *).
(IsNetAddr n, NetHost n ~ IP, CharParsing μ, Monad μ) =>
μ n
netParser
{-# INLINE textual #-}
instance Serializable a ⇒ Serializable (NetAddr a) where
put :: NetAddr a -> s
put (NetAddr a
a Word8
w) = a -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put a
a s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put Word8
w
{-# INLINE put #-}
instance SizedSerializable a ⇒ SizedSerializable (NetAddr a) where
size :: Proxy (NetAddr a) -> Int
size Proxy (NetAddr a)
_ = Proxy a -> Int
forall α. SizedSerializable α => Proxy α -> Int
S.size (Proxy a
forall k (t :: k). Proxy t
Proxy ∷ Proxy a) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
{-# INLINE size #-}
instance Deserializable Net4Addr where
get :: μ Net4Addr
get = μ Net4Addr
forall n (μ :: * -> *).
(IsNetAddr n, Deserializable (NetHost n), Deserializer μ) =>
μ n
getNetAddr μ Net4Addr -> String -> μ Net4Addr
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv4 network address"
{-# INLINE get #-}
instance Deserializable Net6Addr where
get :: μ Net6Addr
get = μ Net6Addr
forall n (μ :: * -> *).
(IsNetAddr n, Deserializable (NetHost n), Deserializer μ) =>
μ n
getNetAddr μ Net6Addr -> String -> μ Net6Addr
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv6 network address"
{-# INLINE get #-}
instance Deserializable (NetAddr IP) where
get :: μ (NetAddr IP)
get = μ (NetAddr IP)
forall n (μ :: * -> *).
(IsNetAddr n, Deserializable (NetHost n), Deserializer μ) =>
μ n
getNetAddr μ (NetAddr IP) -> String -> μ (NetAddr IP)
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IP network address"
{-# INLINE get #-}
instance IsNetAddr Net4Addr where
type NetHost Net4Addr = IP4
netHost :: Net4Addr -> NetHost Net4Addr
netHost (NetAddr IP4
a Word8
_) = NetHost Net4Addr
IP4
a
{-# INLINE netHost #-}
netHostIx :: Net4Addr -> NetHost Net4Addr
netHostIx (NetAddr IP4
a Word8
w) = (IP4
a IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftL` Int
l) IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE netHostIx #-}
netPrefix :: Net4Addr -> NetHost Net4Addr
netPrefix (NetAddr IP4
a Word8
w) = (IP4
a IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE netPrefix #-}
netMask :: Net4Addr -> NetHost Net4Addr
netMask (NetAddr IP4
_ Word8
w) = Word32 -> IP4
IP4 (Word32 -> IP4) -> Word32 -> IP4
forall a b. (a -> b) -> a -> b
$ (Word32
forall w. BinaryWord w => w
allOnes Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE netMask #-}
netLength :: Net4Addr -> Word8
netLength (NetAddr IP4
_ Word8
w) = Word8
w
{-# INLINE netLength #-}
netAddr :: NetHost Net4Addr -> Word8 -> Net4Addr
netAddr NetHost Net4Addr
a Word8
w = IP4 -> Word8 -> Net4Addr
forall a. a -> Word8 -> NetAddr a
NetAddr NetHost Net4Addr
IP4
a (Word8
w Word8 -> Word8 -> Word8
forall a. Ord a => a -> a -> a
`min` Word8
32)
{-# INLINE netAddr #-}
inNetwork :: NetHost Net4Addr -> Net4Addr -> Bool
inNetwork NetHost Net4Addr
h (NetAddr IP4
a Word8
w) = NetHost Net4Addr
IP4
h IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l IP4 -> IP4 -> Bool
forall a. Eq a => a -> a -> Bool
== IP4
a IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE inNetwork #-}
instance IsNetAddr Net6Addr where
type NetHost Net6Addr = IP6
netHost :: Net6Addr -> NetHost Net6Addr
netHost (NetAddr IP6
a Word8
_) = NetHost Net6Addr
IP6
a
{-# INLINE netHost #-}
netHostIx :: Net6Addr -> NetHost Net6Addr
netHostIx (NetAddr IP6
a Word8
w) = (IP6
a IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftL` Int
l) IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE netHostIx #-}
netPrefix :: Net6Addr -> NetHost Net6Addr
netPrefix (NetAddr IP6
a Word8
w) = (IP6
a IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
128 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE netPrefix #-}
netMask :: Net6Addr -> NetHost Net6Addr
netMask (NetAddr IP6
_ Word8
w) = Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ (Word128
forall w. BinaryWord w => w
allOnes Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
128 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE netMask #-}
netLength :: Net6Addr -> Word8
netLength (NetAddr IP6
_ Word8
w) = Word8
w
{-# INLINE netLength #-}
netAddr :: NetHost Net6Addr -> Word8 -> Net6Addr
netAddr NetHost Net6Addr
a Word8
w = IP6 -> Word8 -> Net6Addr
forall a. a -> Word8 -> NetAddr a
NetAddr NetHost Net6Addr
IP6
a (Word8
w Word8 -> Word8 -> Word8
forall a. Ord a => a -> a -> a
`min` Word8
128)
{-# INLINE netAddr #-}
inNetwork :: NetHost Net6Addr -> Net6Addr -> Bool
inNetwork NetHost Net6Addr
h (NetAddr IP6
a Word8
w) = NetHost Net6Addr
IP6
h IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l IP6 -> IP6 -> Bool
forall a. Eq a => a -> a -> Bool
== IP6
a IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Int
128 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINE inNetwork #-}
instance IsNetAddr (NetAddr IP) where
type NetHost (NetAddr IP) = IP
netHost :: NetAddr IP -> NetHost (NetAddr IP)
netHost (NetAddr IP
a Word8
_) = NetHost (NetAddr IP)
IP
a
{-# INLINE netHost #-}
netHostIx :: NetAddr IP -> NetHost (NetAddr IP)
netHostIx (NetAddr IP
a Word8
w) = case IP
a of
IPv4 IP4
a1 → IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> IP) -> IP4 -> IP
forall a b. (a -> b) -> a -> b
$ (IP4
a1 IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftL` Int
l) IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
IPv6 IP6
a1 → IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> IP) -> IP6 -> IP
forall a b. (a -> b) -> a -> b
$ (IP6
a1 IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftL` Int
l) IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINABLE netHostIx #-}
netPrefix :: NetAddr IP -> NetHost (NetAddr IP)
netPrefix (NetAddr IP
a Word8
w) = case IP
a of
IPv4 IP4
a1 → IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> IP) -> IP4 -> IP
forall a b. (a -> b) -> a -> b
$ (IP4
a1 IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
IPv6 IP6
a1 → IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> IP) -> IP6 -> IP
forall a b. (a -> b) -> a -> b
$ (IP6
a1 IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
128 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINABLE netPrefix #-}
netMask :: NetAddr IP -> NetHost (NetAddr IP)
netMask (NetAddr IP
a Word8
w) = case IP
a of
IPv4 IP4
_ → IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> IP) -> IP4 -> IP
forall a b. (a -> b) -> a -> b
$ Word32 -> IP4
IP4 (Word32 -> IP4) -> Word32 -> IP4
forall a b. (a -> b) -> a -> b
$ (Word32
forall w. BinaryWord w => w
allOnes Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
IPv6 IP6
_ → IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> IP) -> IP6 -> IP
forall a b. (a -> b) -> a -> b
$ Word128 -> IP6
IP6 (Word128 -> IP6) -> Word128 -> IP6
forall a b. (a -> b) -> a -> b
$ (Word128
forall w. BinaryWord w => w
allOnes Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftR` Int
l) Word128 -> Int -> Word128
forall a. Bits a => a -> Int -> a
`shiftL` Int
l
where l :: Int
l = Int
128 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
{-# INLINABLE netMask #-}
netLength :: NetAddr IP -> Word8
netLength (NetAddr IP
_ Word8
w) = Word8
w
{-# INLINE netLength #-}
netAddr :: NetHost (NetAddr IP) -> Word8 -> NetAddr IP
netAddr NetHost (NetAddr IP)
a Word8
w = IP -> Word8 -> NetAddr IP
forall a. a -> Word8 -> NetAddr a
NetAddr NetHost (NetAddr IP)
IP
a (Word8
w Word8 -> Word8 -> Word8
forall a. Ord a => a -> a -> a
`min` Word8
m)
where m :: Word8
m = case NetHost (NetAddr IP)
a of
IPv4 _ → Word8
32
IPv6 _ → Word8
128
{-# INLINABLE netAddr #-}
inNetwork :: NetHost (NetAddr IP) -> NetAddr IP -> Bool
inNetwork (IPv4 h) (NetAddr (IPv4 IP4
a) Word8
w) = IP4
h IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l IP4 -> IP4 -> Bool
forall a. Eq a => a -> a -> Bool
== IP4
a IP4 -> Int -> IP4
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Int
32 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
inNetwork (IPv6 h) (NetAddr (IPv6 IP6
a) Word8
w) = IP6
h IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l IP6 -> IP6 -> Bool
forall a. Eq a => a -> a -> Bool
== IP6
a IP6 -> Int -> IP6
forall a. Bits a => a -> Int -> a
`shiftR` Int
l
where l :: Int
l = Int
128 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w
inNetwork NetHost (NetAddr IP)
_ NetAddr IP
_ = Bool
False
net4Addr ∷ IP4 → Word8 → Net4Addr
net4Addr :: IP4 -> Word8 -> Net4Addr
net4Addr = IP4 -> Word8 -> Net4Addr
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr
{-# INLINE net4Addr #-}
net6Addr ∷ IP6 → Word8 → Net6Addr
net6Addr :: IP6 -> Word8 -> Net6Addr
net6Addr = IP6 -> Word8 -> Net6Addr
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr
{-# INLINE net6Addr #-}
toNetAddr46 ∷ NetAddr IP → IP46 (NetAddr IP4) (NetAddr IP6)
toNetAddr46 :: NetAddr IP -> IP46 Net4Addr Net6Addr
toNetAddr46 (NetAddr (IPv4 IP4
a) Word8
w) = Net4Addr -> IP46 Net4Addr Net6Addr
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> Word8 -> Net4Addr
forall a. a -> Word8 -> NetAddr a
NetAddr IP4
a Word8
w)
toNetAddr46 (NetAddr (IPv6 IP6
a) Word8
w) = Net6Addr -> IP46 Net4Addr Net6Addr
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> Word8 -> Net6Addr
forall a. a -> Word8 -> NetAddr a
NetAddr IP6
a Word8
w)
{-# INLINABLE toNetAddr46 #-}
fromNetAddr46 ∷ IP46 (NetAddr IP4) (NetAddr IP6) → NetAddr IP
fromNetAddr46 :: IP46 Net4Addr Net6Addr -> NetAddr IP
fromNetAddr46 (IPv4 (NetAddr IP4
a Word8
w)) = IP -> Word8 -> NetAddr IP
forall a. a -> Word8 -> NetAddr a
NetAddr (IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 IP4
a) Word8
w
fromNetAddr46 (IPv6 (NetAddr IP6
a Word8
w)) = IP -> Word8 -> NetAddr IP
forall a. a -> Word8 -> NetAddr a
NetAddr (IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 IP6
a) Word8
w
{-# INLINABLE fromNetAddr46 #-}
printNetAddr ∷ (IsNetAddr n, Printable (NetHost n), Printer p) ⇒ n → p
printNetAddr :: n -> p
printNetAddr n
n = NetHost n -> p
forall α p. (Printable α, Printer p) => α -> p
print (n -> NetHost n
forall n. IsNetAddr n => n -> NetHost n
netHost n
n) p -> p -> p
forall a. Semigroup a => a -> a -> a
<> Char -> p
forall p. Printer p => Char -> p
P.char7 Char
'/' p -> p -> p
forall a. Semigroup a => a -> a -> a
<> Word8 -> p
forall α p. (Printable α, Printer p) => α -> p
print (n -> Word8
forall n. IsNetAddr n => n -> Word8
netLength n
n)
{-# INLINABLE printNetAddr #-}
ip4Mask ∷ (CharParsing μ, Monad μ) ⇒ μ Word8
ip4Mask :: μ Word8
ip4Mask = (μ Word8 -> String -> μ Word8
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"network prefix length") (μ Word8 -> μ Word8) -> μ Word8 -> μ Word8
forall a b. (a -> b) -> a -> b
$ do
Word8
m ← Decimal -> Int -> μ Word8
forall s α (μ :: * -> *).
(PositionalSystem s, Num α, Monad μ, CharParsing μ) =>
s -> Int -> μ α
nncUpTo Decimal
Decimal Int
2
Bool -> μ () -> μ ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Word8
m Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
> Word8
32) (μ () -> μ ()) -> μ () -> μ ()
forall a b. (a -> b) -> a -> b
$ String -> μ ()
forall (m :: * -> *) a. Parsing m => String -> m a
D.unexpected String
"out of bounds"
Word8 -> μ Word8
forall (m :: * -> *) a. Monad m => a -> m a
return Word8
m
net4Parser ∷ (CharParsing μ, Monad μ, IsNetAddr n, NetHost n ~ IP4) ⇒ μ n
net4Parser :: μ n
net4Parser = IP4 -> Word8 -> n
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr (IP4 -> Word8 -> n) -> μ IP4 -> μ (Word8 -> n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP4
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual μ (Word8 -> n) -> μ Word8 -> μ n
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'/' μ Char -> μ Word8 -> μ Word8
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> μ Word8
forall (μ :: * -> *). (CharParsing μ, Monad μ) => μ Word8
ip4Mask)
μ n -> String -> μ n
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv4 network address"
{-# INLINE net4Parser #-}
ip6Mask ∷ (CharParsing μ, Monad μ) ⇒ μ Word8
ip6Mask :: μ Word8
ip6Mask = (μ Word8 -> String -> μ Word8
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"network prefix length") (μ Word8 -> μ Word8) -> μ Word8 -> μ Word8
forall a b. (a -> b) -> a -> b
$ do
Int
m ← Decimal -> Int -> μ Int
forall s α (μ :: * -> *).
(PositionalSystem s, Num α, Monad μ, CharParsing μ) =>
s -> Int -> μ α
nncUpTo Decimal
Decimal Int
3
Bool -> μ () -> μ ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> (Int
128 ∷ Int)) (μ () -> μ ()) -> μ () -> μ ()
forall a b. (a -> b) -> a -> b
$ String -> μ ()
forall (m :: * -> *) a. Parsing m => String -> m a
D.unexpected String
"out of bounds"
Word8 -> μ Word8
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8 -> μ Word8) -> Word8 -> μ Word8
forall a b. (a -> b) -> a -> b
$ Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m
net6Parser ∷ (CharParsing μ, Monad μ, IsNetAddr n, NetHost n ~ IP6) ⇒ μ n
net6Parser :: μ n
net6Parser = IP6 -> Word8 -> n
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr (IP6 -> Word8 -> n) -> μ IP6 -> μ (Word8 -> n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP6
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual μ (Word8 -> n) -> μ Word8 -> μ n
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'/' μ Char -> μ Word8 -> μ Word8
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> μ Word8
forall (μ :: * -> *). (CharParsing μ, Monad μ) => μ Word8
ip6Mask)
μ n -> String -> μ n
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv6 network address"
{-# INLINE net6Parser #-}
netParser ∷ (IsNetAddr n, NetHost n ~ IP, CharParsing μ, Monad μ) ⇒ μ n
netParser :: μ n
netParser = (μ n -> String -> μ n
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IP network address") (μ n -> μ n) -> μ n -> μ n
forall a b. (a -> b) -> a -> b
$ do
IP
a ← μ IP
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual
μ Char -> μ ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (μ Char -> μ ()) -> μ Char -> μ ()
forall a b. (a -> b) -> a -> b
$ Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'/'
Word8
m ← IP -> μ Word8
forall (μ :: * -> *) t₄ t₆.
(CharParsing μ, Monad μ) =>
IP46 t₄ t₆ -> μ Word8
mask IP
a
n -> μ n
forall (m :: * -> *) a. Monad m => a -> m a
return (n -> μ n) -> n -> μ n
forall a b. (a -> b) -> a -> b
$ NetHost n -> Word8 -> n
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr NetHost n
IP
a Word8
m
where
mask :: IP46 t₄ t₆ -> μ Word8
mask (IPv4 t₄
_) = μ Word8
forall (μ :: * -> *). (CharParsing μ, Monad μ) => μ Word8
ip4Mask
mask (IPv6 t₆
_) = μ Word8
forall (μ :: * -> *). (CharParsing μ, Monad μ) => μ Word8
ip6Mask
putNetAddr ∷ (IsNetAddr n, Serializable (NetHost n), Serializer s) ⇒ n → s
putNetAddr :: n -> s
putNetAddr n
n = NetHost n -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put (n -> NetHost n
forall n. IsNetAddr n => n -> NetHost n
netHost n
n) s -> s -> s
forall a. Semigroup a => a -> a -> a
<> NetHost n -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put (n -> NetHost n
forall n. IsNetAddr n => n -> NetHost n
netPrefix n
n)
{-# INLINE putNetAddr #-}
getNetAddr ∷ (IsNetAddr n, Deserializable (NetHost n), Deserializer μ) ⇒ μ n
getNetAddr :: μ n
getNetAddr = NetHost n -> Word8 -> n
forall n. IsNetAddr n => NetHost n -> Word8 -> n
netAddr (NetHost n -> Word8 -> n) -> μ (NetHost n) -> μ (Word8 -> n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ (NetHost n)
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get μ (Word8 -> n) -> μ Word8 -> μ n
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> μ Word8
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get
{-# INLINE getNetAddr #-}
newtype InetPort = InetPort { InetPort -> Word16
unInetPort ∷ Word16 }
deriving (Typeable, Typeable InetPort
Constr
DataType
Typeable InetPort
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InetPort -> c InetPort)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InetPort)
-> (InetPort -> Constr)
-> (InetPort -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c InetPort))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InetPort))
-> ((forall b. Data b => b -> b) -> InetPort -> InetPort)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r)
-> (forall u. (forall d. Data d => d -> u) -> InetPort -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> InetPort -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort)
-> Data InetPort
InetPort -> Constr
InetPort -> DataType
(forall b. Data b => b -> b) -> InetPort -> InetPort
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InetPort -> c InetPort
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InetPort
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) -> InetPort -> u
forall u. (forall d. Data d => d -> u) -> InetPort -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InetPort
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InetPort -> c InetPort
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c InetPort)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InetPort)
$cInetPort :: Constr
$tInetPort :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> InetPort -> m InetPort
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort
gmapMp :: (forall d. Data d => d -> m d) -> InetPort -> m InetPort
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort
gmapM :: (forall d. Data d => d -> m d) -> InetPort -> m InetPort
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> InetPort -> m InetPort
gmapQi :: Int -> (forall d. Data d => d -> u) -> InetPort -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> InetPort -> u
gmapQ :: (forall d. Data d => d -> u) -> InetPort -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> InetPort -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> InetPort -> r
gmapT :: (forall b. Data b => b -> b) -> InetPort -> InetPort
$cgmapT :: (forall b. Data b => b -> b) -> InetPort -> InetPort
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InetPort)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InetPort)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c InetPort)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c InetPort)
dataTypeOf :: InetPort -> DataType
$cdataTypeOf :: InetPort -> DataType
toConstr :: InetPort -> Constr
$ctoConstr :: InetPort -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InetPort
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c InetPort
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InetPort -> c InetPort
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> InetPort -> c InetPort
$cp1Data :: Typeable InetPort
Data, InetPort -> InetPort -> Bool
(InetPort -> InetPort -> Bool)
-> (InetPort -> InetPort -> Bool) -> Eq InetPort
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InetPort -> InetPort -> Bool
$c/= :: InetPort -> InetPort -> Bool
== :: InetPort -> InetPort -> Bool
$c== :: InetPort -> InetPort -> Bool
Eq, Eq InetPort
Eq InetPort
-> (InetPort -> InetPort -> Ordering)
-> (InetPort -> InetPort -> Bool)
-> (InetPort -> InetPort -> Bool)
-> (InetPort -> InetPort -> Bool)
-> (InetPort -> InetPort -> Bool)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> Ord InetPort
InetPort -> InetPort -> Bool
InetPort -> InetPort -> Ordering
InetPort -> InetPort -> InetPort
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 :: InetPort -> InetPort -> InetPort
$cmin :: InetPort -> InetPort -> InetPort
max :: InetPort -> InetPort -> InetPort
$cmax :: InetPort -> InetPort -> InetPort
>= :: InetPort -> InetPort -> Bool
$c>= :: InetPort -> InetPort -> Bool
> :: InetPort -> InetPort -> Bool
$c> :: InetPort -> InetPort -> Bool
<= :: InetPort -> InetPort -> Bool
$c<= :: InetPort -> InetPort -> Bool
< :: InetPort -> InetPort -> Bool
$c< :: InetPort -> InetPort -> Bool
compare :: InetPort -> InetPort -> Ordering
$ccompare :: InetPort -> InetPort -> Ordering
$cp1Ord :: Eq InetPort
Ord, InetPort
InetPort -> InetPort -> Bounded InetPort
forall a. a -> a -> Bounded a
maxBound :: InetPort
$cmaxBound :: InetPort
minBound :: InetPort
$cminBound :: InetPort
Bounded, Int -> InetPort
InetPort -> Int
InetPort -> [InetPort]
InetPort -> InetPort
InetPort -> InetPort -> [InetPort]
InetPort -> InetPort -> InetPort -> [InetPort]
(InetPort -> InetPort)
-> (InetPort -> InetPort)
-> (Int -> InetPort)
-> (InetPort -> Int)
-> (InetPort -> [InetPort])
-> (InetPort -> InetPort -> [InetPort])
-> (InetPort -> InetPort -> [InetPort])
-> (InetPort -> InetPort -> InetPort -> [InetPort])
-> Enum InetPort
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: InetPort -> InetPort -> InetPort -> [InetPort]
$cenumFromThenTo :: InetPort -> InetPort -> InetPort -> [InetPort]
enumFromTo :: InetPort -> InetPort -> [InetPort]
$cenumFromTo :: InetPort -> InetPort -> [InetPort]
enumFromThen :: InetPort -> InetPort -> [InetPort]
$cenumFromThen :: InetPort -> InetPort -> [InetPort]
enumFrom :: InetPort -> [InetPort]
$cenumFrom :: InetPort -> [InetPort]
fromEnum :: InetPort -> Int
$cfromEnum :: InetPort -> Int
toEnum :: Int -> InetPort
$ctoEnum :: Int -> InetPort
pred :: InetPort -> InetPort
$cpred :: InetPort -> InetPort
succ :: InetPort -> InetPort
$csucc :: InetPort -> InetPort
Enum, Ord InetPort
Ord InetPort
-> ((InetPort, InetPort) -> [InetPort])
-> ((InetPort, InetPort) -> InetPort -> Int)
-> ((InetPort, InetPort) -> InetPort -> Int)
-> ((InetPort, InetPort) -> InetPort -> Bool)
-> ((InetPort, InetPort) -> Int)
-> ((InetPort, InetPort) -> Int)
-> Ix InetPort
(InetPort, InetPort) -> Int
(InetPort, InetPort) -> [InetPort]
(InetPort, InetPort) -> InetPort -> Bool
(InetPort, InetPort) -> InetPort -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (InetPort, InetPort) -> Int
$cunsafeRangeSize :: (InetPort, InetPort) -> Int
rangeSize :: (InetPort, InetPort) -> Int
$crangeSize :: (InetPort, InetPort) -> Int
inRange :: (InetPort, InetPort) -> InetPort -> Bool
$cinRange :: (InetPort, InetPort) -> InetPort -> Bool
unsafeIndex :: (InetPort, InetPort) -> InetPort -> Int
$cunsafeIndex :: (InetPort, InetPort) -> InetPort -> Int
index :: (InetPort, InetPort) -> InetPort -> Int
$cindex :: (InetPort, InetPort) -> InetPort -> Int
range :: (InetPort, InetPort) -> [InetPort]
$crange :: (InetPort, InetPort) -> [InetPort]
$cp1Ix :: Ord InetPort
Ix, Integer -> InetPort
InetPort -> InetPort
InetPort -> InetPort -> InetPort
(InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort)
-> (InetPort -> InetPort)
-> (InetPort -> InetPort)
-> (Integer -> InetPort)
-> Num InetPort
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> InetPort
$cfromInteger :: Integer -> InetPort
signum :: InetPort -> InetPort
$csignum :: InetPort -> InetPort
abs :: InetPort -> InetPort
$cabs :: InetPort -> InetPort
negate :: InetPort -> InetPort
$cnegate :: InetPort -> InetPort
* :: InetPort -> InetPort -> InetPort
$c* :: InetPort -> InetPort -> InetPort
- :: InetPort -> InetPort -> InetPort
$c- :: InetPort -> InetPort -> InetPort
+ :: InetPort -> InetPort -> InetPort
$c+ :: InetPort -> InetPort -> InetPort
Num, Num InetPort
Ord InetPort
Num InetPort
-> Ord InetPort -> (InetPort -> Rational) -> Real InetPort
InetPort -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: InetPort -> Rational
$ctoRational :: InetPort -> Rational
$cp2Real :: Ord InetPort
$cp1Real :: Num InetPort
Real, Enum InetPort
Real InetPort
Real InetPort
-> Enum InetPort
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> (InetPort, InetPort))
-> (InetPort -> InetPort -> (InetPort, InetPort))
-> (InetPort -> Integer)
-> Integral InetPort
InetPort -> Integer
InetPort -> InetPort -> (InetPort, InetPort)
InetPort -> InetPort -> InetPort
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: InetPort -> Integer
$ctoInteger :: InetPort -> Integer
divMod :: InetPort -> InetPort -> (InetPort, InetPort)
$cdivMod :: InetPort -> InetPort -> (InetPort, InetPort)
quotRem :: InetPort -> InetPort -> (InetPort, InetPort)
$cquotRem :: InetPort -> InetPort -> (InetPort, InetPort)
mod :: InetPort -> InetPort -> InetPort
$cmod :: InetPort -> InetPort -> InetPort
div :: InetPort -> InetPort -> InetPort
$cdiv :: InetPort -> InetPort -> InetPort
rem :: InetPort -> InetPort -> InetPort
$crem :: InetPort -> InetPort -> InetPort
quot :: InetPort -> InetPort -> InetPort
$cquot :: InetPort -> InetPort -> InetPort
$cp2Integral :: Enum InetPort
$cp1Integral :: Real InetPort
Integral,
Eq InetPort
InetPort
Eq InetPort
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort -> InetPort)
-> (InetPort -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> InetPort
-> (Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> Bool)
-> (InetPort -> Maybe Int)
-> (InetPort -> Int)
-> (InetPort -> Bool)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int -> InetPort)
-> (InetPort -> Int)
-> Bits InetPort
Int -> InetPort
InetPort -> Bool
InetPort -> Int
InetPort -> Maybe Int
InetPort -> InetPort
InetPort -> Int -> Bool
InetPort -> Int -> InetPort
InetPort -> InetPort -> InetPort
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
popCount :: InetPort -> Int
$cpopCount :: InetPort -> Int
rotateR :: InetPort -> Int -> InetPort
$crotateR :: InetPort -> Int -> InetPort
rotateL :: InetPort -> Int -> InetPort
$crotateL :: InetPort -> Int -> InetPort
unsafeShiftR :: InetPort -> Int -> InetPort
$cunsafeShiftR :: InetPort -> Int -> InetPort
shiftR :: InetPort -> Int -> InetPort
$cshiftR :: InetPort -> Int -> InetPort
unsafeShiftL :: InetPort -> Int -> InetPort
$cunsafeShiftL :: InetPort -> Int -> InetPort
shiftL :: InetPort -> Int -> InetPort
$cshiftL :: InetPort -> Int -> InetPort
isSigned :: InetPort -> Bool
$cisSigned :: InetPort -> Bool
bitSize :: InetPort -> Int
$cbitSize :: InetPort -> Int
bitSizeMaybe :: InetPort -> Maybe Int
$cbitSizeMaybe :: InetPort -> Maybe Int
testBit :: InetPort -> Int -> Bool
$ctestBit :: InetPort -> Int -> Bool
complementBit :: InetPort -> Int -> InetPort
$ccomplementBit :: InetPort -> Int -> InetPort
clearBit :: InetPort -> Int -> InetPort
$cclearBit :: InetPort -> Int -> InetPort
setBit :: InetPort -> Int -> InetPort
$csetBit :: InetPort -> Int -> InetPort
bit :: Int -> InetPort
$cbit :: Int -> InetPort
zeroBits :: InetPort
$czeroBits :: InetPort
rotate :: InetPort -> Int -> InetPort
$crotate :: InetPort -> Int -> InetPort
shift :: InetPort -> Int -> InetPort
$cshift :: InetPort -> Int -> InetPort
complement :: InetPort -> InetPort
$ccomplement :: InetPort -> InetPort
xor :: InetPort -> InetPort -> InetPort
$cxor :: InetPort -> InetPort -> InetPort
.|. :: InetPort -> InetPort -> InetPort
$c.|. :: InetPort -> InetPort -> InetPort
.&. :: InetPort -> InetPort -> InetPort
$c.&. :: InetPort -> InetPort -> InetPort
$cp1Bits :: Eq InetPort
Bits, Eq InetPort
Eq InetPort
-> (Int -> InetPort -> Int)
-> (InetPort -> Int)
-> Hashable InetPort
Int -> InetPort -> Int
InetPort -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: InetPort -> Int
$chash :: InetPort -> Int
hashWithSalt :: Int -> InetPort -> Int
$chashWithSalt :: Int -> InetPort -> Int
$cp1Hashable :: Eq InetPort
Hashable, InetPort -> p
(forall p. Printer p => InetPort -> p) -> Printable InetPort
forall p. Printer p => InetPort -> p
forall α. (forall p. Printer p => α -> p) -> Printable α
print :: InetPort -> p
$cprint :: forall p. Printer p => InetPort -> p
Printable)
anInetPort ∷ Proxy InetPort
anInetPort :: Proxy InetPort
anInetPort = Proxy InetPort
forall k (t :: k). Proxy t
Proxy
instance Show InetPort where
showsPrec :: Int -> InetPort -> ShowS
showsPrec Int
p (InetPort Word16
w) = Int -> Word16 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p Word16
w
{-# INLINE showsPrec #-}
instance Read InetPort where
readsPrec :: Int -> ReadS InetPort
readsPrec Int
p = ((Word16, String) -> (InetPort, String))
-> [(Word16, String)] -> [(InetPort, String)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Word16
w, String
s) → (Word16 -> InetPort
InetPort Word16
w, String
s)) ([(Word16, String)] -> [(InetPort, String)])
-> ReadS Word16 -> ReadS InetPort
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadS Word16
forall a. Read a => Int -> ReadS a
readsPrec Int
p
{-# INLINE readsPrec #-}
instance Textual InetPort where
textual :: μ InetPort
textual = Word16 -> InetPort
InetPort (Word16 -> InetPort) -> μ Word16 -> μ InetPort
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decimal -> μ Word16
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
CharParsing μ) =>
s -> μ α
nncBounded Decimal
Decimal μ InetPort -> String -> μ InetPort
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"port number"
instance Storable InetPort where
alignment :: InetPort -> Int
alignment InetPort
_ = Word16 -> Int
forall a. Storable a => a -> Int
alignment (Word16
forall a. HasCallStack => a
undefined ∷ Word16)
sizeOf :: InetPort -> Int
sizeOf InetPort
_ = Int
2
peek :: Ptr InetPort -> IO InetPort
peek Ptr InetPort
p = Word16 -> InetPort
InetPort (Word16 -> InetPort) -> (Word16 -> Word16) -> Word16 -> InetPort
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Word16
forall α. EndianSensitive α => α -> α
fromBigEndian (Word16 -> InetPort) -> IO Word16 -> IO InetPort
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word16 -> IO Word16
forall a. Storable a => Ptr a -> IO a
peek (Ptr InetPort -> Ptr Word16
forall a b. Ptr a -> Ptr b
castPtr Ptr InetPort
p)
poke :: Ptr InetPort -> InetPort -> IO ()
poke Ptr InetPort
p = Ptr Word16 -> Word16 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr InetPort -> Ptr Word16
forall a b. Ptr a -> Ptr b
castPtr Ptr InetPort
p) (Word16 -> IO ()) -> (InetPort -> Word16) -> InetPort -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Word16
forall α. EndianSensitive α => α -> α
toBigEndian (Word16 -> Word16) -> (InetPort -> Word16) -> InetPort -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InetPort -> Word16
unInetPort
instance Serializable InetPort where
put :: InetPort -> s
put = Word16 -> s
forall s. Serializer s => Word16 -> s
S.word16B (Word16 -> s) -> (InetPort -> Word16) -> InetPort -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InetPort -> Word16
unInetPort
{-# INLINE put #-}
instance SizedSerializable InetPort where
size :: Proxy InetPort -> Int
size Proxy InetPort
_ = Int
2
{-# INLINE size #-}
instance Deserializable InetPort where
get :: μ InetPort
get = Word16 -> InetPort
InetPort (Word16 -> InetPort) -> μ Word16 -> μ InetPort
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ Word16
forall (μ :: * -> *). Deserializer μ => μ Word16
D.word16B μ InetPort -> String -> μ InetPort
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"port number"
{-# INLINE get #-}
data InetAddr a = InetAddr { InetAddr a -> a
inetHost ∷ a
, InetAddr a -> InetPort
inetPort ∷ {-# UNPACK #-} !InetPort
} deriving (InetAddr a -> InetAddr a -> Bool
(InetAddr a -> InetAddr a -> Bool)
-> (InetAddr a -> InetAddr a -> Bool) -> Eq (InetAddr a)
forall a. Eq a => InetAddr a -> InetAddr a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InetAddr a -> InetAddr a -> Bool
$c/= :: forall a. Eq a => InetAddr a -> InetAddr a -> Bool
== :: InetAddr a -> InetAddr a -> Bool
$c== :: forall a. Eq a => InetAddr a -> InetAddr a -> Bool
Eq, Eq (InetAddr a)
Eq (InetAddr a)
-> (InetAddr a -> InetAddr a -> Ordering)
-> (InetAddr a -> InetAddr a -> Bool)
-> (InetAddr a -> InetAddr a -> Bool)
-> (InetAddr a -> InetAddr a -> Bool)
-> (InetAddr a -> InetAddr a -> Bool)
-> (InetAddr a -> InetAddr a -> InetAddr a)
-> (InetAddr a -> InetAddr a -> InetAddr a)
-> Ord (InetAddr a)
InetAddr a -> InetAddr a -> Bool
InetAddr a -> InetAddr a -> Ordering
InetAddr a -> InetAddr a -> InetAddr 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 (InetAddr a)
forall a. Ord a => InetAddr a -> InetAddr a -> Bool
forall a. Ord a => InetAddr a -> InetAddr a -> Ordering
forall a. Ord a => InetAddr a -> InetAddr a -> InetAddr a
min :: InetAddr a -> InetAddr a -> InetAddr a
$cmin :: forall a. Ord a => InetAddr a -> InetAddr a -> InetAddr a
max :: InetAddr a -> InetAddr a -> InetAddr a
$cmax :: forall a. Ord a => InetAddr a -> InetAddr a -> InetAddr a
>= :: InetAddr a -> InetAddr a -> Bool
$c>= :: forall a. Ord a => InetAddr a -> InetAddr a -> Bool
> :: InetAddr a -> InetAddr a -> Bool
$c> :: forall a. Ord a => InetAddr a -> InetAddr a -> Bool
<= :: InetAddr a -> InetAddr a -> Bool
$c<= :: forall a. Ord a => InetAddr a -> InetAddr a -> Bool
< :: InetAddr a -> InetAddr a -> Bool
$c< :: forall a. Ord a => InetAddr a -> InetAddr a -> Bool
compare :: InetAddr a -> InetAddr a -> Ordering
$ccompare :: forall a. Ord a => InetAddr a -> InetAddr a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (InetAddr a)
Ord, Int -> InetAddr a -> ShowS
[InetAddr a] -> ShowS
InetAddr a -> String
(Int -> InetAddr a -> ShowS)
-> (InetAddr a -> String)
-> ([InetAddr a] -> ShowS)
-> Show (InetAddr a)
forall a. Show a => Int -> InetAddr a -> ShowS
forall a. Show a => [InetAddr a] -> ShowS
forall a. Show a => InetAddr a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InetAddr a] -> ShowS
$cshowList :: forall a. Show a => [InetAddr a] -> ShowS
show :: InetAddr a -> String
$cshow :: forall a. Show a => InetAddr a -> String
showsPrec :: Int -> InetAddr a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> InetAddr a -> ShowS
Show, ReadPrec [InetAddr a]
ReadPrec (InetAddr a)
Int -> ReadS (InetAddr a)
ReadS [InetAddr a]
(Int -> ReadS (InetAddr a))
-> ReadS [InetAddr a]
-> ReadPrec (InetAddr a)
-> ReadPrec [InetAddr a]
-> Read (InetAddr a)
forall a. Read a => ReadPrec [InetAddr a]
forall a. Read a => ReadPrec (InetAddr a)
forall a. Read a => Int -> ReadS (InetAddr a)
forall a. Read a => ReadS [InetAddr a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InetAddr a]
$creadListPrec :: forall a. Read a => ReadPrec [InetAddr a]
readPrec :: ReadPrec (InetAddr a)
$creadPrec :: forall a. Read a => ReadPrec (InetAddr a)
readList :: ReadS [InetAddr a]
$creadList :: forall a. Read a => ReadS [InetAddr a]
readsPrec :: Int -> ReadS (InetAddr a)
$creadsPrec :: forall a. Read a => Int -> ReadS (InetAddr a)
Read)
#if !MIN_VERSION_base(4,10,0)
deriving instance Typeable1 InetAddr
#endif
deriving instance Data a ⇒ Data (InetAddr a)
type Inet4Addr = InetAddr IP4
type Inet6Addr = InetAddr IP6
anInetAddr ∷ Proxy InetAddr
anInetAddr :: Proxy InetAddr
anInetAddr = Proxy InetAddr
forall k (t :: k). Proxy t
Proxy
anInetAddrOf ∷ Proxy a → Proxy (InetAddr a)
anInetAddrOf :: Proxy a -> Proxy (InetAddr a)
anInetAddrOf Proxy a
_ = Proxy (InetAddr a)
forall k (t :: k). Proxy t
Proxy
anInet4Addr ∷ Proxy Inet4Addr
anInet4Addr :: Proxy Inet4Addr
anInet4Addr = Proxy Inet4Addr
forall k (t :: k). Proxy t
Proxy
anInet6Addr ∷ Proxy Inet6Addr
anInet6Addr :: Proxy Inet6Addr
anInet6Addr = Proxy Inet6Addr
forall k (t :: k). Proxy t
Proxy
anInetAddrIP ∷ Proxy (InetAddr IP)
anInetAddrIP :: Proxy (InetAddr IP)
anInetAddrIP = Proxy (InetAddr IP)
forall k (t :: k). Proxy t
Proxy
instance Functor InetAddr where
fmap :: (a -> b) -> InetAddr a -> InetAddr b
fmap a -> b
f (InetAddr a
a InetPort
p) = b -> InetPort -> InetAddr b
forall a. a -> InetPort -> InetAddr a
InetAddr (a -> b
f a
a) InetPort
p
{-# INLINE fmap #-}
instance Printable Inet4Addr where
print :: Inet4Addr -> p
print (InetAddr IP4
a InetPort
p) = IP4 -> p
forall α p. (Printable α, Printer p) => α -> p
print IP4
a p -> p -> p
forall a. Semigroup a => a -> a -> a
<> Char -> p
forall p. Printer p => Char -> p
P.char7 Char
':' p -> p -> p
forall a. Semigroup a => a -> a -> a
<> InetPort -> p
forall α p. (Printable α, Printer p) => α -> p
print InetPort
p
{-# INLINABLE print #-}
instance Printable Inet6Addr where
print :: Inet6Addr -> p
print (InetAddr IP6
a InetPort
p) = p -> p
forall p. Printer p => p -> p
P.brackets (IP6 -> p
forall α p. (Printable α, Printer p) => α -> p
print IP6
a) p -> p -> p
forall a. Semigroup a => a -> a -> a
<> Char -> p
forall p. Printer p => Char -> p
P.char7 Char
':' p -> p -> p
forall a. Semigroup a => a -> a -> a
<> InetPort -> p
forall α p. (Printable α, Printer p) => α -> p
print InetPort
p
{-# INLINABLE print #-}
instance Printable (InetAddr IP) where
print :: InetAddr IP -> p
print (InetAddr (IPv4 IP4
a) InetPort
p) = Inet4Addr -> p
forall α p. (Printable α, Printer p) => α -> p
print (IP4 -> InetPort -> Inet4Addr
forall a. a -> InetPort -> InetAddr a
InetAddr IP4
a InetPort
p)
print (InetAddr (IPv6 IP6
a) InetPort
p) = Inet6Addr -> p
forall α p. (Printable α, Printer p) => α -> p
print (IP6 -> InetPort -> Inet6Addr
forall a. a -> InetPort -> InetAddr a
InetAddr IP6
a InetPort
p)
{-# INLINABLE print #-}
instance Textual Inet4Addr where
textual :: μ Inet4Addr
textual = IP4 -> InetPort -> Inet4Addr
forall a. a -> InetPort -> InetAddr a
InetAddr (IP4 -> InetPort -> Inet4Addr)
-> μ IP4 -> μ (InetPort -> Inet4Addr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP4
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual μ (InetPort -> Inet4Addr) -> μ InetPort -> μ Inet4Addr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':' μ Char -> μ InetPort -> μ InetPort
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> μ InetPort
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual)
μ Inet4Addr -> String -> μ Inet4Addr
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv4 socket address"
{-# INLINE textual #-}
instance Textual Inet6Addr where
textual :: μ Inet6Addr
textual = IP6 -> InetPort -> Inet6Addr
forall a. a -> InetPort -> InetAddr a
InetAddr (IP6 -> InetPort -> Inet6Addr)
-> μ IP6 -> μ (InetPort -> Inet6Addr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'[' μ Char -> μ IP6 -> μ IP6
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> μ IP6
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual μ IP6 -> μ Char -> μ IP6
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
']')
μ (InetPort -> Inet6Addr) -> μ InetPort -> μ Inet6Addr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':' μ Char -> μ InetPort -> μ InetPort
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> μ InetPort
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual)
μ Inet6Addr -> String -> μ Inet6Addr
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IPv6 socket address"
{-# INLINE textual #-}
instance Textual (InetAddr IP) where
textual :: μ (InetAddr IP)
textual = IP -> InetPort -> InetAddr IP
forall a. a -> InetPort -> InetAddr a
InetAddr
(IP -> InetPort -> InetAddr IP)
-> μ IP -> μ (InetPort -> InetAddr IP)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (μ Char -> μ (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
'[') μ (Maybe Char) -> (Maybe Char -> μ IP) -> μ IP
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe Char
Nothing → IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> IP) -> μ IP4 -> μ IP
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP4
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual
Just Char
_ → IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> IP) -> μ IP6 -> μ IP
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> μ IP6
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual μ IP -> μ Char -> μ IP
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
']')
μ (InetPort -> InetAddr IP) -> μ InetPort -> μ (InetAddr IP)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> μ Char
forall (m :: * -> *). CharParsing m => Char -> m Char
PC.char Char
':' μ Char -> μ InetPort -> μ InetPort
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> μ InetPort
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
textual)
μ (InetAddr IP) -> String -> μ (InetAddr IP)
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"IP socket address"
{-# INLINABLE textual #-}
instance Hashable a ⇒ Hashable (InetAddr a) where
#if MIN_VERSION_hashable(1,2,0)
hashWithSalt :: Int -> InetAddr a -> Int
hashWithSalt Int
s (InetAddr a
a InetPort
p) = Int
s Int -> a -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` a
a Int -> InetPort -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` InetPort
p
{-# INLINE hashWithSalt #-}
#else
hash (InetAddr a p) = hash a `combine` hash p
{-# INLINE hash #-}
#endif
instance Serializable a ⇒ Serializable (InetAddr a) where
put :: InetAddr a -> s
put (InetAddr a
a InetPort
p) = a -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put a
a s -> s -> s
forall a. Semigroup a => a -> a -> a
<> InetPort -> s
forall α s. (Serializable α, Serializer s) => α -> s
S.put InetPort
p
{-# INLINE put #-}
instance SizedSerializable a ⇒ SizedSerializable (InetAddr a) where
size :: Proxy (InetAddr a) -> Int
size Proxy (InetAddr a)
_ = Proxy a -> Int
forall α. SizedSerializable α => Proxy α -> Int
S.size (Proxy a
forall k (t :: k). Proxy t
Proxy ∷ Proxy a) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2
{-# INLINE size #-}
instance Deserializable a ⇒ Deserializable (InetAddr a) where
get :: μ (InetAddr a)
get = a -> InetPort -> InetAddr a
forall a. a -> InetPort -> InetAddr a
InetAddr (a -> InetPort -> InetAddr a) -> μ a -> μ (InetPort -> InetAddr a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (μ a
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get μ a -> String -> μ a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"host address") μ (InetPort -> InetAddr a) -> μ InetPort -> μ (InetAddr a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> μ InetPort
forall α (μ :: * -> *). (Deserializable α, Deserializer μ) => μ α
D.get μ (InetAddr a) -> String -> μ (InetAddr a)
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"socket address"
{-# INLINE get #-}
toInetAddr46 ∷ InetAddr IP → IP46 (InetAddr IP4) (InetAddr IP6)
toInetAddr46 :: InetAddr IP -> IP46 Inet4Addr Inet6Addr
toInetAddr46 (InetAddr (IPv4 IP4
a) InetPort
w) = Inet4Addr -> IP46 Inet4Addr Inet6Addr
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 (IP4 -> InetPort -> Inet4Addr
forall a. a -> InetPort -> InetAddr a
InetAddr IP4
a InetPort
w)
toInetAddr46 (InetAddr (IPv6 IP6
a) InetPort
w) = Inet6Addr -> IP46 Inet4Addr Inet6Addr
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 (IP6 -> InetPort -> Inet6Addr
forall a. a -> InetPort -> InetAddr a
InetAddr IP6
a InetPort
w)
{-# INLINABLE toInetAddr46 #-}
fromInetAddr46 ∷ IP46 (InetAddr IP4) (InetAddr IP6) → InetAddr IP
fromInetAddr46 :: IP46 Inet4Addr Inet6Addr -> InetAddr IP
fromInetAddr46 (IPv4 (InetAddr IP4
a InetPort
w)) = IP -> InetPort -> InetAddr IP
forall a. a -> InetPort -> InetAddr a
InetAddr (IP4 -> IP
forall t₄ t₆. t₄ -> IP46 t₄ t₆
IPv4 IP4
a) InetPort
w
fromInetAddr46 (IPv6 (InetAddr IP6
a InetPort
w)) = IP -> InetPort -> InetAddr IP
forall a. a -> InetPort -> InetAddr a
InetAddr (IP6 -> IP
forall t₄ t₆. t₆ -> IP46 t₄ t₆
IPv6 IP6
a) InetPort
w
{-# INLINABLE fromInetAddr46 #-}