X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource.hs;h=3a27e9ca5e1acbe786d83a949e7711c6d0657ffb;hp=e48ea217ff99b6c7bc9c6e0a3057ab8c904db636;hb=d0558f77cf306aa2cab58a71aeecff04c1ffcd06;hpb=fc530e41ff8f5f2372b261badecf10891c16546c diff --git a/Network/HTTP/Lucu/Resource.hs b/Network/HTTP/Lucu/Resource.hs index e48ea21..3a27e9c 100644 --- a/Network/HTTP/Lucu/Resource.hs +++ b/Network/HTTP/Lucu/Resource.hs @@ -73,6 +73,7 @@ module Network.HTTP.Lucu.Resource , getConfig , getRemoteAddr , getRemoteAddr' + , getRemoteHost , getRemoteCertificate , getRequest , getMethod @@ -136,7 +137,6 @@ module Network.HTTP.Lucu.Resource import Control.Concurrent.STM import Control.Monad.Reader -import Data.Bits import qualified Data.ByteString as Strict (ByteString) import qualified Data.ByteString.Lazy as Lazy (ByteString) import qualified Data.ByteString.Char8 as C8 hiding (ByteString) @@ -211,20 +211,15 @@ getRemoteAddr = do itr <- getInteraction -- you want a 'Network.Socket.SockAddr' instead of 'Prelude.String', -- use 'getRemoteAddr'. getRemoteAddr' :: Resource String -getRemoteAddr' = do addr <- getRemoteAddr - case addr of - -- Network.Socket は IPv6 を考慮してゐないやうだ… - SockAddrInet _ v4addr - -> let b1 = (v4addr `shiftR` 24) .&. 0xFF - b2 = (v4addr `shiftR` 16) .&. 0xFF - b3 = (v4addr `shiftR` 8) .&. 0xFF - b4 = v4addr .&. 0xFF - in - return $ concat $ intersperse "." $ map show [b4, b3, b2, b1] - SockAddrUnix path - -> return path - _ - -> undefined +getRemoteAddr' = do addr <- getRemoteAddr + (Just str, _) <- liftIO $! getNameInfo [NI_NUMERICHOST] True False addr + return str + +-- |Resolve an address to the remote host. +getRemoteHost :: Resource String +getRemoteHost = do addr <- getRemoteAddr + (Just str, _) <- liftIO $! getNameInfo [] True False addr + return str -- | Return the X.509 certificate of the client, or 'Nothing' if: --