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:
parent
1ad4d58e43
commit
b9cf0c9796
2 changed files with 71 additions and 0 deletions
|
@ -184,6 +184,9 @@ struct ircd::rfc1035::record::A
|
|||
|
||||
A(const answer &);
|
||||
A();
|
||||
|
||||
friend bool operator==(const A &, const A &);
|
||||
friend bool operator!=(const A &, const A &);
|
||||
};
|
||||
|
||||
/// IPv6 address record.
|
||||
|
@ -195,6 +198,9 @@ struct ircd::rfc1035::record::AAAA
|
|||
|
||||
AAAA(const answer &);
|
||||
AAAA();
|
||||
|
||||
friend bool operator==(const AAAA &, const AAAA &);
|
||||
friend bool operator!=(const AAAA &, const AAAA &);
|
||||
};
|
||||
|
||||
/// Canonical name aliasing record
|
||||
|
@ -206,6 +212,9 @@ struct ircd::rfc1035::record::CNAME
|
|||
|
||||
CNAME(const answer &);
|
||||
CNAME();
|
||||
|
||||
friend bool operator==(const CNAME &, const CNAME &);
|
||||
friend bool operator!=(const CNAME &, const CNAME &);
|
||||
};
|
||||
|
||||
/// Service record.
|
||||
|
@ -221,4 +230,7 @@ struct ircd::rfc1035::record::SRV
|
|||
|
||||
SRV(const answer &);
|
||||
SRV();
|
||||
|
||||
friend bool operator==(const SRV &, const SRV &);
|
||||
friend bool operator!=(const SRV &, const SRV &);
|
||||
};
|
||||
|
|
|
@ -218,6 +218,18 @@ ircd::rfc1035::record::A::A(const answer &answer)
|
|||
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
|
||||
//
|
||||
|
@ -240,6 +252,22 @@ ircd::rfc1035::record::AAAA::AAAA(const answer &answer)
|
|||
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()
|
||||
:record{5}
|
||||
{
|
||||
|
@ -258,6 +286,22 @@ ircd::rfc1035::record::CNAME::CNAME(const answer &answer)
|
|||
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()
|
||||
:record{33}
|
||||
{
|
||||
|
@ -285,6 +329,21 @@ ircd::rfc1035::record::SRV::SRV(const answer &answer)
|
|||
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
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue