chiark / gitweb /
resolve-host: make arg_type an int
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Aug 2014 18:02:04 +0000 (14:02 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 4 Aug 2014 02:02:32 +0000 (22:02 -0400)
We are using it also to store _DNS_TYPE_INVALID, so it should be signed.

Makefile.am
src/resolve-host/resolve-host.c
src/resolve/dns-type.c
src/resolve/dns-type.h

index 45d2e58bf5569566a8451613e73295e1e8a23da1..ce8f2472ee5e20e7422162f57159b07fb095a5e3 100644 (file)
@@ -1189,7 +1189,7 @@ src/resolve/dns_type-list.txt: src/resolve/dns-type.h
        $(AM_V_GEN)$(SED) -n -r 's/.* DNS_TYPE_(\w+).*/\1/p' <$< >$@
 
 src/resolve/dns_type-to-name.h: src/resolve/dns_type-list.txt
        $(AM_V_GEN)$(SED) -n -r 's/.* DNS_TYPE_(\w+).*/\1/p' <$< >$@
 
 src/resolve/dns_type-to-name.h: src/resolve/dns_type-list.txt
-       $(AM_V_GEN)$(AWK) 'BEGIN{ print "const char *dns_type_to_string(uint16_t type) {\n\tswitch(type) {" } {printf "        case DNS_TYPE_%s: return ", $$1; sub(/_/, "-"); printf "\"%s\";\n", $$1 } END{ print "\ndefault: return NULL;\n\t}\n}\n" }' <$< >$@
+       $(AM_V_GEN)$(AWK) 'BEGIN{ print "const char *dns_type_to_string(int type) {\n\tswitch(type) {" } {printf "        case DNS_TYPE_%s: return ", $$1; sub(/_/, "-"); printf "\"%s\";\n", $$1 } END{ print "\ndefault: return NULL;\n\t}\n}\n" }' <$< >$@
 
 src/resolve/dns_type-from-name.gperf: src/resolve/dns_type-list.txt
        $(AM_V_GEN)$(AWK) 'BEGIN{ print "struct dns_type_name { const char* name; int id; };"; print "%null-strings"; print "%%";} { s=$$1; sub(/_/, "-", s); printf "%s, ", $$s; printf "DNS_TYPE_%s\n", $$1 }' <$< >$@
 
 src/resolve/dns_type-from-name.gperf: src/resolve/dns_type-list.txt
        $(AM_V_GEN)$(AWK) 'BEGIN{ print "struct dns_type_name { const char* name; int id; };"; print "%null-strings"; print "%%";} { s=$$1; sub(/_/, "-", s); printf "%s, ", $$s; printf "DNS_TYPE_%s\n", $$1 }' <$< >$@
index 987b43a0cb9707e0c14c73f301df9f3519408116..4b46cdfa16cd7ff312be7863a8d456d7d66688fd 100644 (file)
@@ -37,7 +37,7 @@
 
 static int arg_family = AF_UNSPEC;
 static int arg_ifindex = 0;
 
 static int arg_family = AF_UNSPEC;
 static int arg_ifindex = 0;
-static uint16_t arg_type = 0;
+static int arg_type = 0;
 static uint16_t arg_class = 0;
 static bool arg_legend = true;
 
 static uint16_t arg_class = 0;
 static bool arg_legend = true;
 
@@ -316,6 +316,7 @@ static int resolve_record(sd_bus *bus, const char *name) {
         if (r < 0)
                 return bus_log_create_error(r);
 
         if (r < 0)
                 return bus_log_create_error(r);
 
+        assert((uint16_t) arg_type == arg_type);
         r = sd_bus_message_append(req, "sqq", name, arg_class, arg_type);
         if (r < 0)
                 return bus_log_create_error(r);
         r = sd_bus_message_append(req, "sqq", name, arg_class, arg_type);
         if (r < 0)
                 return bus_log_create_error(r);
@@ -482,11 +483,12 @@ static int parse_argv(int argc, char *argv[]) {
                                 return 0;
                         }
 
                                 return 0;
                         }
 
-                        r = dns_type_from_string(optarg, &arg_type);
-                        if (r < 0) {
+                        arg_type = dns_type_from_string(optarg);
+                        if (arg_type < 0) {
                                 log_error("Failed to parse RR record type %s", optarg);
                                 return r;
                         }
                                 log_error("Failed to parse RR record type %s", optarg);
                                 return r;
                         }
+                        assert(arg_type > 0 && (uint16_t) arg_type == arg_type);
 
                         break;
 
 
                         break;
 
index 271a7e176bf9120faaafd6929dba67d24fdf8f43..a3e740896f762a3969930701ed88012c9c85ba05 100644 (file)
@@ -32,16 +32,14 @@ lookup_dns_type (register const char *str, register unsigned int len);
 #include "dns_type-from-name.h"
 #include "dns_type-to-name.h"
 
 #include "dns_type-from-name.h"
 #include "dns_type-to-name.h"
 
-int dns_type_from_string(const char *s, uint16_t *type) {
+int dns_type_from_string(const char *s) {
         const struct dns_type_name *sc;
 
         assert(s);
         const struct dns_type_name *sc;
 
         assert(s);
-        assert(type);
 
         sc = lookup_dns_type(s, strlen(s));
         if (!sc)
 
         sc = lookup_dns_type(s, strlen(s));
         if (!sc)
-                return -EINVAL;
+                return _DNS_TYPE_INVALID;
 
 
-        *type = sc->id;
-        return 0;
+        return sc->id;
 }
 }
index 66063153a0ce929605cc280b01197c6bf0291278..86951d233a3dac8fd0e7f4c87bb2736b1e30bfc8 100644 (file)
 
 #pragma once
 
 
 #pragma once
 
-#include <inttypes.h>
-
 #include "macro.h"
 
 #include "macro.h"
 
-const char *dns_type_to_string(uint16_t type);
-int dns_type_from_string(const char *s, uint16_t *type);
+const char *dns_type_to_string(int type);
+int dns_type_from_string(const char *s);
 
 /* DNS record types, taken from
  * http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.
 
 /* DNS record types, taken from
  * http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.