runNamed cnf findZone
= withSocketsDo $
do installHandler sigPIPE Ignore Nothing
- _tcpListenerTID <- forkIO $ tcpListen
- udpListen
+
+ let hint = defaultHints {
+ addrFlags = [AI_PASSIVE, AI_V4MAPPED]
+ , addrFamily = AF_INET6
+ , addrSocketType = NoSocketType
+ , addrProtocol = defaultProtocol
+ }
+ (ai:_) <- getAddrInfo (Just hint) Nothing (Just $ cnfServerPort cnf)
+
+ _tcpListenerTID <- forkIO $ tcpListen ai
+ udpListen ai
where
- udpListen :: IO ()
- udpListen = do -- FIXME: we should support IPv6 when the network package supports it.
- so <- socket AF_INET Datagram defaultProtocol
- bindSocket so $ cnfServerAddress cnf
- udpLoop so
+ udpListen :: AddrInfo -> IO ()
+ udpListen ai
+ = do so <- socket (addrFamily ai) Datagram defaultProtocol
+ bindSocket so (addrAddress ai)
+ udpLoop so
udpLoop :: Socket -> IO ()
udpLoop so
_handlerTID <- forkIO $ udpHandler so packet cameFrom
udpLoop so
- tcpListen :: IO ()
- tcpListen = do so <- socket AF_INET Stream defaultProtocol
- bindSocket so $ cnfServerAddress cnf
- listen so 255
- tcpLoop so
+ tcpListen :: AddrInfo -> IO ()
+ tcpListen ai
+ = do so <- socket (addrFamily ai) Stream defaultProtocol
+ bindSocket so (addrAddress ai)
+ listen so 255
+ tcpLoop so
tcpLoop :: Socket -> IO ()
tcpLoop so
data Config
= Config {
- cnfServerAddress :: !SockAddr
+ cnfServerPort :: !ServiceName
, cnfAllowTransfer :: !Bool
}
deriving Show
defaultConfig :: Config
defaultConfig = Config {
- cnfServerAddress = SockAddrInet 53 iNADDR_ANY
+ cnfServerPort = "domain"
, cnfAllowTransfer = False
}