-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Library for IP and MAC addresses -- -- The ip package provides types and functions for dealing with -- IPv4 addresses, CIDR blocks, and MAC addresses. We provide instances -- for typeclasses found in commonly used packages like aeson, -- vector, and hashable. We also provide Parsers for -- working with attoparsec. -- -- Notably, this package does not overload functions by introducing any -- typeclasses of its own. Neither does it prefix functions with the name -- of the type that they work on. Instead, functions of the same name are -- exported by several different modules, and it is expected that end -- users disambiguate by importing these modules qualified. -- -- The only module intended to be imported unqualified is -- Net.Types. The types in this package should not conflict with -- the types in any other commonly used packages. -- -- The following packages are intended to be used with this package: -- -- @package ip @version 1.0.0 module Net.IPv6 -- | A 128-bit Internet Protocol version 6 address. data IPv6 IPv6 :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> IPv6 [ipv6A] :: IPv6 -> {-# UNPACK #-} !Word64 [ipv6B] :: IPv6 -> {-# UNPACK #-} !Word64 fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> 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 ip = fromWord16s 0x3124 0x0 0x0 0xDEAD 0xCAFE 0xFF 0xFE00 0x1
--   
--   >>> ip
--   fromWord16s 0x3124 0x0000 0x0000 0xdead 0xcafe 0x00ff 0xfe00 0x0001
--   
--   >>> T.putStrLn (encode ip)
--   3124::dead:cafe:ff:fe00:1
--   
fromWord16s :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IPv6 toWord16s :: IPv6 -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) any :: IPv6 loopback :: IPv6 -- | Encodes the IP, using zero-compression on the leftmost-longest string -- of zeroes in the address. encode :: IPv6 -> Text decode :: Text -> Maybe IPv6 parser :: Parser IPv6 instance GHC.Read.Read Net.IPv6.S instance GHC.Show.Show Net.IPv6.S instance GHC.Classes.Ord Net.IPv6.IPv6 instance GHC.Classes.Eq Net.IPv6.IPv6 instance GHC.Show.Show Net.IPv6.IPv6 instance GHC.Read.Read Net.IPv6.IPv6 instance Data.Aeson.Types.ToJSON.ToJSON Net.IPv6.IPv6 instance Data.Aeson.Types.FromJSON.FromJSON Net.IPv6.IPv6 -- | 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. module Net.IPv4 -- | Create an IPv4 address from four octets. The first argument is -- the most significant octet. The last argument is the least -- significant. Since IP addresses are commonly written using dot-decimal -- notation, this is the recommended way to create an IP address. -- Additionally, it is used for the Show and Read instances -- of IPv4 to help keep things readable in GHCi. -- --
--   >>> let ip = fromOctets 192 168 1 1
--   
--   >>> ip
--   fromOctets 192 168 1 1
--   
--   >>> getIPv4 ip
--   3232235777
--   
fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4 -- | 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. toOctets :: IPv4 -> (Word8, Word8, Word8, Word8) -- | The IP address representing any host: 0.0.0.0 any :: IPv4 -- | The loopback IP address: 127.0.0.1 loopback :: IPv4 -- | The broadcast IP address: 255.255.255.255 broadcast :: IPv4 -- | Checks to see if the IPv4 address belongs to a private network. -- The three private networks that are checked are 10.0.0.0/8, -- 172.16.0.0/12, and 192.168.0.0/16. private :: IPv4 -> Bool -- | Checks to see if the IPv4 address belongs to a reserved -- network. This includes the three private networks that private -- checks along with several other ranges that are not used on the public -- Internet. reserved :: IPv4 -> Bool -- | Checks to see if the IPv4 address is publicly routable. -- --
--   public x == not (reserved x)
--   
public :: IPv4 -> Bool encode :: IPv4 -> Text decode :: Text -> Maybe IPv4 builder :: IPv4 -> Builder reader :: Reader IPv4 parser :: Parser IPv4 -- | This exists mostly for testing purposes. print :: IPv4 -> IO () encodeUtf8 :: IPv4 -> ByteString decodeUtf8 :: ByteString -> Maybe IPv4 builderUtf8 :: IPv4 -> Builder parserUtf8 :: Parser IPv4 encodeString :: IPv4 -> String decodeString :: String -> Maybe IPv4 -- | A 32-bit Internet Protocol version 4 address. newtype IPv4 IPv4 :: Word32 -> IPv4 [getIPv4] :: IPv4 -> Word32 instance Foreign.Storable.Storable Net.IPv4.IPv4 instance Data.Bits.FiniteBits Net.IPv4.IPv4 instance Data.Bits.Bits Net.IPv4.IPv4 instance Data.Primitive.Types.Prim Net.IPv4.IPv4 instance GHC.Generics.Generic Net.IPv4.IPv4 instance Data.Hashable.Class.Hashable Net.IPv4.IPv4 instance GHC.Enum.Bounded Net.IPv4.IPv4 instance GHC.Enum.Enum Net.IPv4.IPv4 instance GHC.Classes.Ord Net.IPv4.IPv4 instance GHC.Classes.Eq Net.IPv4.IPv4 instance GHC.Show.Show Net.IPv4.IPv4 instance GHC.Read.Read Net.IPv4.IPv4 instance Data.Vector.Unboxed.Base.Unbox Net.IPv4.IPv4 instance Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector Net.IPv4.IPv4 instance Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector Net.IPv4.IPv4 instance Data.Aeson.Types.ToJSON.ToJSON Net.IPv4.IPv4 instance Data.Aeson.Types.FromJSON.FromJSON Net.IPv4.IPv4 instance Data.Aeson.Types.ToJSON.ToJSONKey Net.IPv4.IPv4 instance Data.Aeson.Types.FromJSON.FromJSONKey Net.IPv4.IPv4 module Net.IPv4.Range -- | 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: -- --
--   >>> print $ normalize $ IPv4Range (fromOctets 192 168 1 19) 24
--   192.168.1.0/24
--   
--   >>> print $ normalize $ IPv4Range (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: -- --
--   normalize r == (normalize . normalize) r
--   
normalize :: IPv4Range -> IPv4Range -- | Checks to see if an IPv4 address belongs in the -- IPv4Range. -- --
--   >>> let ip = fromOctets 10 10 1 92
--   
--   >>> contains (IPv4Range (fromOctets 10 0 0 0) 8) ip
--   True
--   
--   >>> contains (IPv4Range (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 = IPv4Range (fromOctets 10 10 10 6) 31
--   
--   >>> mapM_ (P.print . contains r) (take 5 $ iterate succ $ 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. contains :: IPv4Range -> IPv4 -> Bool -- | 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
--   
member :: IPv4 -> IPv4Range -> Bool -- | The inclusive lower bound of an IPv4Range. This is -- conventionally understood to be the broadcast address of a subnet. For -- example: -- --
--   >>> I.print $ lowerInclusive $ IPv4Range (fromOctets 10 10 1 160) 25
--   10.10.1.128
--   
-- -- Note that the lower bound of a normalized IPv4Range is simply -- the ip address of the range: -- --
--   lowerInclusive r == ipv4RangeBase (normalize r)
--   
lowerInclusive :: IPv4Range -> IPv4 upperInclusive :: IPv4Range -> IPv4 -- | Convert an IPv4Range into a list of the IPv4 addresses -- that are in it. >>> let r = IPv4Range (fromOctets 192 168 1 -- 8) 30 >>> mapM_ I.print (toList r) 192.168.1.8 192.168.1.9 -- 192.168.1.10 192.168.1.11 toList :: IPv4Range -> [IPv4] toGenerator :: MonadPlus m => IPv4Range -> m IPv4 -- | The RFC1918 24-bit block. Subnet mask: 10.0.0.0/8 private24 :: IPv4Range -- | The RFC1918 20-bit block. Subnet mask: 172.16.0.0/12 private20 :: IPv4Range -- | The RFC1918 16-bit block. Subnet mask: 192.168.0.0/16 private16 :: IPv4Range encode :: IPv4Range -> Text decode :: Text -> Maybe IPv4Range builder :: IPv4Range -> Builder parser :: Parser IPv4Range -- | This exists mostly for testing purposes. print :: IPv4Range -> IO () -- | 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. data IPv4Range IPv4Range :: {-# UNPACK #-} !IPv4 -> {-# UNPACK #-} !Word8 -> IPv4Range [ipv4RangeBase] :: IPv4Range -> {-# UNPACK #-} !IPv4 [ipv4RangeLength] :: IPv4Range -> {-# UNPACK #-} !Word8 instance GHC.Generics.Generic Net.IPv4.Range.IPv4Range instance GHC.Read.Read Net.IPv4.Range.IPv4Range instance GHC.Show.Show Net.IPv4.Range.IPv4Range instance GHC.Classes.Ord Net.IPv4.Range.IPv4Range instance GHC.Classes.Eq Net.IPv4.Range.IPv4Range instance Data.Hashable.Class.Hashable Net.IPv4.Range.IPv4Range instance Data.Aeson.Types.ToJSON.ToJSON Net.IPv4.Range.IPv4Range instance Data.Aeson.Types.FromJSON.FromJSON Net.IPv4.Range.IPv4Range instance Data.Vector.Unboxed.Base.Unbox Net.IPv4.Range.IPv4Range instance Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector Net.IPv4.Range.IPv4Range instance Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector Net.IPv4.Range.IPv4Range module Net.IP case_ :: (IPv4 -> a) -> (IPv6 -> a) -> IP -> a -- | If the address is an IPv4 address, return the address. ipv4 :: IP -> Maybe IPv4 -- | If the address is an IPv6 address, and if it is not an -- IPv4-mapped IPv6 address, return the address. ipv6 :: IP -> Maybe IPv6 fromIPv4 :: IPv4 -> IP fromIPv6 :: IPv6 -> IP encode :: IP -> Text decode :: Text -> Maybe IP -- | A 32-bit IPv4 address or a 128-bit IPv6 address. -- Internally, this is just represented as an IPv6 address. The -- functions provided in Net.IP help simulate constructing and -- pattern matching on values of this type. All functions and typeclass -- methods that convert IP values to text will display it as an -- IPv4 address if possible. newtype IP IP :: IPv6 -> IP [getIP] :: IP -> IPv6 instance GHC.Classes.Ord Net.IP.IP instance GHC.Classes.Eq Net.IP.IP instance GHC.Show.Show Net.IP.IP instance GHC.Read.Read Net.IP.IP instance Data.Aeson.Types.ToJSON.ToJSON Net.IP.IP instance Data.Aeson.Types.FromJSON.FromJSON Net.IP.IP module Net.Mac fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Mac toOctets :: Mac -> (Word8, Word8, Word8, Word8, Word8, Word8) encode :: Mac -> Text encodeWith :: MacCodec -> Mac -> Text decode :: Text -> Maybe Mac decodeWith :: MacCodec -> Text -> Maybe Mac decodeEither :: Text -> Either String Mac decodeEitherWith :: MacCodec -> Text -> Either String Mac builder :: Mac -> Builder parser :: Parser Mac parserWith :: MacCodec -> Parser Mac encodeUtf8 :: Mac -> ByteString encodeWithUtf8 :: MacCodec -> Mac -> ByteString -- | Lenient decoding of MAC address that accepts lowercase, uppercase, and -- any kind separator. decodeUtf8 :: ByteString -> Maybe Mac decodeWithUtf8 :: MacCodec -> ByteString -> Maybe Mac -- | Make a bytestring builder from a Mac address using a colon as -- the separator. builderUtf8 :: Mac -> Builder -- | Parser for a Mac address using with a colon as the separator -- (i.e. FA:43:B2:C0:0F:99). parserUtf8 :: Parser Mac -- | Parser for a Mac address using the provided settings. parserWithUtf8 :: MacCodec -> Parser Mac parserLenientUtf8 :: Parser Mac -- | A 48-bit MAC address. Do not use the data constructor for this type. -- It is not considered part of the stable API, and it allows you to -- construct invalid MAC addresses. newtype Mac Mac :: Word64 -> Mac [getMac] :: Mac -> Word64 data MacCodec MacCodec :: !MacGrouping -> !Bool -> MacCodec [macCodecGrouping] :: MacCodec -> !MacGrouping [macCodecUpperCase] :: MacCodec -> !Bool -- | The format expected by the mac address parser. The Word8 taken -- by some of these constructors is the ascii value of the character to -- be used as the separator. This is typically a colon, a hyphen, or a -- space character. All decoding functions are case insensitive. data MacGrouping -- | Two-character groups, FA:2B:40:09:8C:11 MacGroupingPairs :: !Char -> MacGrouping -- | Three-character groups, 24B-F0A-025-829 MacGroupingTriples :: !Char -> MacGrouping -- | Four-character groups, A220.0745.CAC7 MacGroupingQuadruples :: !Char -> MacGrouping -- | No separator, 24AF4B5B0780 MacGroupingNoSeparator :: MacGrouping instance GHC.Generics.Generic Net.Mac.MacCodec instance GHC.Read.Read Net.Mac.MacCodec instance GHC.Show.Show Net.Mac.MacCodec instance GHC.Classes.Ord Net.Mac.MacCodec instance GHC.Classes.Eq Net.Mac.MacCodec instance GHC.Generics.Generic Net.Mac.MacGrouping instance GHC.Read.Read Net.Mac.MacGrouping instance GHC.Show.Show Net.Mac.MacGrouping instance GHC.Classes.Ord Net.Mac.MacGrouping instance GHC.Classes.Eq Net.Mac.MacGrouping instance GHC.Generics.Generic Net.Mac.Mac instance GHC.Read.Read Net.Mac.Mac instance GHC.Show.Show Net.Mac.Mac instance GHC.Classes.Ord Net.Mac.Mac instance GHC.Classes.Eq Net.Mac.Mac instance Data.Hashable.Class.Hashable Net.Mac.Mac instance Data.Aeson.Types.ToJSON.ToJSON Net.Mac.Mac instance Data.Aeson.Types.ToJSON.ToJSONKey Net.Mac.Mac instance Data.Aeson.Types.FromJSON.FromJSONKey Net.Mac.Mac instance Data.Aeson.Types.FromJSON.FromJSON Net.Mac.Mac module Net.Types -- | A 32-bit Internet Protocol version 4 address. newtype IPv4 IPv4 :: Word32 -> IPv4 [getIPv4] :: IPv4 -> Word32 -- | A 128-bit Internet Protocol version 6 address. data IPv6 IPv6 :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> IPv6 [ipv6A] :: IPv6 -> {-# UNPACK #-} !Word64 [ipv6B] :: IPv6 -> {-# UNPACK #-} !Word64 -- | A 32-bit IPv4 address or a 128-bit IPv6 address. -- Internally, this is just represented as an IPv6 address. The -- functions provided in Net.IP help simulate constructing and -- pattern matching on values of this type. All functions and typeclass -- methods that convert IP values to text will display it as an -- IPv4 address if possible. newtype IP IP :: IPv6 -> IP [getIP] :: IP -> IPv6 -- | 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. data IPv4Range IPv4Range :: {-# UNPACK #-} !IPv4 -> {-# UNPACK #-} !Word8 -> IPv4Range [ipv4RangeBase] :: IPv4Range -> {-# UNPACK #-} !IPv4 [ipv4RangeLength] :: IPv4Range -> {-# UNPACK #-} !Word8 -- | A 48-bit MAC address. Do not use the data constructor for this type. -- It is not considered part of the stable API, and it allows you to -- construct invalid MAC addresses. newtype Mac Mac :: Word64 -> Mac [getMac] :: Mac -> Word64 data MacCodec MacCodec :: !MacGrouping -> !Bool -> MacCodec [macCodecGrouping] :: MacCodec -> !MacGrouping [macCodecUpperCase] :: MacCodec -> !Bool -- | The format expected by the mac address parser. The Word8 taken -- by some of these constructors is the ascii value of the character to -- be used as the separator. This is typically a colon, a hyphen, or a -- space character. All decoding functions are case insensitive. data MacGrouping -- | Two-character groups, FA:2B:40:09:8C:11 MacGroupingPairs :: !Char -> MacGrouping -- | Three-character groups, 24B-F0A-025-829 MacGroupingTriples :: !Char -> MacGrouping -- | Four-character groups, A220.0745.CAC7 MacGroupingQuadruples :: !Char -> MacGrouping -- | No separator, 24AF4B5B0780 MacGroupingNoSeparator :: MacGrouping