summaryrefslogtreecommitdiff
path: root/Presence/LocalPeerCred.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-25 18:09:08 -0400
committerjoe <joe@jerkface.net>2013-06-25 18:09:08 -0400
commite74b4448748af7e068a9d162b62fccc0ede0e81a (patch)
treede08edd1b13cb922f908684c0d8e28020f18e430 /Presence/LocalPeerCred.hs
parent4ae6bf78a836cf35450387431aea93d522ce8f84 (diff)
SEnd addresses on the wire between peers rather than domain names.
Diffstat (limited to 'Presence/LocalPeerCred.hs')
-rw-r--r--Presence/LocalPeerCred.hs31
1 files changed, 20 insertions, 11 deletions
diff --git a/Presence/LocalPeerCred.hs b/Presence/LocalPeerCred.hs
index b544af97..ee1a4a0f 100644
--- a/Presence/LocalPeerCred.hs
+++ b/Presence/LocalPeerCred.hs
@@ -1,5 +1,11 @@
1module LocalPeerCred where 1module LocalPeerCred where
2 2
3{- for main
4import System.Environment
5import Control.Monad
6-}
7
8import System.Endian
3import Data.ByteString.Lazy.Char8 as L hiding (map,putStrLn,tail,splitAt,tails,filter) 9import Data.ByteString.Lazy.Char8 as L hiding (map,putStrLn,tail,splitAt,tails,filter)
4import qualified Data.ByteString.Lazy.Char8 as L (splitAt) 10import qualified Data.ByteString.Lazy.Char8 as L (splitAt)
5import qualified Data.ByteString.Lazy as W8 11import qualified Data.ByteString.Lazy as W8
@@ -38,7 +44,9 @@ getLocalPeerCred' (SockAddrInet portn host) = do
38 44
39getLocalPeerCred' (SockAddrInet6 portn flow host scope) = do 45getLocalPeerCred' (SockAddrInet6 portn flow host scope) = do
40 let port = fromEnum portn 46 let port = fromEnum portn
41 trace "tcp6" $ withFile "/proc/net/tcp6" ReadMode (parseProcNet port host) 47 (a,b,c,d) = host
48 host' = (toBE32 a, toBE32 b, toBE32 c, toBE32 d)
49 withFile "/proc/net/tcp6" ReadMode (parseProcNet port host')
42 50
43getLocalPeerCred' addr@(SockAddrUnix _) = 51getLocalPeerCred' addr@(SockAddrUnix _) =
44 -- TODO: parse /proc/net/unix 52 -- TODO: parse /proc/net/unix
@@ -81,20 +89,21 @@ parseProcNet port host h = do
81 fmap snd . listToMaybe $ filter ((==(port,host)).fst) rs 89 fmap snd . listToMaybe $ filter ((==(port,host)).fst) rs
82 {- trace ("found: "++show u) -} 90 {- trace ("found: "++show u) -}
83 u `seq` return u 91 u `seq` return u
84{- 92 {-
85 where 93 where
86 a === b = let r= a==b in trace ("Comparing "++show (a,b)++"-->"++show r) r 94 a === b = let r= a==b in trace ("Comparing "++show (a,b)++"-->"++show r) r
87-} 95 -}
88 96
89{- 97{-
90main = do 98main = do
91 args <- getArgs 99 args <- getArgs
92 let addr = fromJust $ do 100 let addr_str = fromJust (args??0)
93 port <- args ?? 0 101 port_str = fromJust (args??1)
94 host <- args ?? 1 102 info <- getAddrInfo (Just $ defaultHints { addrFlags = [ AI_NUMERICHOST ] })
95 return $ SockAddrInet (toEnum . fromIntegral . readInt $ port) (toEnum (read host::Int)) 103 (Just addr_str)
96 readInt x = read x :: Int 104 (Just port_str)
97 105 let addrs = map addrAddress info
98 r <- getLocalPeerCred' addr 106 forM_ addrs $ \addr -> do
99 putStrLn $ "r = " ++ show r 107 r <- getLocalPeerCred' addr
108 putStrLn $ "r{"++show addr++"} = " ++ show r
100-} 109-}