| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Net.IPv4
Description
An IPv4 data type
This module provides the IPv4 data type and functions for working
with it. There are also encoding and decoding functions provided
in this module, but they should be imported from
Net.IPv4.Text and Net.IPv4.ByteString.Char8 instead. They are
defined here so that the FromJSON and ToJSON instances can
use them.
At some point, a highly efficient IPv4-to-ByteString function needs
to be added to this module to take advantage of aeson's new
toEncoding method.
- newtype IPv4 = IPv4 {}
- data IPv4Range = IPv4Range {
- ipv4RangeBase :: !IPv4
- ipv4RangeLength :: !Word8
- mask :: Word8 -> Word32
- normalize :: IPv4Range -> IPv4Range
- member :: IPv4 -> IPv4Range -> Bool
- lowerInclusive :: IPv4Range -> IPv4
- upperInclusive :: IPv4Range -> IPv4
- private24 :: IPv4Range
- private20 :: IPv4Range
- private16 :: IPv4Range
- fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4
- fromOctets' :: Word32 -> Word32 -> Word32 -> Word32 -> IPv4
- toOctets :: IPv4 -> (Word8, Word8, Word8, Word8)
- prAddr :: IPv4 -> IO ()
- prRange :: IPv4Range -> IO ()
- fromDotDecimalText :: Text -> Maybe IPv4
- fromDotDecimalText' :: Text -> Either String IPv4
- rangeFromDotDecimalText' :: Text -> Either String IPv4Range
- dotDecimalRangeParser :: Parser IPv4Range
- dotDecimalParser :: Parser IPv4
- toDotDecimalText :: IPv4 -> Text
- toDotDecimalBuilder :: IPv4 -> Builder
- rangeToDotDecimalText :: IPv4Range -> Text
- rangeToDotDecimalBuilder :: IPv4Range -> Builder
Types
A 32-bit Internet Protocol address.
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 | |
Fields
| |
Range functions
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:
>>>prRange $ normalize $ IPv4Range (fromOctets 192 168 1 19) 24192.168.1.0/24>>>prRange $ normalize $ IPv4Range (fromOctets 192 168 1 163) 28192.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:
normalize r == (normalize . normalize) r
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.
member ip r == contains r ip
lowerInclusive :: IPv4Range -> IPv4 Source #
upperInclusive :: IPv4Range -> IPv4 Source #
Private Ranges
Conversion Functions
fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4 Source #
Create an IPv4 address from four octets. The first argument
is the most significant octet. The last argument is the least
significant.
Since the Show and Read instances for IPv4 are not generally
usefully, this function is the recommened way to create IPv4 addresses.
For example:
>>>fromOctets 192 168 1 1IPv4 {getIPv4 = 3232235777}
fromOctets' :: Word32 -> Word32 -> Word32 -> Word32 -> IPv4 Source #
This is sort of a misnomer. It takes Word32 to make dotDecimalParser probably perform better. This is mostly for internal use.
toOctets :: IPv4 -> (Word8, Word8, Word8, Word8) Source #
Convert an IPv4 address into a quadruple of octets. The first
element in the quadruple is the most significant octet. The last
element is the least significant octet.
Internal Functions
dotDecimalParser :: Parser IPv4 Source #
This does not do an endOfInput check because it is reused in the range parser implementation.
toDotDecimalText :: IPv4 -> Text Source #
toDotDecimalBuilder :: IPv4 -> Builder Source #