summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs14
m---------sub/hspec0
2 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
135instance 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
135instance Serialize IPv4 where 149instance Serialize IPv4 where
136 put = putWord32host . toHostAddress 150 put = putWord32host . toHostAddress
137 get = fromHostAddress <$> getWord32host 151 get = fromHostAddress <$> getWord32host
diff --git a/sub/hspec b/sub/hspec
new file mode 160000
Subproject 6b5bf6fe8bc59909c5b7346f6f70fdfe643d115