Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
- ipv4 :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4
- fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4
- fromTupleOctets :: (Word8, Word8, Word8, Word8) -> IPv4
- toOctets :: IPv4 -> (Word8, Word8, Word8, Word8)
- any :: IPv4
- loopback :: IPv4
- broadcast :: IPv4
- private :: IPv4 -> Bool
- reserved :: IPv4 -> Bool
- public :: IPv4 -> Bool
- encode :: IPv4 -> Text
- decode :: Text -> Maybe IPv4
- builder :: IPv4 -> Builder
- reader :: Reader IPv4
- parser :: Parser IPv4
- encodeUtf8 :: IPv4 -> ByteString
- decodeUtf8 :: ByteString -> Maybe IPv4
- builderUtf8 :: IPv4 -> Builder
- parserUtf8 :: Parser IPv4
- encodeString :: IPv4 -> String
- decodeString :: String -> Maybe IPv4
- print :: IPv4 -> IO ()
- newtype IPv4 = IPv4 {}
Conversion Functions
ipv4 :: 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 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 addr = ipv4 192 168 1 1
>>>
addr
ipv4 192 168 1 1>>>
getIPv4 addr
3232235777
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
.
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.
Special IP Addresses
Range Predicates
private :: IPv4 -> Bool Source #
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
.
public :: IPv4 -> Bool Source #
Checks to see if the IPv4
address is publicly routable.
public x == not (reserved x)
Textual Conversion
Text
UTF-8 ByteString
encodeUtf8 :: IPv4 -> ByteString Source #
Encode an IPv4
address to a UTF-8 encoded ByteString
.
decodeUtf8 :: ByteString -> Maybe IPv4 Source #
builderUtf8 :: IPv4 -> Builder Source #
parserUtf8 :: Parser IPv4 Source #
String
These functions exist for the convenience of those who need a
String
representation of an IPv4
address. Using them
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
).
encodeString :: IPv4 -> String Source #
Printing
Types
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.
Bounded IPv4 Source # | |
Enum IPv4 Source # | |
Eq IPv4 Source # | |
Ord IPv4 Source # | |
Read IPv4 Source # | |
Show IPv4 Source # | |
Generic IPv4 Source # | |
Hashable IPv4 Source # | |
ToJSON IPv4 Source # | |
ToJSONKey IPv4 Source # | |
FromJSON IPv4 Source # | |
FromJSONKey IPv4 Source # | |
Storable IPv4 Source # | |
Bits IPv4 Source # | |
FiniteBits IPv4 Source # | |
Prim IPv4 Source # | |
Unbox IPv4 Source # | |
Vector Vector IPv4 Source # | |
MVector MVector IPv4 Source # | |
type Rep IPv4 Source # | |
data Vector IPv4 Source # | |
data MVector s IPv4 Source # | |