summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Utility/WebApp.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs
index 883f4d183..21a5761bc 100644
--- a/Utility/WebApp.hs
+++ b/Utility/WebApp.hs
@@ -63,14 +63,18 @@ runWebApp app observer = do
{- Binds to a local socket, selecting any free port.
-
+ - Prefers to bind to the ipv4 address rather than the ipv6 address
+ - of localhost, if it's available.
+ -
- As a (very weak) form of security, only connections from
- localhost are accepted. -}
localSocket :: IO Socket
localSocket = do
addrs <- getAddrInfo (Just hints) (Just localhost) Nothing
- case addrs of
- [] -> error "unable to bind to a local socket"
- (addr:_) -> go addr
+ case (partition (\a -> addrFamily a == AF_INET) addrs) of
+ (v4addr:_, _) -> go v4addr
+ (_, v6addr:_) -> go v6addr
+ _ -> error "unable to bind to a local socket"
where
hints = defaultHints
{ addrFlags = [AI_ADDRCONFIG]