summaryrefslogtreecommitdiff
path: root/src/Network/UPNP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/UPNP.hs')
-rw-r--r--src/Network/UPNP.hs40
1 files changed, 0 insertions, 40 deletions
diff --git a/src/Network/UPNP.hs b/src/Network/UPNP.hs
deleted file mode 100644
index 01d222bf..00000000
--- a/src/Network/UPNP.hs
+++ /dev/null
@@ -1,40 +0,0 @@
1module Network.UPNP where
2
3import Data.Maybe
4import Network.Address (sockAddrPort)
5import Network.Socket
6import System.Directory
7import System.Process as Process
8import DPut
9import DebugTag
10
11protocols :: SocketType -> [String]
12protocols Stream = ["tcp"]
13protocols Datagram = ["udp"]
14protocols _ = ["udp","tcp"]
15
16upnpc :: FilePath
17upnpc = "/usr/bin/upnpc"
18
19-- | Invokes the miniupnpc command line program to request ports from a UPNP
20-- wifi router. Returns the process handle on success.
21requestPorts :: String -- ^ Description stored on router.
22 -> [(SocketType, SockAddr)] -- ^ Protocol-port pairs to request.
23 -> IO (Maybe ProcessHandle)
24requestPorts description binds = do
25 let requests = do
26 (stype,saddr) <- binds
27 proto <- protocols stype
28 port <- maybeToList (sockAddrPort saddr)
29 [ show port, proto ]
30 bail = return Nothing
31 case requests of
32 [] -> bail
33 _ -> do
34 gotMiniUPNPC <- doesFileExist upnpc
35 if gotMiniUPNPC then do
36 phandle <- spawnProcess upnpc $ "-e": description : "-r" : requests
37 return $ Just phandle
38 else do
39 dput XMisc $ "Warning: unable to find miniupnpc client at "++upnpc++"."
40 bail