diff options
author | James Crayne <jim.crayne@gmail.com> | 2013-07-05 03:17:48 -0400 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2013-07-05 03:17:48 -0400 |
commit | 498481cd24e877a82b685b7da8ee1632e7cb7243 (patch) | |
tree | 7a7bcb450a510b8363621e81ece96195ba4223c8 /Presence/LocalPeerCred.hs | |
parent | 7f1225c9521c2e4936c5ccf73f1cc34e8c459bb3 (diff) |
Fixed handling ipv4 encoded as ipv6
Diffstat (limited to 'Presence/LocalPeerCred.hs')
-rw-r--r-- | Presence/LocalPeerCred.hs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Presence/LocalPeerCred.hs b/Presence/LocalPeerCred.hs index b6ec9491..0122b5d0 100644 --- a/Presence/LocalPeerCred.hs +++ b/Presence/LocalPeerCred.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE ViewPatterns #-} | ||
1 | module LocalPeerCred where | 2 | module LocalPeerCred where |
2 | 3 | ||
3 | {- for main | 4 | {- for main |
@@ -37,18 +38,18 @@ parseHex bs = L.concat . parseHex' $ bs | |||
37 | then [] | 38 | then [] |
38 | else parseHex' ts | 39 | else parseHex' ts |
39 | 40 | ||
40 | getLocalPeerCred' (SockAddrInet portn host) = do | 41 | getLocalPeerCred' (unmap6mapped4 -> SockAddrInet portn host) = do |
41 | let port = fromEnum portn | 42 | let port = fromEnum portn |
42 | {- trace ("tcp4 "++show(port,host)) $ -} | 43 | {- trace ("tcp4 "++show(port,host)) $ -} |
43 | withFile "/proc/net/tcp" ReadMode (parseProcNet port host) | 44 | withFile "/proc/net/tcp" ReadMode (parseProcNet port host) |
44 | 45 | ||
45 | getLocalPeerCred' (SockAddrInet6 portn flow host scope) = do | 46 | getLocalPeerCred' (unmap6mapped4 -> SockAddrInet6 portn flow host scope) = do |
46 | let port = fromEnum portn | 47 | let port = fromEnum portn |
47 | (a,b,c,d) = host | 48 | (a,b,c,d) = host |
48 | host' = (toBE32 a, toBE32 b, toBE32 c, toBE32 d) | 49 | host' = (toBE32 a, toBE32 b, toBE32 c, toBE32 d) |
49 | withFile "/proc/net/tcp6" ReadMode (parseProcNet port host') | 50 | withFile "/proc/net/tcp6" ReadMode (parseProcNet port host') |
50 | 51 | ||
51 | getLocalPeerCred' addr@(SockAddrUnix _) = | 52 | getLocalPeerCred' (unmap6mapped4 -> addr@(SockAddrUnix _)) = |
52 | -- TODO: parse /proc/net/unix | 53 | -- TODO: parse /proc/net/unix |
53 | -- see also: Network.Socket.getPeerCred | 54 | -- see also: Network.Socket.getPeerCred |
54 | return Nothing | 55 | return Nothing |
@@ -109,3 +110,7 @@ main = do | |||
109 | r <- getLocalPeerCred' addr | 110 | r <- getLocalPeerCred' addr |
110 | putStrLn $ "r{"++show addr++"} = " ++ show r | 111 | putStrLn $ "r{"++show addr++"} = " ++ show r |
111 | -} | 112 | -} |
113 | |||
114 | -- PEER NAME: [::ffff:127.0.0.1]:34307 | ||
115 | unmap6mapped4 addr@(SockAddrInet6 port _ (0,0,0xFFFF,a) _) = SockAddrInet port (toBE32 a) | ||
116 | unmap6mapped4 addr = addr | ||