on master help sign in
Merge pull request #568 from LeifW/broaden_localhost_checking
6bcb9c7Edwin Brady
idris.cabal+1
@@ -357,6 +357,7 @@ Executable idris
357 , Util.Pretty
357 , Util.Pretty
358 , Util.System
358 , Util.System
359 , Util.DynamicLinker
359 , Util.DynamicLinker
360+ , Util.Net
360
361
361 , Pkg.Package
362 , Pkg.Package
362 , Pkg.PParser
363 , Pkg.PParser
src/Idris/REPL.hs+5−2
@@ -27,6 +27,7 @@ import Idris.CaseSplit
27import Paths_idris
27import Paths_idris
28import Util.System
28import Util.System
29import Util.DynamicLinker
29import Util.DynamicLinker
30+import Util.Net (listenOnLocalhost)
30
31
31import Core.Evaluate
32import Core.Evaluate
32import Core.Execute (execute)
33import Core.Execute (execute)
@@ -111,7 +112,7 @@ startServer orig stvar fn_in = do tid <- runIO $ forkOS serverLoop
111 where serverLoop :: IO ()
112 where serverLoop :: IO ()
112 -- TODO: option for port number
113 -- TODO: option for port number
113 serverLoop = withSocketsDo $
114 serverLoop = withSocketsDo $
114− do sock <- listenOn $ PortNumber 4294
115+ do sock <- listenOnLocalhost $ PortNumber 4294
115 i <- readMVar stvar
116 i <- readMVar stvar
116 loop fn i sock
117 loop fn i sock
117
118
@@ -121,7 +122,9 @@ startServer orig stvar fn_in = do tid <- runIO $ forkOS serverLoop
121
122
122 loop fn ist sock
123 loop fn ist sock
123 = do (h,host,_) <- accept sock
124 = do (h,host,_) <- accept sock
125+ -- just use the local part of the hostname
126+ -- for the "localhost.localdomain" case
124− if (host == "localhost" ||
127+ if ((takeWhile (/= '.') host) == "localhost" ||
125 host == "127.0.0.1")
128 host == "127.0.0.1")
126 then do
129 then do
127 cmd <- hGetLine h
130 cmd <- hGetLine h
src/Util/Net.hsnew file+22
@@ -0,0 +1,22 @@
1+module Util.Net (listenOnLocalhost) where
2+
3+import Network
4+import Network.Socket hiding (sClose, PortNumber)
5+import Network.BSD (getProtocolNumber)
6+import Control.Exception (bracketOnError)
7+
8+-- Copied from upstream impl of listenOn
9+-- bound to localhost interface instead of iNADDR_ANY
10+listenOnLocalhost (PortNumber port) = do
11+ proto <- getProtocolNumber "tcp"
12+ localhost <- inet_addr "127.0.0.1"
13+ bracketOnError
14+ (socket AF_INET Stream proto)
15+ (sClose)
16+ (\sock -> do
17+ setSocketOption sock ReuseAddr 1
18+ bindSocket sock (SockAddrInet port localhost)
19+ listen sock maxListenQueue
20+ return sock
21+ )
22+