Chapter 5. The net category: networking support

Table of Contents
5.1. BSD: System database info
5.2. Socket: The high-level networking interface
5.3. SocketPrim: The low-level socket binding
5.4. URI

(Darren Moffat supplied the initial version of this library.)

5.1. BSD: System database info

The BSD module provides functions to get at system-database info; pretty straightforward if you're into this sort of thing:
type HostName         = String

getHostName          :: IO Hostname

data ServiceEntry = ServiceEntry  {
   serviceName       :: ServiceName,   -- Official Name
   serviceAliases    :: [ServiceName], -- aliases
   servicePort       :: PortNumber,    -- Port Number (network byte order)
   serviceProtocol   :: ProtocolName   -- Protocol
 }
type ServiceName      = String

getServiceByName     :: ServiceName -> ProtocolName -> IO ServiceEntry
getServiceByPort     :: PortNumber  -> ProtocolName -> IO ServiceEntry
getServicePortNumber :: ServiceName -> IO PortNumber

-- not available con Cygwin/Mingw
getServiceEntry      :: IO ServiceEntry
setServiceEntry      :: Bool -> IO ()
endServiceEntry      :: IO ()
getServiceEntries    :: Bool -> IO [ServiceEntry]

type ProtocolName     = String
type ProtocolNumber   = Int   -- from SocketPrim

data ProtocolEntry = ProtocolEntry  {
     protoName       :: ProtocolName,   -- Official Name
     protoAliases    :: [ProtocolName], -- aliases
     protoNumber     :: ProtocolNumber  -- Protocol Number
 }

getProtocolByName    :: ProtocolName   -> IO ProtocolEntry
getProtocolByNumber  :: ProtocolNumber -> IO ProtcolEntry
getProtocolNumber    :: ProtocolName   -> ProtocolNumber

 -- not available con Cygwin/Mingw
setProtocolEntry     :: Bool -> IO ()
getProtocolEntry     :: IO ProtocolEntry
endProtocolEntry     :: IO ()
getProtocolEntries   :: Bool -> IO [ProtocolEntry]

-- from SocketPrim
newtype PortNumber    = -- instance of Eq, Ord, Enum, Num, Real, Integral, Show
   PNum Int             -- 16-bit value stored in network byte order.
mkPortNumber         :: Int -> PortNumber

data HostEntry = HostEntry {
     hostName        :: HostName,     -- Official Name
     hostAliases     :: [HostName],   -- aliases
     hostFamily      :: Family,       -- Host Type (currently AF_INET)
     hostAddresses   :: [HostAddress] -- Set of Network Addresses  (in network byte order)
 }

getHostByName        :: HostName -> IO HostEntry
getHostByAddr        :: HostAddress -> Family -> IO HostEntry
hostAddress          :: HostEntry -> HostAddress

-- not available con Cygwin/Mingw
setHostEntry         :: Bool -> IO ()
getHostEntry         :: IO HostEntry
endHostEntry         :: IO ()
getHostEntries       :: Bool -> IO [HostEntry]

type NetworkAddr      = Word -- host byte order
type NetworkName      = String

data NetworkEntry =
  NetworkEntry {
     networkName     :: NetworkName,   -- official name
     networkAliases  :: [NetworkName], -- aliases
     networkFamily   :: Family,        -- type
     networkAddress  :: NetworkAddr
   }

-- not available con Cygwin/Mingw
getNetworkByName     :: NetworkName -> IO NetworkEntry
getNetworkByAddr     :: NetworkAddr -> Family -> IO NetworkEntry
setNetworkEntry      :: Bool -> IO ()
getNetworkEntry      :: IO NetworkEntry
endNetworkEntry      :: IO ()
getNetworkEntries    :: Bool -> IO [NetworkEntry]

-- if available
symlink              :: String -> String -> IO ()
readlink             :: String -> IO String