resolve-host: allow specifying type as TYPEnn
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 2 Feb 2015 04:12:27 +0000 (23:12 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 29 Jan 2016 17:13:08 +0000 (12:13 -0500)
This mirrors the behaviour of host and makes the conversion to and from
string symmetrical.

src/resolve/dns-type.c
src/resolve/dns-type.h

index 46ab694..fc2f182 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/socket.h>
 
 #include "dns-type.h"
+#include "parse-util.h"
 #include "string-util.h"
 
 typedef const struct {
@@ -41,10 +42,19 @@ int dns_type_from_string(const char *s) {
         assert(s);
 
         sc = lookup_dns_type(s, strlen(s));
-        if (!sc)
-                return _DNS_TYPE_INVALID;
+        if (sc)
+                return sc->id;
 
-        return sc->id;
+        s = startswith_no_case(s, "TYPE");
+        if (s) {
+                unsigned x;
+
+                if (safe_atou(s, &x) >= 0 &&
+                    x <= UINT16_MAX)
+                        return (int) x;
+        }
+
+        return _DNS_TYPE_INVALID;
 }
 
 bool dns_type_is_pseudo(uint16_t type) {
index 1d9a59d..d025544 100644 (file)
@@ -139,6 +139,7 @@ int dns_type_to_af(uint16_t t);
 bool dns_class_is_pseudo(uint16_t class);
 bool dns_class_is_valid_rr(uint16_t class);
 
+/* TYPE?? follows http://tools.ietf.org/html/rfc3597#section-5 */
 const char *dns_type_to_string(int type);
 int dns_type_from_string(const char *s);