From: PHO Date: Thu, 28 May 2009 03:06:34 +0000 (+0900) Subject: The server now accepts IPv6 connections. X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=826401d22c87d6c5d77ad4f427d28d6b97a9d12f;p=haskell-dns.git The server now accepts IPv6 connections. --- diff --git a/ExampleDNSServer.hs b/ExampleDNSServer.hs index 9fb8ee6..428f261 100644 --- a/ExampleDNSServer.hs +++ b/ExampleDNSServer.hs @@ -10,7 +10,7 @@ main = runNamed cnf (return . findZone) where cnf :: Config cnf = Config { - cnfServerAddress = SockAddrInet 9090 iNADDR_ANY + cnfServerPort = "9090" , cnfAllowTransfer = True } diff --git a/Network/DNS/Named.hs b/Network/DNS/Named.hs index 4a9eaed..3d0a6dc 100644 --- a/Network/DNS/Named.hs +++ b/Network/DNS/Named.hs @@ -27,14 +27,23 @@ runNamed :: Config -> (DomainName -> IO (Maybe Zone)) -> IO () 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 @@ -42,11 +51,12 @@ runNamed cnf findZone _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 diff --git a/Network/DNS/Named/Config.hs b/Network/DNS/Named/Config.hs index 4985897..febd5ba 100644 --- a/Network/DNS/Named/Config.hs +++ b/Network/DNS/Named/Config.hs @@ -9,13 +9,13 @@ import Network.Socket data Config = Config { - cnfServerAddress :: !SockAddr + cnfServerPort :: !ServiceName , cnfAllowTransfer :: !Bool } deriving Show defaultConfig :: Config defaultConfig = Config { - cnfServerAddress = SockAddrInet 53 iNADDR_ANY + cnfServerPort = "domain" , cnfAllowTransfer = False }