postgresql-types-0.1.2: Precise PostgreSQL types representation and driver-agnostic codecs
Safe HaskellNone
LanguageHaskell2010

PostgresqlTypes.Inet

Synopsis

Documentation

data Inet Source #

PostgreSQL inet type.

Holds an IPv4 or IPv6 host address, and optionally its subnet, all in one field. The subnet is represented by the number of network address bits present in the host address (the “netmask”). If the netmask is 32 and the address is IPv4, then the value does not indicate a subnet, only a single host. In IPv6, the address length is 128 bits, so 128 bits specify a unique host address. Note that if you want to accept only networks, you should use the cidr type rather than inet.

The input format for this type is address/y where address is an IPv4 or IPv6 address and y is the number of bits in the netmask. If the /y portion is omitted, the netmask is taken to be 32 for IPv4 or 128 for IPv6, so the value represents just a single host. On display, the /y portion is suppressed if the netmask specifies a single host.

PostgreSQL docs.

Instances

Instances details
Arbitrary Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Methods

arbitrary :: Gen Inet #

shrink :: Inet -> [Inet] #

IsString Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Methods

fromString :: String -> Inet #

Read Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Show Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Methods

showsPrec :: Int -> Inet -> ShowS #

show :: Inet -> String #

showList :: [Inet] -> ShowS #

Eq Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Methods

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

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

Ord Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Methods

compare :: Inet -> Inet -> Ordering #

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

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

(>) :: Inet -> Inet -> Bool #

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

max :: Inet -> Inet -> Inet #

min :: Inet -> Inet -> Inet #

Hashable Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Methods

hashWithSalt :: Int -> Inet -> Int #

hash :: Inet -> Int #

IsScalar Inet Source # 
Instance details

Defined in PostgresqlTypes.Inet

Accessors

fold Source #

Arguments

:: (Word32 -> Word8 -> a)

Function to handle IPv4 address case.

Takes the IPv4 address as Word32 and the netmask as Word8 both in big-endian order.

-> (Word32 -> Word32 -> Word32 -> Word32 -> Word8 -> a)

Function to handle IPv6 address case.

Takes the four 32-bit words of the IPv6 address in big-endian order and the netmask as Word8.

-> Inet 
-> a 

Pattern match on Inet type.

refineToV4 :: Inet -> Maybe (Word32, Word8) Source #

Refine an IPv4 Inet value from a 32-bit address and an 8-bit netmask, both in big-endian order.

refineToV6 :: Inet -> Maybe (Word32, Word32, Word32, Word32, Word8) Source #

Refine an IPv6 Inet value from four 32-bit words representing the address and an 8-bit netmask, all in big-endian order.

Constructors

normalizeFromV4 Source #

Arguments

:: Word32

IPv4 address as a 32-bit big-endian word.

-> Word8

Network mask length (0-32).

-> Inet 

Construct an IPv4 Inet value from a 32-bit address and an 8-bit netmask, both in big-endian order.

The netmask is clamped to be in the range 0-32.

normalizeFromV6 Source #

Arguments

:: Word32

First 32 bits of IPv6 address in big-endian order.

-> Word32

Second 32 bits of IPv6 address in big-endian order.

-> Word32

Third 32 bits of IPv6 address in big-endian order.

-> Word32

Fourth 32 bits of IPv6 address in big-endian order.

-> Word8

Network mask length (0-128).

-> Inet 

Construct an IPv6 Inet value from four 32-bit words representing the address and an 8-bit netmask, all in big-endian order.

The netmask is clamped to be in the range 0-128.

refineFromV4 Source #

Arguments

:: Word32

IPv4 address as a 32-bit big-endian word.

-> Word8

Network mask length (0-32).

-> Maybe Inet 

Refine an IPv4 Inet value from a 32-bit address and an 8-bit netmask, both in big-endian order.

Returns Nothing if the netmask is out of range (greater than 32).

refineFromV6 Source #

Arguments

:: Word32

First 32 bits of IPv6 address in big-endian order.

-> Word32

Second 32 bits of IPv6 address in big-endian order.

-> Word32

Third 32 bits of IPv6 address in big-endian order.

-> Word32

Fourth 32 bits of IPv6 address in big-endian order.

-> Word8

Network mask length (0-128).

-> Maybe Inet 

Refine an IPv6 Inet value from four 32-bit words representing the address and an 8-bit netmask, all in big-endian order.

Returns Nothing if the netmask is out of range (greater than 128).