on master help sign in
Only bind to the localhost interface from REPL network socket.

Copied 'n pasted impl of http://hackage.haskell.org/package/network-2.2.1.7/docs/Network.html#v:listenOn modified to listen on localhost instead of iNADDR_ANY

commit054810992d2a38a00d815abfc0040db13e2c1077 authorLeif Warner <leif@janrain.com> dateTue 29 Oct 2013, 19:55 (13 years ago) parentfa52522
3 files changed+25−1
idris.cabal+1 src/Idris/REPL.hs+2−1 src/Util/Net.hs+22
idris.cabal+1
@@ -357,6 +357,7 @@ Executable idris
357357 , Util.Pretty
358358 , Util.System
359359 , Util.DynamicLinker
360+ , Util.Net
360361
361362 , Pkg.Package
362363 , Pkg.PParser
src/Idris/REPL.hs+2−1
@@ -27,6 +27,7 @@ import Idris.CaseSplit
2727import Paths_idris
2828import Util.System
2929import Util.DynamicLinker
30+import Util.Net (listenOnLocalhost)
3031
3132import Core.Evaluate
3233import Core.Execute (execute)
@@ -111,7 +112,7 @@ startServer orig stvar fn_in = do tid <- runIO $ forkOS serverLoop
111112 where serverLoop :: IO ()
112113 -- TODO: option for port number
113114 serverLoop = withSocketsDo $
114− do sock <- listenOn $ PortNumber 4294
115+ do sock <- listenOnLocalhost $ PortNumber 4294
115116 i <- readMVar stvar
116117 loop fn i sock
117118
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+