graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Net.IPv6

Synopsis

Documentation

decodeRange :: Text -> Maybe IPv6Range Source #

Decode an IPv6Range from Text.

>>> addr = IPv6.ipv6 0xDEAD 0xBEEF 0x3240 0xA426 0xBA68 0x1CD0 0x4263 0x109B
>>> fmap IPv6.encodeRange $ IPv6.decodeRange (Text.pack "dead:beef:3240:a426:ba68:1cd0:4263:109b/28")
Just "dead:bee0::/28"

parserRange :: Parser IPv6Range Source #

Parse an IPv6Range using a Parser.

data IPv6Range Source #

An IPv6Range. It is made up of the first IPv6 in the range and its length.

Constructors

IPv6Range 

Instances

Instances details
Eq IPv6Range Source # 
Instance details

Defined in Net.IPv6

Ord IPv6Range Source # 
Instance details

Defined in Net.IPv6

Read IPv6Range Source # 
Instance details

Defined in Net.IPv6

Show IPv6Range Source # 
Instance details

Defined in Net.IPv6

Generic IPv6Range Source # 
Instance details

Defined in Net.IPv6

Associated Types

type Rep IPv6Range :: Type -> Type #

type Rep IPv6Range Source # 
Instance details

Defined in Net.IPv6

newtype IPv6 Source #

A 128-bit Internet Protocol version 6 address.

Constructors

IPv6 

Fields

parser :: Parser IPv6 Source #

Parse an IPv6 using Parser.

>>> Atto.parseOnly IPv6.parser (Text.pack "dead:beef:3240:a426:ba68:1cd0:4263:109b")
Right (ipv6 0xdead 0xbeef 0x3240 0xa426 0xba68 0x1cd0 0x4263 0x109b)

normalize :: IPv6Range -> IPv6Range Source #

Normalize an IPv6Range. The first result of this is that the IPv6 inside the IPv6Range is changed so that the insignificant bits are zeroed out. For example:

>>> addr1 = IPv6.ipv6 0x0192 0x0168 0x0001 0x0019 0x0000 0x0000 0x0000 0x0000
>>> addr2 = IPv6.ipv6 0x0192 0x0168 0x0001 0x0163 0x0000 0x0000 0x0000 0x0000
>>> IPv6.printRange $ IPv6.normalize $ IPv6.IPv6Range addr1 24
192:100::/24
>>> IPv6.printRange $ IPv6.normalize $ IPv6.IPv6Range addr2 28
192:160::/28

The second effect of this is that the mask length is lowered to be 128 or smaller. Working with IPv6Ranges that have not been normalized does not cause any issues for this library, although other applications may reject such ranges (especially those with a mask length above 128).

Note that 'normalize is idempotent, that is:

IPv6.normalize r == (IPv6.normalize . IPv6.normalize) r

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

An alias for the ipv6 smart constructor.

fromWord16sWord128 :: Word128 -> Word128 -> Word128 -> Word128 -> Word128 -> Word128 -> Word128 -> Word128 -> Word128 Source #

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.

IPv6.member ip r == IPv6.contains r ip

contains :: IPv6Range -> IPv6 -> Bool Source #

Checks to see if an IPv6 address belongs in the IPv6Range.

>>> let ip = IPv6.ipv6 0x2001 0x0db8 0x0db8 0x1094 0x2051 0x0000 0x0000 0x0001
>>> let iprange mask = IPv6.IPv6Range (IPv6.ipv6 0x2001 0x0db8 0x0000 0x0000 0x0000 0x0000 0x0000 0x0001) mask
>>> IPv6.contains (iprange 8) ip
True
>>> IPv6.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 = IPv6.IPv6Range (IPv6.ipv6 0x2001 0x0db8 0x0000 0x0000 0x0000 0x0000 0x0000 0x0001) 64
>>> fmap (IPv6.contains r) (take 5 $ iterate succ $ IPv6.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.

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.

fromWord32sWord128 :: Word128 -> Word128 -> Word128 -> Word128 -> Word128 Source #