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