Z-IO-0.4.0.0: Simple and high performance IO toolkit for Haskell
Copyright(c) Winterland 2018
LicenseBSD
Maintainerdrkoster@qq.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.IO.Network.SocketAddr

Description

This module provides necessary types and constant for low level socket address manipulating.

Synopsis

name to address

data SocketAddr Source #

IPv4 or IPv6 socket address, i.e. the sockaddr_in or sockaddr_in6 struct.

Example on JSON instance:

> JSON.encodeText  $ ipv6 "3731:54:65fe:2::a8" 9090
"{"addr":[14129,84,26110,2,0,0,0,168],"port":9090,"flow":0,"scope":0}"
> JSON.encodeText  $ ipv4 "128.14.32.1" 9090
"{"addr":[128,14,32,1],"port":9090}"

Instances

Instances details
Eq SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Ord SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Show SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Generic SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Associated Types

type Rep SocketAddr :: Type -> Type #

JSON SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Print SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

type Rep SocketAddr Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

ipv4 :: HasCallStack => CBytes -> PortNumber -> SocketAddr Source #

Convert a string containing an IPv4 addresses to a binary structure

This is partial function, wrong address will throw InvalidArgument exception.

ipv6 :: HasCallStack => CBytes -> PortNumber -> SocketAddr Source #

Convert a string containing an IPv6 addresses to a binary structure

This is partial function, wrong address will throw InvalidArgument exception.

withSocketAddr :: SocketAddr -> (Ptr SocketAddr -> IO a) -> IO a Source #

Pass SocketAddr to FFI as pointer.

