diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-08 08:15:21 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-10-03 07:00:40 -0400 |
commit | 9c02c2816c826d8f40cfaa4409175c88cfc1ea12 (patch) | |
tree | 69d2a079d19b7affa9e2b5f41552ed2b35c68d7d /whosocket.hs | |
parent | fbf9890a6bcd4e6212b5947f908bc34f233b279d (diff) |
Move example utilities into examples directory.
Diffstat (limited to 'whosocket.hs')
-rw-r--r-- | whosocket.hs | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/whosocket.hs b/whosocket.hs deleted file mode 100644 index f84e3178..00000000 --- a/whosocket.hs +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | {-# LANGUAGE TupleSections #-} | ||
3 | module Main where | ||
4 | |||
5 | import LocalPeerCred | ||
6 | import ControlMaybe | ||
7 | import UTmp | ||
8 | import ByteStringOperators | ||
9 | |||
10 | import System.Directory | ||
11 | import Data.Char | ||
12 | import System.Posix.Types | ||
13 | import System.Posix.Files | ||
14 | import qualified Data.ByteString.Lazy.Char8 as L | ||
15 | ( unpack | ||
16 | , pack | ||
17 | , take | ||
18 | , putStrLn | ||
19 | ) | ||
20 | import Data.List (groupBy) | ||
21 | import Data.Maybe (listToMaybe,mapMaybe,catMaybes) | ||
22 | |||
23 | import Network.Socket | ||
24 | import System.Environment | ||
25 | import Control.Arrow (first) | ||
26 | import System.Endian | ||
27 | |||
28 | usage = do | ||
29 | putStrLn $ "whosocket numeric-address port" | ||
30 | |||
31 | main = do | ||
32 | args <- getArgs | ||
33 | case (args??0,args??1) of | ||
34 | (Just addr_str,Just port_str) -> whosocket addr_str port_str | ||
35 | _ -> usage | ||
36 | |||
37 | whosocket :: HostName -> ServiceName -> IO () | ||
38 | whosocket addr_str port_str = do | ||
39 | info <- getAddrInfo (Just $ defaultHints { addrFlags = [ AI_NUMERICHOST ] }) | ||
40 | (Just addr_str) | ||
41 | (Just port_str) | ||
42 | let addr = head $ map addrAddress info | ||
43 | r <- getLocalPeerCred' addr | ||
44 | putStrLn $ "r{"++show addr++"} = " ++ show r | ||
45 | |||
46 | us <- UTmp.users | ||
47 | let filterTTYs (_,tty,pid) = | ||
48 | if L.take 3 tty == "tty" | ||
49 | then Just (tty,pid) | ||
50 | else Nothing | ||
51 | tty_pids = mapMaybe filterTTYs us | ||
52 | |||
53 | tty <- maybe (return Nothing) | ||
54 | (fmap fst . uncurry (identifyTTY tty_pids)) | ||
55 | r | ||
56 | putStrLn $ "uid = " ++ show (fmap fst r) | ||
57 | L.putStrLn $ "tty = " <++?> tty | ||
58 | |||
59 | return () | ||
60 | |||