Copyright | (c) The University of Glasgow 2001 |
---|---|
License | BSD-3-Clause |
Maintainer | libraries@haskell.org |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
The Network.BSD module defines Haskell bindings to network programming functionality (mostly network database operations) provided by BSD Unix derivatives.
NOTE: Some of the types are reexported from Network.Socket in order to make the network-bsd
API self-contained.
Windows compatibility
The following functions are not exported by Network.BSD on the Windows platform:
getHostEntries
,setHostEntry
,getHostEntry
,endHostEntry
getServiceEntries
,getServiceEntry
,setServiceEntry
,endServiceEntry
getProtocolEntries
,setProtocolEntry
,getProtocolEntry
,endProtocolEntry
getNetworkByName
,getNetworkByAddr
,getNetworkEntries
,setNetworkEntry
,getNetworkEntry
,endNetworkEntry
Synopsis
- type HostName = String
- type HostAddress = Word32
- data Family
- = AF_UNSPEC
- | AF_UNIX
- | AF_INET
- | AF_INET6
- | AF_IMPLINK
- | AF_PUP
- | AF_CHAOS
- | AF_NS
- | AF_NBS
- | AF_ECMA
- | AF_DATAKIT
- | AF_CCITT
- | AF_SNA
- | AF_DECnet
- | AF_DLI
- | AF_LAT
- | AF_HYLINK
- | AF_APPLETALK
- | AF_ROUTE
- | AF_NETBIOS
- | AF_NIT
- | AF_802
- | AF_ISO
- | AF_OSI
- | AF_NETMAN
- | AF_X25
- | AF_AX25
- | AF_OSINET
- | AF_GOSSIP
- | AF_IPX
- | Pseudo_AF_XTP
- | AF_CTF
- | AF_WAN
- | AF_SDL
- | AF_NETWARE
- | AF_NDD
- | AF_INTF
- | AF_COIP
- | AF_CNT
- | Pseudo_AF_RTIP
- | Pseudo_AF_PIP
- | AF_SIP
- | AF_ISDN
- | Pseudo_AF_KEY
- | AF_NATM
- | AF_ARP
- | Pseudo_AF_HDRCMPLT
- | AF_ENCAP
- | AF_LINK
- | AF_RAW
- | AF_RIF
- | AF_NETROM
- | AF_BRIDGE
- | AF_ATMPVC
- | AF_ROSE
- | AF_NETBEUI
- | AF_SECURITY
- | AF_PACKET
- | AF_ASH
- | AF_ECONET
- | AF_ATMSVC
- | AF_IRDA
- | AF_PPPOX
- | AF_WANPIPE
- | AF_BLUETOOTH
- | AF_CAN
- getHostName :: IO HostName
- data HostEntry = HostEntry {
- hostName :: HostName
- hostAliases :: [HostName]
- hostFamily :: Family
- hostAddresses :: [HostAddress]
- getHostByName :: HostName -> IO HostEntry
- getHostByAddr :: Family -> HostAddress -> IO HostEntry
- hostAddress :: HostEntry -> HostAddress
- getHostEntries :: Bool -> IO [HostEntry]
- setHostEntry :: Bool -> IO ()
- getHostEntry :: IO HostEntry
- endHostEntry :: IO ()
- data ServiceEntry = ServiceEntry {}
- type ServiceName = String
- data PortNumber
- getServiceByName :: ServiceName -> ProtocolName -> IO ServiceEntry
- getServiceByPort :: PortNumber -> ProtocolName -> IO ServiceEntry
- getServicePortNumber :: ServiceName -> IO PortNumber
- getServiceEntries :: Bool -> IO [ServiceEntry]
- getServiceEntry :: IO ServiceEntry
- setServiceEntry :: Bool -> IO ()
- endServiceEntry :: IO ()
- type ProtocolName = String
- type ProtocolNumber = CInt
- data ProtocolEntry = ProtocolEntry {}
- getProtocolByName :: ProtocolName -> IO ProtocolEntry
- getProtocolByNumber :: ProtocolNumber -> IO ProtocolEntry
- getProtocolNumber :: ProtocolName -> IO ProtocolNumber
- defaultProtocol :: ProtocolNumber
- getProtocolEntries :: Bool -> IO [ProtocolEntry]
- setProtocolEntry :: Bool -> IO ()
- getProtocolEntry :: IO ProtocolEntry
- endProtocolEntry :: IO ()
- type NetworkName = String
- type NetworkAddr = CULong
- data NetworkEntry = NetworkEntry {}
- getNetworkByName :: NetworkName -> IO NetworkEntry
- getNetworkByAddr :: NetworkAddr -> Family -> IO NetworkEntry
- getNetworkEntries :: Bool -> IO [NetworkEntry]
- setNetworkEntry :: Bool -> IO ()
- getNetworkEntry :: IO NetworkEntry
- endNetworkEntry :: IO ()
- ifNameToIndex :: String -> IO (Maybe Int)
Host names and network addresses
Either a host name e.g., "haskell.org"
or a numeric host
address string consisting of a dotted decimal IPv4 address or an
IPv6 address e.g., "192.168.0.1"
.
type HostAddress = Word32 #
The raw network byte order number is read using host byte order.
Therefore on little-endian architectures the byte order is swapped. For
example 127.0.0.1
is represented as 0x0100007f
on little-endian hosts
and as 0x7f000001
on big-endian hosts.
For direct manipulation prefer hostAddressToTuple
and
tupleToHostAddress
.
Address families.
A constructor being present here does not mean it is supported by the
operating system: see isSupportedFamily
.
AF_UNSPEC | unspecified |
AF_UNIX | UNIX-domain |
AF_INET | Internet Protocol version 4 |
AF_INET6 | Internet Protocol version 6 |
AF_IMPLINK | Arpanet imp addresses |
AF_PUP | pup protocols: e.g. BSP |
AF_CHAOS | mit CHAOS protocols |
AF_NS | XEROX NS protocols |
AF_NBS | nbs protocols |
AF_ECMA | european computer manufacturers |
AF_DATAKIT | datakit protocols |
AF_CCITT | CCITT protocols, X.25 etc |
AF_SNA | IBM SNA |
AF_DECnet | DECnet |
AF_DLI | Direct data link interface |
AF_LAT | LAT |
AF_HYLINK | NSC Hyperchannel |
AF_APPLETALK | Apple Talk |
AF_ROUTE | Internal Routing Protocol (aka AF_NETLINK) |
AF_NETBIOS | NetBios-style addresses |
AF_NIT | Network Interface Tap |
AF_802 | IEEE 802.2, also ISO 8802 |
AF_ISO | ISO protocols |
AF_OSI | umbrella of all families used by OSI |
AF_NETMAN | DNA Network Management |
AF_X25 | CCITT X.25 |
AF_AX25 | AX25 |
AF_OSINET | AFI |
AF_GOSSIP | US Government OSI |
AF_IPX | Novell Internet Protocol |
Pseudo_AF_XTP | eXpress Transfer Protocol (no AF) |
AF_CTF | Common Trace Facility |
AF_WAN | Wide Area Network protocols |
AF_SDL | SGI Data Link for DLPI |
AF_NETWARE | Netware |
AF_NDD | NDD |
AF_INTF | Debugging use only |
AF_COIP | connection-oriented IP, aka ST II |
AF_CNT | Computer Network Technology |
Pseudo_AF_RTIP | Help Identify RTIP packets |
Pseudo_AF_PIP | Help Identify PIP packets |
AF_SIP | Simple Internet Protocol |
AF_ISDN | Integrated Services Digital Network |
Pseudo_AF_KEY | Internal key-management function |
AF_NATM | native ATM access |
AF_ARP | ARP (RFC 826) |
Pseudo_AF_HDRCMPLT | Used by BPF to not rewrite hdrs in iface output |
AF_ENCAP | ENCAP |
AF_LINK | Link layer interface |
AF_RAW | Link layer interface |
AF_RIF | raw interface |
AF_NETROM | Amateur radio NetROM |
AF_BRIDGE | multiprotocol bridge |
AF_ATMPVC | ATM PVCs |
AF_ROSE | Amateur Radio X.25 PLP |
AF_NETBEUI | Netbeui 802.2LLC |
AF_SECURITY | Security callback pseudo AF |
AF_PACKET | Packet family |
AF_ASH | Ash |
AF_ECONET | Acorn Econet |
AF_ATMSVC | ATM SVCs |
AF_IRDA | IRDA sockets |
AF_PPPOX | PPPoX sockets |
AF_WANPIPE | Wanpipe API sockets |
AF_BLUETOOTH | bluetooth sockets |
AF_CAN | Controller Area Network |
getHostName :: IO HostName Source #
Calling getHostName
returns the standard host name for the current
processor, as set at boot time.
gethostname(2)
.
Representation of the POSIX hostent
structure defined in <netdb.h>.
HostEntry | |
|
Instances
Read HostEntry Source # | |
Show HostEntry Source # | |
Storable HostEntry Source # | |
Defined in Network.BSD | |
NFData HostEntry Source # | Since: 2.8.1.0 |
Defined in Network.BSD |
getHostByAddr :: Family -> HostAddress -> IO HostEntry Source #
Get a HostEntry
corresponding to the given address and family.
Note that only IPv4 is currently supported.
hostAddress :: HostEntry -> HostAddress Source #
Low level functionality
setHostEntry :: Bool -> IO () Source #
sethostent(3)
.
getHostEntry :: IO HostEntry Source #
gethostent(3)
.
endHostEntry :: IO () Source #
endhostent(3)
.
Service names
data ServiceEntry Source #
Representation of the POSIX servent
structure defined in <netdb.h>.
ServiceEntry | |
|
Instances
Show ServiceEntry Source # | |
Defined in Network.BSD showsPrec :: Int -> ServiceEntry -> ShowS # show :: ServiceEntry -> String # showList :: [ServiceEntry] -> ShowS # | |
Storable ServiceEntry Source # | |
Defined in Network.BSD sizeOf :: ServiceEntry -> Int # alignment :: ServiceEntry -> Int # peekElemOff :: Ptr ServiceEntry -> Int -> IO ServiceEntry # pokeElemOff :: Ptr ServiceEntry -> Int -> ServiceEntry -> IO () # peekByteOff :: Ptr b -> Int -> IO ServiceEntry # pokeByteOff :: Ptr b -> Int -> ServiceEntry -> IO () # peek :: Ptr ServiceEntry -> IO ServiceEntry # poke :: Ptr ServiceEntry -> ServiceEntry -> IO () # | |
NFData ServiceEntry Source # | Since: 2.8.1.0 |
Defined in Network.BSD rnf :: ServiceEntry -> () # |
type ServiceName = String #
Either a service name e.g., "http"
or a numeric port number.
data PortNumber #
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
getServiceByName :: ServiceName -> ProtocolName -> IO ServiceEntry Source #
Get service by name.
getServiceByPort :: PortNumber -> ProtocolName -> IO ServiceEntry Source #
Get the service given a PortNumber
and ProtocolName
.
getServicePortNumber :: ServiceName -> IO PortNumber Source #
Get the PortNumber
corresponding to the ServiceName
.
getServiceEntries :: Bool -> IO [ServiceEntry] Source #
Retrieve list of all ServiceEntry
via getservent(3)
.
Low level functionality
getServiceEntry :: IO ServiceEntry Source #
getservent(3)
.
setServiceEntry :: Bool -> IO () Source #
setservent(3)
.
endServiceEntry :: IO () Source #
endservent(3)
.
Protocol names
type ProtocolName = String Source #
type ProtocolNumber = CInt #
Protocl number.
data ProtocolEntry Source #
Representation of the POSIX protoent
structure defined in <netdb.h>.
ProtocolEntry | |
|
Instances
Read ProtocolEntry Source # | |
Defined in Network.BSD readsPrec :: Int -> ReadS ProtocolEntry # readList :: ReadS [ProtocolEntry] # | |
Show ProtocolEntry Source # | |
Defined in Network.BSD showsPrec :: Int -> ProtocolEntry -> ShowS # show :: ProtocolEntry -> String # showList :: [ProtocolEntry] -> ShowS # | |
Storable ProtocolEntry Source # | |
Defined in Network.BSD sizeOf :: ProtocolEntry -> Int # alignment :: ProtocolEntry -> Int # peekElemOff :: Ptr ProtocolEntry -> Int -> IO ProtocolEntry # pokeElemOff :: Ptr ProtocolEntry -> Int -> ProtocolEntry -> IO () # peekByteOff :: Ptr b -> Int -> IO ProtocolEntry # pokeByteOff :: Ptr b -> Int -> ProtocolEntry -> IO () # peek :: Ptr ProtocolEntry -> IO ProtocolEntry # poke :: Ptr ProtocolEntry -> ProtocolEntry -> IO () # | |
NFData ProtocolEntry Source # | Since: 2.8.1.0 |
Defined in Network.BSD rnf :: ProtocolEntry -> () # |
getProtocolByName :: ProtocolName -> IO ProtocolEntry Source #
getprotobyname(3)
.
getProtocolByNumber :: ProtocolNumber -> IO ProtocolEntry Source #
getprotobynumber(3)
.
getProtocolNumber :: ProtocolName -> IO ProtocolNumber Source #
getprotobyname(3)
.
defaultProtocol :: ProtocolNumber #
This is the default protocol for a given service.
>>>
defaultProtocol
0
getProtocolEntries :: Bool -> IO [ProtocolEntry] Source #
Retrieve list of all ProtocolEntry
via getprotoent(3)
.
Low level functionality
setProtocolEntry :: Bool -> IO () Source #
setprotoent(3)
.
getProtocolEntry :: IO ProtocolEntry Source #
getprotoent(3)
.
endProtocolEntry :: IO () Source #
endprotoent(3)
.
Network names
type NetworkName = String Source #
type NetworkAddr = CULong Source #
data NetworkEntry Source #
Representation of the POSIX netent
structure defined in <netdb.h>.
NetworkEntry | |
|
Instances
Read NetworkEntry Source # | |
Defined in Network.BSD readsPrec :: Int -> ReadS NetworkEntry # readList :: ReadS [NetworkEntry] # | |
Show NetworkEntry Source # | |
Defined in Network.BSD showsPrec :: Int -> NetworkEntry -> ShowS # show :: NetworkEntry -> String # showList :: [NetworkEntry] -> ShowS # | |
Storable NetworkEntry Source # | |
Defined in Network.BSD sizeOf :: NetworkEntry -> Int # alignment :: NetworkEntry -> Int # peekElemOff :: Ptr NetworkEntry -> Int -> IO NetworkEntry # pokeElemOff :: Ptr NetworkEntry -> Int -> NetworkEntry -> IO () # peekByteOff :: Ptr b -> Int -> IO NetworkEntry # pokeByteOff :: Ptr b -> Int -> NetworkEntry -> IO () # peek :: Ptr NetworkEntry -> IO NetworkEntry # poke :: Ptr NetworkEntry -> NetworkEntry -> IO () # | |
NFData NetworkEntry Source # | Since: 2.8.1.0 |
Defined in Network.BSD rnf :: NetworkEntry -> () # |
getNetworkByName :: NetworkName -> IO NetworkEntry Source #
getnetbyname(3)
.
getNetworkByAddr :: NetworkAddr -> Family -> IO NetworkEntry Source #
getnetbyaddr(3)
.
getNetworkEntries :: Bool -> IO [NetworkEntry] Source #
Get the list of network entries via getnetent(3)
.
Low level functionality
setNetworkEntry :: Bool -> IO () Source #
Open the network name database. The parameter specifies whether a connection is maintained open between various networkEntry calls
setnetent(3)
.
getNetworkEntry :: IO NetworkEntry Source #
getnetent(3)
.
endNetworkEntry :: IO () Source #
Close the connection to the network name database.
endnetent(3)
.