withSocketAddrUnsafe :: SocketAddr -> (MBA# SocketAddr -> IO a) -> IO a Source #

Pass SocketAddr to FFI as pointer.

USE THIS FUNCTION WITH UNSAFE FFI CALL ONLY.

withSocketAddrStorage :: (Ptr SocketAddr -> IO ()) -> IO SocketAddr Source #

Allocate space for sockaddr_storage and pass to FFI.

withSocketAddrStorageUnsafe :: (MBA# SocketAddr -> IO ()) -> IO SocketAddr Source #

Allocate space for sockaddr_storage and pass to FFI.

USE THIS FUNCTION WITH UNSAFE FFI CALL ONLY.

IPv4 address

newtype IPv4 Source #

Independent of endianness. For example 127.0.0.1 is stored as (127, 0, 0, 1).

For direct manipulation prefer ipv4AddrToTuple and tupleToIPv4Addr.

JSON instance encode ipv4 address into an array with 4 Word8 octets.

Constructors

IPv4 

Fields

Instances

Instances details
Eq IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

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

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

Ord IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

compare :: IPv4 -> IPv4 -> Ordering #

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

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

(>) :: IPv4 -> IPv4 -> Bool #

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

max :: IPv4 -> IPv4 -> IPv4 #

min :: IPv4 -> IPv4 -> IPv4 #

Show IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

showsPrec :: Int -> IPv4 -> ShowS #

show :: IPv4 -> String #

showList :: [IPv4] -> ShowS #

Generic IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Associated Types

type Rep IPv4 :: Type -> Type #

Methods

from :: IPv4 -> Rep IPv4 x #

to :: Rep IPv4 x -> IPv4 #

JSON IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Print IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

toUTF8BuilderP :: Int -> IPv4 -> Builder () #

Unaligned IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Storable IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

sizeOf :: IPv4 -> Int #

alignment :: IPv4 -> Int #

peekElemOff :: Ptr IPv4 -> Int -> IO IPv4 #

pokeElemOff :: Ptr IPv4 -> Int -> IPv4 -> IO () #

peekByteOff :: Ptr b -> Int -> IO IPv4 #

pokeByteOff :: Ptr b -> Int -> IPv4 -> IO () #

peek :: Ptr IPv4 -> IO IPv4 #

poke :: Ptr IPv4 -> IPv4 -> IO () #

type Rep IPv4 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

type Rep IPv4 = D1 ('MetaData "IPv4" "Z.IO.Network.SocketAddr" "Z-IO-0.4.0.0-yZ8PAxRS7u6ehgjyvfzwd" 'True) (C1 ('MetaCons "IPv4" 'PrefixI 'True) (S1 ('MetaSel ('Just "getIPv4Addr") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

ipv4Any :: IPv4 Source #

0.0.0.0

ipv4Broadcast :: IPv4 Source #

255.255.255.255

ipv4None :: IPv4 Source #

255.255.255.255

ipv4AddrToTuple :: IPv4 -> (Word8, Word8, Word8, Word8) Source #

Converts IPv4 to representation-independent IPv4 quadruple. For example for 127.0.0.1 the function will return (127, 0, 0, 1) regardless of host endianness.

tupleToIPv4Addr :: (Word8, Word8, Word8, Word8) -> IPv4 Source #

Converts IPv4 quadruple to IPv4.

IPv6 address

data IPv6 Source #

Independent of endianness. For example ::1 is stored as (0, 0, 0, 1).

For direct manipulation prefer ipv6AddrToTuple and tupleToIPv6Addr.

JSON instance encode ipv6 address into an array with 8 Word16 octets.

Constructors

IPv6 !Word32 !Word32 !Word32 !Word32 

Instances

Instances details
Eq IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

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

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

Ord IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

compare :: IPv6 -> IPv6 -> Ordering #

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

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

(>) :: IPv6 -> IPv6 -> Bool #

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

max :: IPv6 -> IPv6 -> IPv6 #

min :: IPv6 -> IPv6 -> IPv6 #

Show IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

showsPrec :: Int -> IPv6 -> ShowS #

show :: IPv6 -> String #

showList :: [IPv6] -> ShowS #

Generic IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Associated Types

type Rep IPv6 :: Type -> Type #

Methods

from :: IPv6 -> Rep IPv6 x #

to :: Rep IPv6 x -> IPv6 #

JSON IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Print IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

toUTF8BuilderP :: Int -> IPv6 -> Builder () #

Unaligned IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Storable IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Methods

sizeOf :: IPv6 -> Int #

alignment :: IPv6 -> Int #

peekElemOff :: Ptr IPv6 -> Int -> IO IPv6 #

pokeElemOff :: Ptr IPv6 -> Int -> IPv6 -> IO () #

peekByteOff :: Ptr b -> Int -> IO IPv6 #

pokeByteOff :: Ptr b -> Int -> IPv6 -> IO () #

peek :: Ptr IPv6 -> IO IPv6 #

poke :: Ptr IPv6 -> IPv6 -> IO () #

type Rep IPv6 Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

port numbber

newtype PortNumber Source #

Port number.

Use the Num instance (i.e. use a literal) to create a -- PortNumber value.

>>> 1 :: PortNumber
1
>>> read "1" :: PortNumber
1
>>> show (12345 :: PortNumber)
"12345"
>>> 50000 < (51000 :: PortNumber)
True
>>> 50000 < (52000 :: PortNumber)
True
>>> 50000 + (10000 :: PortNumber)
60000

Constructors

PortNumber Word16 

Instances

Instances details
Bounded PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Enum PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Eq PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Integral PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Num PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Ord PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Read PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Real PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Show PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Generic PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Associated Types

type Rep PortNumber :: Type -> Type #

JSON PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Print PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Unaligned PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

Storable PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

type Rep PortNumber Source # 
Instance details

Defined in Z.IO.Network.SocketAddr

type Rep PortNumber = D1 ('MetaData "PortNumber" "Z.IO.Network.SocketAddr" "Z-IO-0.4.0.0-yZ8PAxRS7u6ehgjyvfzwd" 'True) (C1 ('MetaCons "PortNumber" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))

family, type, protocol

SocketFamily

pattern AF_UNSPEC :: SocketFamily Source #

unspecified

pattern AF_INET :: SocketFamily Source #

internetwork: UDP, TCP, etc

pattern AF_INET6 :: SocketFamily Source #

Internet Protocol version 6

pattern SOCK_ANY :: SocketType Source #

Used in getAddrInfo hints, for any type can be returned by getAddrInfo

Internal helper