diff options
-rw-r--r-- | contrib/librdns/rdns.h | 7 | ||||
-rw-r--r-- | contrib/librdns/util.c | 42 |
2 files changed, 49 insertions, 0 deletions
diff --git a/contrib/librdns/rdns.h b/contrib/librdns/rdns.h index 82506d36a..ff8eadcc6 100644 --- a/contrib/librdns/rdns.h +++ b/contrib/librdns/rdns.h @@ -353,6 +353,13 @@ const char *rdns_strerror (enum dns_rcode rcode); const char *rdns_strtype (enum rdns_request_type type); /** + * Parse string and return request type + * @param str + * @return + */ +enum rdns_request_type rdns_type_fromstr (const char *str); + +/** * Increase refcount for a request * @param req * @return diff --git a/contrib/librdns/util.c b/contrib/librdns/util.c index 974c97554..1eb5410c3 100644 --- a/contrib/librdns/util.c +++ b/contrib/librdns/util.c @@ -247,6 +247,48 @@ rdns_strtype (enum rdns_request_type type) return dns_types[type]; } +enum rdns_request_type +rdns_type_fromstr (const char *str) +{ + if (str) { + if (strcmp (str, "a") == 0) { + return RDNS_REQUEST_A; + } + else if (strcmp (str, "ns") == 0) { + return RDNS_REQUEST_NS; + } + else if (strcmp (str, "soa") == 0) { + return RDNS_REQUEST_SOA; + } + else if (strcmp (str, "ptr") == 0) { + return RDNS_REQUEST_PTR; + } + else if (strcmp (str, "mx") == 0) { + return RDNS_REQUEST_MX; + } + else if (strcmp (str, "srv") == 0) { + return RDNS_REQUEST_SRV; + } + else if (strcmp (str, "txt") == 0) { + return RDNS_REQUEST_TXT; + } + else if (strcmp (str, "spf") == 0) { + return RDNS_REQUEST_SPF; + } + else if (strcmp (str, "aaaa") == 0) { + return RDNS_REQUEST_AAAA; + } + else if (strcmp (str, "tlsa") == 0) { + return RDNS_REQUEST_TLSA; + } + else if (strcmp (str, "any") == 0) { + return RDNS_REQUEST_ANY; + } + } + + return -1; +} + uint16_t rdns_permutor_generate_id (void) { |