1 module Network.Socket.IsString () where
5 import System.IO.Unsafe
7 instance IsString HostAddress where
9 = let hint = defaultHints {
10 addrFlags = [AI_NUMERICHOST]
11 , addrFamily = AF_INET
13 ret = unsafePerformIO $
14 getAddrInfo (Just hint) (Just str) Nothing
17 [] -> error (str ++ " seems not to be a valid IPv4 address")
18 (x:xs) -> case addrAddress x of
21 _ -> error ("getAddrInfo (" ++ str ++ ") returned a strange result: " ++ show (x:xs))
23 instance IsString HostAddress6 where
25 = let hint = defaultHints {
26 addrFlags = [AI_NUMERICHOST]
27 , addrFamily = AF_INET6
29 ret = unsafePerformIO $
30 getAddrInfo (Just hint) (Just str) Nothing
33 [] -> error (str ++ " seems not to be a valid IPv6 address")
34 (x:xs) -> case addrAddress x of
35 SockAddrInet6 _ _ addr _
37 _ -> error ("getAddrInfo (" ++ str ++ ") returned a strange result: " ++ show (x:xs))