diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-12-18 18:53:11 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-12-18 18:53:11 +0100 |
commit | 4b548ef382007e40bd8fb3affdce9f843d0d63ac (patch) | |
tree | 99c7a85840e1b83f1aec40b6194ef7a4981182ed /src/resolve/dns-type.c | |
parent | 3e92a71901960ad9af15ced891d529b2d8ef3c90 (diff) |
resolved: move DNS class utilities to dns-type.c and add more helpers
Let's make DNS class helpers more like DNS type helpers, let's move them
from resolved-dns-rr.[ch] into dns-type.[ch].
This also adds two new calls dns_class_is_pseudo() and
dns_class_is_valid_rr() which operate similar to dns_type_is_pseudo()
and dns_type_is_valid_rr() but for classes instead of types.
This should hopefully make handling of DNS classes and DNS types more
alike.
Diffstat (limited to 'src/resolve/dns-type.c')
-rw-r--r-- | src/resolve/dns-type.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/resolve/dns-type.c b/src/resolve/dns-type.c index 8281da3b7c..cc52ef9abe 100644 --- a/src/resolve/dns-type.c +++ b/src/resolve/dns-type.c @@ -20,6 +20,7 @@ ***/ #include "dns-type.h" +#include "string-util.h" typedef const struct { uint16_t type; @@ -64,6 +65,10 @@ bool dns_type_is_pseudo(uint16_t type) { ); } +bool dns_class_is_pseudo(uint16_t class) { + return class == DNS_TYPE_ANY; +} + bool dns_type_is_valid_query(uint16_t type) { /* The types valid as questions in packets */ @@ -85,3 +90,34 @@ bool dns_type_is_valid_rr(uint16_t type) { DNS_TYPE_AXFR, DNS_TYPE_IXFR); } + +bool dns_class_is_valid_rr(uint16_t class) { + return class != DNS_CLASS_ANY; +} + +const char *dns_class_to_string(uint16_t class) { + + switch (class) { + + case DNS_CLASS_IN: + return "IN"; + + case DNS_CLASS_ANY: + return "ANY"; + } + + return NULL; +} + +int dns_class_from_string(const char *s) { + + if (!s) + return _DNS_CLASS_INVALID; + + if (strcaseeq(s, "IN")) + return DNS_CLASS_IN; + else if (strcaseeq(s, "ANY")) + return DNS_CLASS_ANY; + + return _DNS_CLASS_INVALID; +} |