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

Net.IPv4

Synopsis

Documentation

data IPv4Range Source #

The length should be between 0 and 32. These bounds are inclusive. This expectation is not in any way enforced by this library because it does not cause errors. A mask length greater than 32 will be treated as if it were 32.

Constructors

IPv4Range 

Instances

Instances details
Eq IPv4Range Source # 
Instance details

Defined in Net.IPv4

Ord IPv4Range Source # 
Instance details

Defined in Net.IPv4

Read IPv4Range Source # 
Instance details

Defined in Net.IPv4

Show IPv4Range Source # 
Instance details

Defined in Net.IPv4

Generic IPv4Range Source # 
Instance details

Defined in Net.IPv4

Associated Types

type Rep IPv4Range :: Type -> Type #

type Rep IPv4Range Source # 
Instance details

Defined in Net.IPv4

type Rep IPv4Range = D1 ('MetaData "IPv4Range" "Net.IPv4" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "IPv4Range" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipv4RangeBase") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 IPv4) :*: S1 ('MetaSel ('Just "ipv4RangeLength") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8)))

newtype IPv4 Source #

A 32-bit Internet Protocol version 4 address. To use this with the network library, it is necessary to use Network.Socket.htonl to convert the underlying Word32 from host byte order to network byte order.

Constructors

IPv4 

Fields

Instances

Instances details
Bounded IPv4 Source # 
Instance details

Defined in Net.IPv4

Enum IPv4 Source # 
Instance details

Defined in Net.IPv4

Methods

succ :: IPv4 -> IPv4 #

pred :: IPv4 -> IPv4 #

toEnum :: Int -> IPv4 #

fromEnum :: IPv4 -> Int #

enumFrom :: IPv4 -> [IPv4] #

enumFromThen :: IPv4 -> IPv4 -> [IPv4] #

enumFromTo :: IPv4 -> IPv4 -> [IPv4] #

enumFromThenTo :: IPv4 -> IPv4 -> IPv4 -> [IPv4] #

Eq IPv4 Source # 
Instance details

Defined in Net.IPv4

Methods

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

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

Ord IPv4 Source # 
Instance details

Defined in Net.IPv4

Methods

compare :: IPv4 -> IPv4 -> Ordering #

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

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

(>) :: IPv4 -> IPv4 -> Bool #

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

max :: IPv4 -> IPv4 -> IPv4 #

min :: IPv4 -> IPv4 -> IPv4 #

Read IPv4 Source # 
Instance details

Defined in Net.IPv4

Show IPv4 Source # 
Instance details

Defined in Net.IPv4

Methods

showsPrec :: Int -> IPv4 -> ShowS #

show :: IPv4 -> String #

showList :: [IPv4] -> ShowS #

Ix IPv4 Source # 
Instance details

Defined in Net.IPv4

Methods

range :: (IPv4, IPv4) -> [IPv4] #

index :: (IPv4, IPv4) -> IPv4 -> Int #

unsafeIndex :: (IPv4, IPv4) -> IPv4 -> Int #

inRange :: (IPv4, IPv4) -> IPv4 -> Bool #

rangeSize :: (IPv4, IPv4) -> Int #

unsafeRangeSize :: (IPv4, IPv4) -> Int #

Generic IPv4 Source # 
Instance details

Defined in Net.IPv4

Associated Types

type Rep IPv4 :: Type -> Type #

Methods

from :: IPv4 -> Rep IPv4 x #

to :: Rep IPv4 x -> IPv4 #

Bits IPv4 Source # 
Instance details

Defined in Net.IPv4

FiniteBits IPv4 Source # 
Instance details

Defined in Net.IPv4

Hashable IPv4 Source # 
Instance details

Defined in Net.IPv4

Methods

hashWithSalt :: Int -> IPv4 -> Int

hash :: IPv4 -> Int

type Rep IPv4 Source # 
Instance details

Defined in Net.IPv4

type Rep IPv4 = D1 ('MetaData "IPv4" "Net.IPv4" "graphql-engine-1.0.0-inplace" 'True) (C1 ('MetaCons "IPv4" 'PrefixI 'True) (S1 ('MetaSel ('Just "getIPv4") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

decodeRange :: Text -> Maybe IPv4Range Source #

Decode an IPv4Range from Text.

>>> IPv4.decodeRange "172.16.0.0/12"
Just (IPv4Range {ipv4RangeBase = ipv4 172 16 0 0, ipv4RangeLength = 12})
>>> IPv4.decodeRange "192.168.25.254/16"
Just (IPv4Range {ipv4RangeBase = ipv4 192 168 0 0, ipv4RangeLength = 16})

parserRange :: Parser IPv4Range Source #

Parse an IPv4Range using a Parser.

>>> AT.parseOnly IPv4.parserRange "192.168.25.254/16"
Right (IPv4Range {ipv4RangeBase = ipv4 192 168 0 0, ipv4RangeLength = 16})

parser :: Parser IPv4 Source #

Parse an IPv4 address using a Parser.

>>> AT.parseOnly IPv4.parser "192.168.2.47"
Right (ipv4 192 168 2 47)
>>> AT.parseOnly IPv4.parser "192.168.2.470"
Left "Failed reading: All octets in an IPv4 address must be between 0 and 255"

dotDecimalParser :: Parser IPv4 Source #

This does not do an endOfInput check because it is reused in the range parser implementation.

contains :: IPv4Range -> IPv4 -> Bool Source #

Checks to see if an IPv4 address belongs in the IPv4Range.

>>> let ip = IPv4.fromOctets 10 10 1 92
>>> IPv4.contains (IPv4.IPv4Range (IPv4.fromOctets 10 0 0 0) 8) ip
True
>>> IPv4.contains (IPv4.IPv4Range (IPv4.fromOctets 10 11 0 0) 16) 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 = IPv4.IPv4Range (IPv4.fromOctets 10 10 10 6) 31
>>> mapM_ (P.print . IPv4.contains r) (take 5 $ iterate succ $ IPv4.fromOctets 10 10 10 5)
False
True
True
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 :: IPv4 -> IPv4Range -> Bool Source #

This is provided to mirror the interface provided by Data.Set. It behaves just like contains but with flipped arguments.

IPv4.member ip r == IPv4.contains r ip

fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4 Source #

An alias for the ipv4 smart constructor.

fromTupleOctets :: (Word8, Word8, Word8, Word8) -> IPv4 Source #

An uncurried variant of fromOctets.

fromOctets' :: Word -> Word -> Word -> Word -> IPv4 Source #

This is sort of a misnomer. It takes Word to make dotDecimalParser perform better. This is mostly for internal use. The arguments must all fit in a Word8.

normalize :: IPv4Range -> IPv4Range Source #

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

>>> IPv4.printRange $ IPv4.normalize $ IPv4.IPv4Range (IPv4.fromOctets 192 168 1 19) 24
192.168.1.0/24
>>> IPv4.printRange $ IPv4.normalize $ IPv4.IPv4Range (IPv4.fromOctets 192 168 1 163) 28
192.168.1.160/28

The second effect of this is that the mask length is lowered to be 32 or smaller. Working with IPv4Ranges 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 32).

Note that normalize is idempotent, that is:

IPv4.normalize r == (IPv4.normalize . IPv4.normalize) r