summaryrefslogtreecommitdiff
path: root/network-addr/src/Network/Address.hs
diff options
context:
space:
mode:
Diffstat (limited to 'network-addr/src/Network/Address.hs')
-rw-r--r--network-addr/src/Network/Address.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/network-addr/src/Network/Address.hs b/network-addr/src/Network/Address.hs
index 9cfbbb40..57bb11d1 100644
--- a/network-addr/src/Network/Address.hs
+++ b/network-addr/src/Network/Address.hs
@@ -41,6 +41,8 @@ module Network.Address
41 , ipFamily 41 , ipFamily
42 , is4mapped 42 , is4mapped
43 , either4or6 43 , either4or6
44 , make6mapped4
45 , canonize
44 46
45 -- * PeerId 47 -- * PeerId
46 -- $peer-id 48 -- $peer-id
@@ -132,6 +134,7 @@ import Text.PrettyPrint.HughesPJClass hiding ((<>),($$))
132#if !MIN_VERSION_time(1,5,0) 134#if !MIN_VERSION_time(1,5,0)
133import System.Locale (defaultTimeLocale) 135import System.Locale (defaultTimeLocale)
134#endif 136#endif
137import System.Endian (fromBE32)
135import System.Entropy 138import System.Entropy
136import DPut 139import DPut
137import DebugTag 140import DebugTag
@@ -1242,6 +1245,16 @@ either4or6 a6@(SockAddrInet6 port _ addr _)
1242 | Just ip4 <- (fromSockAddr a6 >>= un4map) = Left (setPort port $ toSockAddr ip4) 1245 | Just ip4 <- (fromSockAddr a6 >>= un4map) = Left (setPort port $ toSockAddr ip4)
1243 | otherwise = Right a6 1246 | otherwise = Right a6
1244 1247
1248make6mapped4 :: SockAddr -> SockAddr
1249make6mapped4 addr@(SockAddrInet6 {}) = addr
1250make6mapped4 addr@(SockAddrInet port a) = SockAddrInet6 port 0 (0,0,0xFFFF,fromBE32 a) 0
1251
1252canonize :: SockAddr -> SockAddr
1253canonize a6@(SockAddrInet6 port _ addr _)
1254 | Just ip4 <- (fromSockAddr a6 >>= un4map) = setPort port $ toSockAddr ip4
1255canonize a = a
1256
1257
1245data WantIP = Want_IP4 | Want_IP6 | Want_Both 1258data WantIP = Want_IP4 | Want_IP6 | Want_Both
1246 deriving (Eq, Enum, Ord, Show) 1259 deriving (Eq, Enum, Ord, Show)
1247 1260