ip-1.3.0: Library for IP and MAC addresses

Safe HaskellNone
LanguageHaskell2010

Net.IPv6

Contents

Synopsis

Types

data IPv6 #

A 128-bit Internet Protocol version 6 address.

Constructors

IPv6 

Fields

Instances
Eq IPv6 # 
Instance details

Defined in Net.IPv6

Methods

(==) :: IPv6 -> IPv6 -> Bool #

(/=) :: IPv6 -> IPv6 -> Bool #

Ord IPv6 # 
Instance details

Defined in Net.IPv6

Methods

compare :: IPv6 -> IPv6 -> Ordering #

(<) :: IPv6 -> IPv6 -> Bool #

(<=) :: IPv6 -> IPv6 -> Bool #

(>) :: IPv6 -> IPv6 -> Bool #

(>=) :: IPv6 -> IPv6 -> Bool #

max :: IPv6 -> IPv6 -> IPv6 #

min :: IPv6 -> IPv6 -> IPv6 #

Read IPv6 # 
Instance details

Defined in Net.IPv6

Show IPv6 # 
Instance details

Defined in Net.IPv6

Methods

showsPrec :: Int -> IPv6 -> ShowS #

show :: IPv6 -> String #

showList :: [IPv6] -> ShowS #

ToJSON IPv6 # 
Instance details

Defined in Net.IPv6

FromJSON IPv6 # 
Instance details

Defined in Net.IPv6

Prim IPv6 # 
Instance details

Defined in Net.IPv6

Convert

ipv6 :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6 #

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 #

fromWord16s :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6 #

An alias for the ipv6 smart constructor.

fromWord32s :: Word32 -> Word32 -> Word32 -> Word32 -> IPv6 #

Build an IPv6 from four 32-bit words. The leftmost argument is the high word and the rightword is the low word.

fromTupleWord32s :: (Word32, Word32, Word32, Word32) -> IPv6 #

Uncurried variant of fromWord32s.

toWord16s :: IPv6 -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) #

Convert an IPv6 to eight 16-bit words.

toWord32s :: IPv6 -> (Word32, Word32, Word32, Word32) #

Convert an IPv6 to four 32-bit words.

Special IP Addresses

Textual Conversion

Text

encode :: IPv6 -> Text #

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 #

Decode an IPv6 address. This accepts both standard IPv6 notation (with zero compression) and mixed notation for IPv4-mapped IPv6 addresses.

Printing

print :: IPv6 -> IO () #