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 InetAddr = InetAddr {}
- inetAny :: InetAddr
- inetBroadcast :: InetAddr
- inetNone :: InetAddr
- inetLoopback :: InetAddr
- inetUnspecificGroup :: InetAddr
- inetAllHostsGroup :: InetAddr
- inetMaxLocalGroup :: InetAddr
- inetAddrToTuple :: InetAddr -> (Word8, Word8, Word8, Word8)
- tupleToInetAddr :: (Word8, Word8, Word8, Word8) -> InetAddr
- data Inet6Addr = Inet6Addr !Word32 !Word32 !Word32 !Word32
- inet6Any :: Inet6Addr
- inet6Loopback :: Inet6Addr
- inet6AddrToTuple :: Inet6Addr -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
- tupleToInet6Addr :: (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) -> Inet6Addr
- type FlowInfo = Word32
- type ScopeID = Word32
- newtype PortNumber = PortNumber Word16
- portAny :: PortNumber
- data SocketFamily where
- pattern AF_UNSPEC :: SocketFamily
- pattern AF_INET :: SocketFamily
- pattern AF_INET6 :: SocketFamily
- data SocketType where
- pattern SOCK_DGRAM :: SocketType
- pattern SOCK_STREAM :: SocketType
- pattern SOCK_SEQPACKET :: SocketType
- pattern SOCK_RAW :: SocketType
- pattern SOCK_RDM :: SocketType
- pattern SOCK_ANY :: SocketType
- data ProtocolNumber where
- 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.
Instances
Eq SocketAddr Source # | |
Defined in Z.IO.Network.SocketAddr (==) :: SocketAddr -> SocketAddr -> Bool # (/=) :: SocketAddr -> SocketAddr -> Bool # | |
Ord SocketAddr Source # | |
Defined in Z.IO.Network.SocketAddr compare :: SocketAddr -> SocketAddr -> Ordering # (<) :: SocketAddr -> SocketAddr -> Bool # (<=) :: SocketAddr -> SocketAddr -> Bool # (>) :: SocketAddr -> SocketAddr -> Bool # (>=) :: SocketAddr -> SocketAddr -> Bool # max :: SocketAddr -> SocketAddr -> SocketAddr # min :: SocketAddr -> SocketAddr -> SocketAddr # | |
Show SocketAddr Source # | |
Defined in Z.IO.Network.SocketAddr showsPrec :: Int -> SocketAddr -> ShowS # show :: SocketAddr -> String # showList :: [SocketAddr] -> ShowS # |
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 inetAddrToTuple
and tupleToInetAddr
.
Instances
Eq InetAddr Source # | |
Ord InetAddr Source # | |
Defined in Z.IO.Network.SocketAddr | |
Show InetAddr Source # | |
Unaligned InetAddr Source # | |
Defined in Z.IO.Network.SocketAddr unalignedSize :: InetAddr -> Int # indexWord8ArrayAs# :: ByteArray# -> Int# -> InetAddr # readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, InetAddr#) # writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> InetAddr -> State# s -> State# s # peekMBA :: MutableByteArray# RealWorld -> Int -> IO InetAddr # pokeMBA :: MutableByteArray# RealWorld -> Int -> InetAddr -> IO () # indexBA :: ByteArray# -> Int -> InetAddr # | |
Storable InetAddr Source # | |
Defined in Z.IO.Network.SocketAddr |
inetBroadcast :: InetAddr Source #
255.255.255.255
inetLoopback :: InetAddr Source #
127.0.0.1
inetUnspecificGroup :: InetAddr Source #
224.0.0.0
inetAllHostsGroup :: InetAddr Source #
224.0.0.1
inetMaxLocalGroup :: InetAddr Source #
224.0.0.255
inetAddrToTuple :: InetAddr -> (Word8, Word8, Word8, Word8) Source #
Converts InetAddr
to representation-independent IPv4 quadruple.
For example for 127.0.0.1
the function will return (127, 0, 0, 1)
regardless of host endianness.
tupleToInetAddr :: (Word8, Word8, Word8, Word8) -> InetAddr Source #
Converts IPv4 quadruple to InetAddr
.
IPv6 address
Independent of endianness. For example ::1
is stored as (0, 0, 0, 1)
.
For direct manipulation prefer inet6AddrToTuple
and tupleToInet6Addr
.
Instances
Eq Inet6Addr Source # | |
Ord Inet6Addr Source # | |
Defined in Z.IO.Network.SocketAddr | |
Show Inet6Addr Source # | |
Unaligned Inet6Addr Source # | |
Defined in Z.IO.Network.SocketAddr unalignedSize :: Inet6Addr -> Int # indexWord8ArrayAs# :: ByteArray# -> Int# -> Inet6Addr # readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, Inet6Addr#) # writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> Inet6Addr -> State# s -> State# s # peekMBA :: MutableByteArray# RealWorld -> Int -> IO Inet6Addr # pokeMBA :: MutableByteArray# RealWorld -> Int -> Inet6Addr -> IO () # indexBA :: ByteArray# -> Int -> Inet6Addr # | |
Storable Inet6Addr Source # | |
Defined in Z.IO.Network.SocketAddr |
inet6Loopback :: Inet6Addr Source #
::1
inet6AddrToTuple :: Inet6Addr -> (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) Source #
convert Inet6Addr
to octets.
tupleToInet6Addr :: (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16) -> Inet6Addr Source #
convert Inet6Addr
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
data SocketFamily where Source #
pattern AF_UNSPEC :: SocketFamily | unspecified |
pattern AF_INET :: SocketFamily | internetwork: UDP, TCP, etc |
pattern AF_INET6 :: SocketFamily | Internet Protocol version 6 |
Instances
data SocketType where Source #
pattern SOCK_DGRAM :: SocketType | |
pattern SOCK_STREAM :: SocketType | |
pattern SOCK_SEQPACKET :: SocketType | |
pattern SOCK_RAW :: SocketType | |
pattern SOCK_RDM :: SocketType | |
pattern SOCK_ANY :: SocketType | Used in getAddrInfo hints, for any type can be returned by getAddrInfo |
Instances
data ProtocolNumber where Source #
pattern IPPROTO_DEFAULT :: ProtocolNumber | |
pattern IPPROTO_IP :: ProtocolNumber | |
pattern IPPROTO_TCP :: ProtocolNumber | |
pattern IPPROTO_UDP :: ProtocolNumber |
Instances
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 #