chiark / gitweb /
resolve-host: list types and classes
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 1 Aug 2014 00:06:30 +0000 (20:06 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 31 Jul 2014 12:56:03 +0000 (08:56 -0400)
Also update systemctl to similar style.

src/resolve-host/resolve-host.c
src/resolve/resolved-dns-rr.h
src/systemctl/systemctl.c

index 1b1edaf..1063790 100644 (file)
@@ -39,6 +39,7 @@ static int arg_family = AF_UNSPEC;
 static int arg_ifindex = 0;
 static uint16_t arg_type = 0;
 static uint16_t arg_class = 0;
+static bool arg_legend = true;
 
 static int resolve_host(sd_bus *bus, const char *name) {
 
@@ -387,6 +388,32 @@ static int resolve_record(sd_bus *bus, const char *name) {
         return 0;
 }
 
+static void help_dns_types(void) {
+        int i;
+        const char *t;
+
+        if (arg_legend)
+                puts("Known dns types:");
+        for (i = 0; i < _DNS_TYPE_MAX; i++) {
+                t = dns_type_to_string(i);
+                if (t)
+                        puts(t);
+        }
+}
+
+static void help_dns_classes(void) {
+        int i;
+        const char *t;
+
+        if (arg_legend)
+                puts("Known dns classes:");
+        for (i = 0; i < _DNS_CLASS_MAX; i++) {
+                t = dns_class_to_string(i);
+                if (t)
+                        puts(t);
+        }
+}
+
 static void help(void) {
         printf("%s [OPTIONS...]\n\n"
                "Resolve IPv4 or IPv6 addresses.\n\n"
@@ -397,12 +424,14 @@ static void help(void) {
                "  -i INTERFACE          Filter by interface\n"
                "  -t --type=TYPE        Query RR with DNS type\n"
                "  -c --class=CLASS      Query RR with DNS class\n"
+               "  --no-legend           Do not print column headers\n"
                , program_invocation_short_name);
 }
 
 static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
+                ARG_NO_LEGEND,
         };
 
         static const struct option options[] = {
@@ -410,6 +439,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "version",     no_argument,       NULL, ARG_VERSION   },
                 { "type",        no_argument,       NULL, 't'           },
                 { "class",       no_argument,       NULL, 'c'           },
+                { "no-legend",   no_argument,       NULL, ARG_NO_LEGEND },
                 {}
         };
 
@@ -447,19 +477,35 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 't':
+                        if (streq(optarg, "help")) {
+                                help_dns_types();
+                                return 0;
+                        }
+
                         r = dns_type_from_string(optarg, &arg_type);
                         if (r < 0) {
                                 log_error("Failed to parse RR record type %s", optarg);
                                 return r;
                         }
+
                         break;
 
                 case 'c':
+                        if (streq(optarg, "help")) {
+                                help_dns_classes();
+                                return 0;
+                        }
+
                         r = dns_class_from_string(optarg, &arg_class);
                         if (r < 0) {
                                 log_error("Failed to parse RR record class %s", optarg);
                                 return r;
                         }
+
+                        break;
+
+                case ARG_NO_LEGEND:
+                        arg_legend = false;
                         break;
 
                 case '?':
index 5246300..7b73cdc 100644 (file)
@@ -35,6 +35,8 @@ typedef struct DnsResourceRecord DnsResourceRecord;
 enum {
         DNS_CLASS_IN   = 0x01,
         DNS_CLASS_ANY  = 0xFF,
+        _DNS_CLASS_MAX,
+        _DNS_CLASS_INVALID = -1
 };
 
 /* DNS record types, see RFC 1035 */
@@ -60,6 +62,8 @@ enum {
         DNS_TYPE_TSIG  = 0xFA,
         DNS_TYPE_IXFR  = 0xFB,
         DNS_TYPE_AXFR  = 0xFC,
+        _DNS_TYPE_MAX,
+        _DNS_TYPE_INVALID = -1
 };
 
 struct DnsResourceKey {
index 21e33d5..8ec0db2 100644 (file)
@@ -5627,18 +5627,17 @@ static int runlevel_help(void) {
         return 0;
 }
 
-static int help_types(void) {
+static void help_types(void) {
         int i;
         const char *t;
 
-        puts("Available unit types:");
+        if (!arg_no_legend)
+                puts("Available unit types:");
         for (i = 0; i < _UNIT_TYPE_MAX; i++) {
                 t = unit_type_to_string(i);
                 if (t)
                         puts(t);
         }
-
-        return 0;
 }
 
 static int systemctl_parse_argv(int argc, char *argv[]) {