Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- ipv6 :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6
- fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> IPv6
- fromWord16s :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6
- fromWord32s :: Word32 -> Word32 -> Word32 -> Word32 -> IPv6
- fromTupleWord16s :: (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) -> IPv6
- fromTupleWord32s :: (Word32, Word32, Word32, Word32) -> IPv6
- toWord16s :: IPv6 -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
- toWord32s :: IPv6 -> (Word32, Word32, Word32, Word32)
- any :: IPv6
- loopback :: IPv6
- encode :: IPv6 -> Text
- decode :: Text -> Maybe IPv6
- parser :: Parser IPv6
- print :: IPv6 -> IO ()
- range :: IPv6 -> Word8 -> IPv6Range
- fromBounds :: IPv6 -> IPv6 -> IPv6Range
- normalize :: IPv6Range -> IPv6Range
- contains :: IPv6Range -> IPv6 -> Bool
- member :: IPv6 -> IPv6Range -> Bool
- lowerInclusive :: IPv6Range -> IPv6
- upperInclusive :: IPv6Range -> IPv6
- encodeRange :: IPv6Range -> Text
- decodeRange :: Text -> Maybe IPv6Range
- parserRange :: Parser IPv6Range
- printRange :: IPv6Range -> IO ()
- data IPv6 = IPv6 {}
- data IPv6Range = IPv6Range {
- ipv6RangeBase :: !IPv6
- ipv6RangeLength :: !Word8
Convert
ipv6 :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6 Source #
Create an IPv6
address from the eight 16-bit fragments that make
it up. This closely resembles the standard IPv6 notation, so
is used for the Show
instance. Note that this lacks the formatting
feature for suppress zeroes in an IPv6
address, but it should be
readable enough for hacking in GHCi.
>>>
let addr = ipv6 0x3124 0x0 0x0 0xDEAD 0xCAFE 0xFF 0xFE00 0x1
>>>
addr
ipv6 0x3124 0x0000 0x0000 0xdead 0xcafe 0x00ff 0xfe00 0x0001>>>
T.putStrLn (encode addr)
3124::dead:cafe:ff:fe00:1
fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> IPv6 Source #
fromWord16s :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6 Source #
An alias for the ipv6
smart constructor.
fromWord32s :: Word32 -> Word32 -> Word32 -> Word32 -> IPv6 Source #
Build an IPv6
from four 32-bit words. The leftmost argument
is the high word and the rightword is the low word.
fromTupleWord16s :: (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) -> IPv6 Source #
Uncurried variant of fromWord16s
.
fromTupleWord32s :: (Word32, Word32, Word32, Word32) -> IPv6 Source #
Uncurried variant of fromWord32s
.
toWord16s :: IPv6 -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) Source #
Convert an IPv6
to eight 16-bit words.
Special IP Addresses
Textual Conversion
Text
encode :: IPv6 -> Text Source #
Encodes the IP, using zero-compression on the leftmost-longest string of zeroes in the address. Per RFC 5952 Section 5, this uses mixed notation when encoding an IPv4-mapped IPv6 address:
>>>
T.putStrLn $ encode $ fromWord16s 0xDEAD 0xBEEF 0x0 0x0 0x0 0x0 0x0 0x1234
dead:beef::1234>>>
T.putStrLn $ encode $ fromWord16s 0x0 0x0 0x0 0x0 0x0 0xFFFF 0x6437 0xA5B4
::ffff:100.55.165.180>>>
T.putStrLn $ encode $ fromWord16s 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
::
decode :: Text -> Maybe IPv6 Source #
Decode an IPv6 address. This accepts both standard IPv6 notation (with zero compression) and mixed notation for IPv4-mapped IPv6 addresses.
Printing
IPv6 Ranges
Range functions
contains :: IPv6Range -> IPv6 -> Bool Source #
Checks to see if an IPv6
address belongs in the IPv6Range
.
>>>
let ip = ipv6 0x2001 0x0db8 0x0db8 0x1094 0x2051 0x0000 0x0000 0x0001
>>>
let iprange mask = IPv6Range (ipv6 0x2001 0x0db8 0x0000 0x0000 0x0000 0x0000 0x0000 0x0001) mask
>>>
contains (iprange 8) ip
True>>>
contains (iprange 48) ip
False
Typically, element-testing functions are written to take the element as the first argument and the set as the second argument. This is intentionally written the other way for better performance when iterating over a collection. For example, you might test elements in a list for membership like this:
>>>
let r = IPv6Range (ipv6 0x2001 0x0db8 0x0000 0x0000 0x0000 0x0000 0x0000 0x0001) 64
>>>
fmap (contains r) (take 5 $ iterate succ $ ipv6 0x2001 0x0db8 0x0000 0x0000 0xffff 0xffff 0xffff 0xfffe)
[True,True,False,False,False]
The implementation of contains
ensures that (with GHC), the bitmask
creation and range normalization only occur once in the above example.
They are reused as the list is iterated.
member :: IPv6 -> IPv6Range -> Bool Source #
This is provided to mirror the interface provided by Data.Set
. It
behaves just like contains
but with flipped arguments.
member ip r == contains r ip
lowerInclusive :: IPv6Range -> IPv6 Source #
The inclusive lower bound of an IPv6Range
. This is conventionally
understood to be the broadcast address of a subnet. For example:
>>>
T.putStrLn $ encode $ lowerInclusive $ IPv6Range (ipv6 0x2001 0x0db8 0x0000 0x0000 0x0000 0x0000 0x0000 0x0001) 25
2001:d80::
Note that the lower bound of a normalized IPv4Range
is simply the
ip address of the range:
lowerInclusive r == ipv6RangeBase (normalize r)
upperInclusive :: IPv6Range -> IPv6 Source #
Textual Conversion
Text
encodeRange :: IPv6Range -> Text Source #
printRange :: IPv6Range -> IO () Source #
This exists mostly for testing purposes.
Types
A 128-bit Internet Protocol version 6 address.
Instances
Bounded IPv6 Source # | |
Enum IPv6 Source # | Since |
Eq IPv6 Source # | |
Ord IPv6 Source # | |
Read IPv6 Source # | |
Show IPv6 Source # | |
ToJSON IPv6 Source # | |
FromJSON IPv6 Source # | |
Prim IPv6 Source # | |
Defined in Net.IPv6 alignment# :: IPv6 -> Int# # indexByteArray# :: ByteArray# -> Int# -> IPv6 # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, IPv6#) # writeByteArray# :: MutableByteArray# s -> Int# -> IPv6 -> State# s -> State# s # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> IPv6 -> State# s -> State# s # indexOffAddr# :: Addr# -> Int# -> IPv6 # readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, IPv6#) # writeOffAddr# :: Addr# -> Int# -> IPv6 -> State# s -> State# s # setOffAddr# :: Addr# -> Int# -> Int# -> IPv6 -> State# s -> State# s # |
IPv6Range | |
|
Instances
Eq IPv6Range Source # | |
Ord IPv6Range Source # | |
Defined in Net.IPv6 | |
Read IPv6Range Source # | |
Show IPv6Range Source # | |
Generic IPv6Range Source # | |
type Rep IPv6Range Source # | |
Defined in Net.IPv6 type Rep IPv6Range = D1 (MetaData "IPv6Range" "Net.IPv6" "ip-1.4.0-Junhy5A5FRoFlPpNTJeTWQ" False) (C1 (MetaCons "IPv6Range" PrefixI True) (S1 (MetaSel (Just "ipv6RangeBase") SourceUnpack SourceStrict DecidedStrict) (Rec0 IPv6) :*: S1 (MetaSel (Just "ipv6RangeLength") SourceUnpack SourceStrict DecidedStrict) (Rec0 Word8))) |