ip-1.4.1: Library for IP and MAC addresses

Safe HaskellNone
LanguageHaskell2010

Net.IP

Contents

Description

An IP data type representing either an IPv4 address or an IPv6 address. The user can think of this as though it were a sum type. However, to minimize indirections, it is actually implemented as an IPv6 address, with IPv4 addresses being represented as an IPv4-mapped IPv6 addresses:

+---------+---------+--------------+
| 80 bits | 16 bits | 32 bits      |
+---------+---------+--------------+
| 00...00 | FFFF    | IPv4 address |
+---------+---------+--------------+

All functions and instance methods that deal with textual conversion will encode an IP using either dot-decimal notation (for IPv4) or RFC 5952 (for IPv6). They will decode an IP from either format as well. The Show instance presents an address in as valid haskell code that resembles the formatted address:

>>> decode "192.168.3.100"
Just (ipv4 192 168 3 100)
>>> decode "A3F5:12:F26::1466:8B91"
Just (ipv6 0xa3f5 0x0012 0x0f26 0x0000 0x0000 0x0000 0x1466 0x8b91)
Synopsis

Pattern Matching

case_ :: (IPv4 -> a) -> (IPv6 -> a) -> IP -> a Source #

Construction

ipv4 :: Word8 -> Word8 -> Word8 -> Word8 -> IP Source #

Construct an IP address from the four octets of an IPv4 address.

ipv6 :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> IP Source #

Construct an IP address from the eight 16-bit chunks of an IPv6 address.

Textual Conversion

Text

Printing

print :: IP -> IO () Source #

Types

newtype IP Source #

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.

Constructors

IP 

Fields

Instances
Eq IP Source # 
Instance details

Defined in Net.IP

Methods

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

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

Ord IP Source # 
Instance details

Defined in Net.IP

Methods

compare :: IP -> IP -> Ordering #

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

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

(>) :: IP -> IP -> Bool #

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

max :: IP -> IP -> IP #

min :: IP -> IP -> IP #

Read IP Source # 
Instance details

Defined in Net.IP

Show IP Source # 
Instance details

Defined in Net.IP

Methods

showsPrec :: Int -> IP -> ShowS #

show :: IP -> String #

showList :: [IP] -> ShowS #

Generic IP Source # 
Instance details

Defined in Net.IP

Associated Types

type Rep IP :: * -> * #

Methods

from :: IP -> Rep IP x #

to :: Rep IP x -> IP #

ToJSON IP Source # 
Instance details

Defined in Net.IP

FromJSON IP Source # 
Instance details

Defined in Net.IP

NFData IP Source # 
Instance details

Defined in Net.IP

Methods

rnf :: IP -> () #

type Rep IP Source # 
Instance details

Defined in Net.IP

type Rep IP = D1 (MetaData "IP" "Net.IP" "ip-1.4.1-EoFLganEe87B23MDW12YOQ" True) (C1 (MetaCons "IP" PrefixI True) (S1 (MetaSel (Just "getIP") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 IPv6)))