module Network.Socket.IsString () where import Data.String import Network.Socket import System.IO.Unsafe instance IsString HostAddress where fromString str = let hint = defaultHints { addrFlags = [AI_NUMERICHOST] , addrFamily = AF_INET } ret = unsafePerformIO $ getAddrInfo (Just hint) (Just str) Nothing in case ret of [] -> error (str ++ " seems not to be a valid IPv4 address") (x:xs) -> case addrAddress x of SockAddrInet _ addr -> addr _ -> error ("getAddrInfo (" ++ str ++ ") returned a strange result: " ++ show (x:xs)) instance IsString HostAddress6 where fromString str = let hint = defaultHints { addrFlags = [AI_NUMERICHOST] , addrFamily = AF_INET6 } ret = unsafePerformIO $ getAddrInfo (Just hint) (Just str) Nothing in case ret of [] -> error (str ++ " seems not to be a valid IPv6 address") (x:xs) -> case addrAddress x of SockAddrInet6 _ _ addr _ -> addr _ -> error ("getAddrInfo (" ++ str ++ ") returned a strange result: " ++ show (x:xs))