Copyright | (c) Winterland 2018 |
---|---|
License | BSD |
Maintainer | drkoster@qq.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides necessary types and constant for low level socket address manipulating.
Synopsis
- data SocketAddr
- ipv4 :: HasCallStack => CBytes -> PortNumber -> SocketAddr
- ipv6 :: HasCallStack => CBytes -> PortNumber -> SocketAddr
- sockAddrFamily :: SocketAddr -> SocketFamily
- withSocketAddr :: SocketAddr -> (Ptr SocketAddr -> IO a) -> IO a
- withSocketAddrUnsafe :: SocketAddr -> (MBA# SocketAddr -> IO a) -> IO a
- sizeOfSocketAddr :: SocketAddr -> CSize
- withSocketAddrStorage :: (Ptr SocketAddr -> IO ()) -> IO SocketAddr
- withSocketAddrStorageUnsafe :: (MBA# SocketAddr -> IO ()) -> IO SocketAddr
- sizeOfSocketAddrStorage :: CSize
- newtype IPv4 = IPv4 {}
- ipv4Any :: IPv4
- ipv4Broadcast :: IPv4
- ipv4None :: IPv4
- ipv4Loopback :: IPv4
- ipv4UnspecificGroup :: IPv4
- ipv4AllHostsGroup :: IPv4
- ipv4MaxLocalGroup :: IPv4
- ipv4AddrToTuple :: IPv4 -> (Word8, Word8, Word8, Word8)
- tupleToIPv4Addr :: (Word8, Word8, Word8, Word8) -> IPv4
- data IPv6 = IPv6 !Word32 !Word32 !Word32 !Word32
- ipv6Any :: IPv6
- ipv6Loopback :: IPv6
- ipv6AddrToTuple :: IPv6 -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
- tupleToIPv6Addr :: (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) -> IPv6
- type FlowInfo = Word32
- type ScopeID = Word32
- newtype PortNumber = PortNumber Word16
- portAny :: PortNumber
- type SocketFamily = CInt
- pattern AF_UNSPEC :: SocketFamily
- pattern AF_INET :: SocketFamily
- pattern AF_INET6 :: SocketFamily
- type SocketType = CInt
- pattern SOCK_DGRAM :: SocketType
- pattern SOCK_STREAM :: SocketType
- pattern SOCK_SEQPACKET :: SocketType
- pattern SOCK_RAW :: SocketType
- pattern SOCK_RDM :: SocketType
- pattern SOCK_ANY :: SocketType
- type ProtocolNumber = CInt
- pattern IPPROTO_DEFAULT :: ProtocolNumber
- pattern IPPROTO_IP :: ProtocolNumber
- pattern IPPROTO_TCP :: ProtocolNumber
- pattern IPPROTO_UDP :: ProtocolNumber
- peekSocketAddr :: HasCallStack => Ptr SocketAddr -> IO SocketAddr
- pokeSocketAddr :: Ptr SocketAddr -> SocketAddr -> IO ()
- peekSocketAddrMBA :: HasCallStack => MBA# SocketAddr -> IO SocketAddr
- pokeSocketAddrMBA :: MBA# SocketAddr -> SocketAddr -> IO ()
- htons :: Word16 -> Word16
- ntohs :: Word16 -> Word16
- ntohl :: Word32 -> Word32
- htonl :: Word32 -> Word32
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
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.
sizeOfSocketAddr :: SocketAddr -> CSize Source #
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
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.
Instances
Eq IPv4 Source # | |
Ord IPv4 Source # | |
Show IPv4 Source # | |
Generic IPv4 Source # | |
ToValue IPv4 Source # | |
Defined in Z.IO.Network.SocketAddr | |
EncodeJSON IPv4 Source # | |
Defined in Z.IO.Network.SocketAddr encodeJSON :: IPv4 -> Builder () # | |
FromValue IPv4 Source # | |
ShowT IPv4 Source # | |
Defined in Z.IO.Network.SocketAddr toUTF8BuilderP :: Int -> IPv4 -> Builder () # | |
Unaligned IPv4 Source # | |
Defined in Z.IO.Network.SocketAddr unalignedSize :: IPv4 -> Int # unalignedSize# :: IPv4 -> Int# # indexWord8ArrayAs# :: ByteArray# -> Int# -> IPv4 # readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, IPv4 #) # writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> IPv4 -> State# s -> State# s # peekMBA :: MutableByteArray# RealWorld -> Int -> IO IPv4 # pokeMBA :: MutableByteArray# RealWorld -> Int -> IPv4 -> IO () # indexBA :: ByteArray# -> Int -> IPv4 # | |
Storable IPv4 Source # | |
Defined in Z.IO.Network.SocketAddr | |
type Rep IPv4 Source # | |
Defined in Z.IO.Network.SocketAddr |
ipv4Broadcast :: IPv4 Source #
255.255.255.255
ipv4Loopback :: IPv4 Source #
127.0.0.1
ipv4UnspecificGroup :: IPv4 Source #
224.0.0.0
ipv4AllHostsGroup :: IPv4 Source #
224.0.0.1
ipv4MaxLocalGroup :: IPv4 Source #
224.0.0.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.
IPv6 address
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.
Instances
ipv6Loopback :: IPv6 Source #
::1
ipv6AddrToTuple :: IPv6 -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) Source #
convert IPv6
to octets.
tupleToIPv6Addr :: (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) -> IPv6 Source #
convert IPv6
from octets.
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
Instances
portAny :: PortNumber Source #
:0
family, type, protocol
SocketFamily
type SocketFamily = CInt Source #
pattern AF_UNSPEC :: SocketFamily Source #
unspecified
pattern AF_INET :: SocketFamily Source #
internetwork: UDP, TCP, etc
pattern AF_INET6 :: SocketFamily Source #
Internet Protocol version 6
type SocketType = CInt Source #
pattern SOCK_DGRAM :: SocketType Source #
pattern SOCK_STREAM :: SocketType Source #
pattern SOCK_SEQPACKET :: SocketType Source #
pattern SOCK_RAW :: SocketType Source #
pattern SOCK_RDM :: SocketType Source #
pattern SOCK_ANY :: SocketType Source #
Used in getAddrInfo hints, for any type can be returned by getAddrInfo
type ProtocolNumber = CInt Source #
pattern IPPROTO_DEFAULT :: ProtocolNumber Source #
pattern IPPROTO_IP :: ProtocolNumber Source #
pattern IPPROTO_TCP :: ProtocolNumber Source #
pattern IPPROTO_UDP :: ProtocolNumber Source #
Internal helper
peekSocketAddr :: HasCallStack => Ptr SocketAddr -> IO SocketAddr Source #
pokeSocketAddr :: Ptr SocketAddr -> SocketAddr -> IO () Source #
peekSocketAddrMBA :: HasCallStack => MBA# SocketAddr -> IO SocketAddr Source #
pokeSocketAddrMBA :: MBA# SocketAddr -> SocketAddr -> IO () Source #