0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

ircd::rfc1035: Comparison operator suite for record types.

This commit is contained in:
Jason Volk 2018-04-14 17:14:31 -07:00
parent 1ad4d58e43
commit b9cf0c9796
2 changed files with 71 additions and 0 deletions

View file

@ -184,6 +184,9 @@ struct ircd::rfc1035::record::A
A(const answer &); A(const answer &);
A(); A();
friend bool operator==(const A &, const A &);
friend bool operator!=(const A &, const A &);
}; };
/// IPv6 address record. /// IPv6 address record.
@ -195,6 +198,9 @@ struct ircd::rfc1035::record::AAAA
AAAA(const answer &); AAAA(const answer &);
AAAA(); AAAA();
friend bool operator==(const AAAA &, const AAAA &);
friend bool operator!=(const AAAA &, const AAAA &);
}; };
/// Canonical name aliasing record /// Canonical name aliasing record
@ -206,6 +212,9 @@ struct ircd::rfc1035::record::CNAME
CNAME(const answer &); CNAME(const answer &);
CNAME(); CNAME();
friend bool operator==(const CNAME &, const CNAME &);
friend bool operator!=(const CNAME &, const CNAME &);
}; };
/// Service record. /// Service record.
@ -221,4 +230,7 @@ struct ircd::rfc1035::record::SRV
SRV(const answer &); SRV(const answer &);
SRV(); SRV();
friend bool operator==(const SRV &, const SRV &);
friend bool operator!=(const SRV &, const SRV &);
}; };

View file

@ -218,6 +218,18 @@ ircd::rfc1035::record::A::A(const answer &answer)
ip4 = bswap(*(const uint32_t *)data(rdata)); ip4 = bswap(*(const uint32_t *)data(rdata));
} }
bool
ircd::rfc1035::operator!=(const record::A &a, const record::A &b)
{
return !(a == b);
}
bool
ircd::rfc1035::operator==(const record::A &a, const record::A &b)
{
return a.ip4 == b.ip4;
}
// //
// AAAA // AAAA
// //
@ -240,6 +252,22 @@ ircd::rfc1035::record::AAAA::AAAA(const answer &answer)
ip6 = bswap(*(const uint128_t *)data(rdata)); ip6 = bswap(*(const uint128_t *)data(rdata));
} }
bool
ircd::rfc1035::operator!=(const record::AAAA &a, const record::AAAA &b)
{
return !(a == b);
}
bool
ircd::rfc1035::operator==(const record::AAAA &a, const record::AAAA &b)
{
return a.ip6 == b.ip6;
}
//
// CNAME
//
ircd::rfc1035::record::CNAME::CNAME() ircd::rfc1035::record::CNAME::CNAME()
:record{5} :record{5}
{ {
@ -258,6 +286,22 @@ ircd::rfc1035::record::CNAME::CNAME(const answer &answer)
name = string_view{namebuf, len - 1}; name = string_view{namebuf, len - 1};
} }
bool
ircd::rfc1035::operator!=(const record::CNAME &a, const record::CNAME &b)
{
return !(a == b);
}
bool
ircd::rfc1035::operator==(const record::CNAME &a, const record::CNAME &b)
{
return a.name == b.name;
}
//
// SRV
//
ircd::rfc1035::record::SRV::SRV() ircd::rfc1035::record::SRV::SRV()
:record{33} :record{33}
{ {
@ -285,6 +329,21 @@ ircd::rfc1035::record::SRV::SRV(const answer &answer)
assert(std::distance(pos, end(rdata)) == 0); assert(std::distance(pos, end(rdata)) == 0);
} }
bool
ircd::rfc1035::operator!=(const record::SRV &a, const record::SRV &b)
{
return !(a == b);
}
bool
ircd::rfc1035::operator==(const record::SRV &a, const record::SRV &b)
{
return a.tgt == b.tgt &&
a.port == b.port &&
a.weight == b.weight &&
a.priority == b.priority;
}
// //
// Util / misc // Util / misc
// //