summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core/PeerAddr.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Core/PeerAddr.hs')
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs
index 63ae04b9..b9d4878e 100644
--- a/src/Network/BitTorrent/Core/PeerAddr.hs
+++ b/src/Network/BitTorrent/Core/PeerAddr.hs
@@ -133,6 +133,20 @@ instance BEncode IPv6 where
133 fromBEncode = ipFromBEncode 133 fromBEncode = ipFromBEncode
134 {-# INLINE fromBEncode #-} 134 {-# INLINE fromBEncode #-}
135 135
136instance Serialize IP where
137 put (IPv4 ip) = put ip
138 put (IPv6 ip) = put ip
139
140 -- | When 'get'ing an IP it must be 'isolate'd to the appropriate number of
141 -- bytes since we have no other way of telling which address type we are
142 -- trying to parse
143 get = do
144 n <- remaining
145 case n of
146 4 -> IPv4 <$> get
147 16 -> IPv6 <$> get
148 _ -> fail "Wrong number of bytes remaining to parse IP"
149
136instance Serialize IPv4 where 150instance Serialize IPv4 where
137 put = putWord32host . toHostAddress 151 put = putWord32host . toHostAddress
138 get = fromHostAddress <$> getWord32host 152 get = fromHostAddress <$> getWord32host