-- 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 imported these modules qualified. For example, -- Data.IPv4.Text and Data.IPv4.ByteString.Char8 have -- nearly identical export lists. -- -- 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: -- --
-- >>> fromOctets 192 168 1 1
-- IPv4 {getIPv4 = 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 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: -- --
-- >>> prRange $ normalize $ IPv4Range (fromOctets 192 168 1 19) 24 -- 192.168.1.0/24 -- -- >>> prRange $ 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_ (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 -- | This only exists for doctests. Do not use it. prRange :: IPv4Range -> IO () module Net.IPv4.Range.Text encode :: IPv4Range -> Text decode :: Text -> Maybe IPv4Range decodeEither :: Text -> Either String IPv4Range builder :: IPv4Range -> Builder parser :: Parser IPv4Range -- | This exists mostly for testing purposes. print :: IPv4Range -> IO () module Net.IPv4.Text encode :: IPv4 -> Text decode :: Text -> Maybe IPv4 decodeEither :: Text -> Either String IPv4 builder :: IPv4 -> Builder reader :: Reader IPv4 parser :: Parser IPv4 -- | This exists mostly for testing purposes. print :: IPv4 -> IO () -- | This module exists for the convenience of those who need a -- String representation of an IPv4 address. Using this -- module is discouraged unless the end user is working with a library -- that can only use String to deal with textual data (such as -- pandoc, hxr, or network). module Net.IPv4.String encode :: IPv4 -> String decode :: String -> Maybe IPv4 decodeEither :: String -> Either String IPv4 module Net.IPv4.ByteString.Char8 -- | This should be rewritten to not create Text as an -- intermediate step. encode :: IPv4 -> ByteString -- | This should also be rewritten decode :: ByteString -> Maybe IPv4 builder :: IPv4 -> Builder parser :: Parser IPv4 module Net.Mac fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Mac fromOctetsNoCast :: Word16 -> Word16 -> Word32 -> Word32 -> Word32 -> Word32 -> Mac module Net.Mac.Text encode :: Mac -> Text decode :: Text -> Maybe Mac decodeEither :: Text -> Either String Mac builder :: Mac -> Builder parser :: Parser Mac encodeWith :: MacEncoding -> Mac -> Text module Net.Mac.ByteString.Char8 -- | This is a bad implementation that should be rewritten encode :: Mac -> ByteString -- | This is a bad implementation that should be rewritten decode :: ByteString -> Maybe Mac builder :: Mac -> Builder parser :: Parser Mac