Skip to content

Commit 883cea7

Browse files
committed
Restore compatibility with old CSubNet serialization
1 parent 0b2abaa commit 883cea7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/netaddress.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,21 @@ class CSubNet
468468
friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
469469
friend bool operator<(const CSubNet& a, const CSubNet& b);
470470

471-
SERIALIZE_METHODS(CSubNet, obj) { READWRITE(obj.network, obj.netmask, obj.valid); }
471+
SERIALIZE_METHODS(CSubNet, obj)
472+
{
473+
READWRITE(obj.network);
474+
if (obj.network.IsIPv4()) {
475+
// Before commit 102867c587f5f7954232fb8ed8e85cda78bb4d32, CSubNet used the last 4 bytes of netmask
476+
// to store the relevant bytes for an IPv4 mask. For compatiblity reasons, keep doing so in
477+
// serialized form.
478+
unsigned char dummy[12] = {0};
479+
READWRITE(dummy);
480+
READWRITE(MakeSpan(obj.netmask).first(4));
481+
} else {
482+
READWRITE(obj.netmask);
483+
}
484+
READWRITE(obj.valid);
485+
}
472486
};
473487

474488
/** A combination of a network address (CNetAddr) and a (TCP) port */

0 commit comments

Comments
 (0)