Skip to content

Commit de292aa

Browse files
committed
resolve-host: make arg_type an int
We are using it also to store _DNS_TYPE_INVALID, so it should be signed.
1 parent 7263f72 commit de292aa

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ src/resolve/dns_type-list.txt: src/resolve/dns-type.h
11891189
$(AM_V_GEN)$(SED) -n -r 's/.* DNS_TYPE_(\w+).*/\1/p' <$< >$@
11901190

11911191
src/resolve/dns_type-to-name.h: src/resolve/dns_type-list.txt
1192-
$(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" }' <$< >$@
1192+
$(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" }' <$< >$@
11931193

11941194
src/resolve/dns_type-from-name.gperf: src/resolve/dns_type-list.txt
11951195
$(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-host/resolve-host.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
static int arg_family = AF_UNSPEC;
3939
static int arg_ifindex = 0;
40-
static uint16_t arg_type = 0;
40+
static int arg_type = 0;
4141
static uint16_t arg_class = 0;
4242
static bool arg_legend = true;
4343

@@ -316,6 +316,7 @@ static int resolve_record(sd_bus *bus, const char *name) {
316316
if (r < 0)
317317
return bus_log_create_error(r);
318318

319+
assert((uint16_t) arg_type == arg_type);
319320
r = sd_bus_message_append(req, "sqq", name, arg_class, arg_type);
320321
if (r < 0)
321322
return bus_log_create_error(r);
@@ -482,11 +483,12 @@ static int parse_argv(int argc, char *argv[]) {
482483
return 0;
483484
}
484485

485-
r = dns_type_from_string(optarg, &arg_type);
486-
if (r < 0) {
486+
arg_type = dns_type_from_string(optarg);
487+
if (arg_type < 0) {
487488
log_error("Failed to parse RR record type %s", optarg);
488489
return r;
489490
}
491+
assert(arg_type > 0 && (uint16_t) arg_type == arg_type);
490492

491493
break;
492494

src/resolve/dns-type.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ lookup_dns_type (register const char *str, register unsigned int len);
3232
#include "dns_type-from-name.h"
3333
#include "dns_type-to-name.h"
3434

35-
int dns_type_from_string(const char *s, uint16_t *type) {
35+
int dns_type_from_string(const char *s) {
3636
const struct dns_type_name *sc;
3737

3838
assert(s);
39-
assert(type);
4039

4140
sc = lookup_dns_type(s, strlen(s));
4241
if (!sc)
43-
return -EINVAL;
42+
return _DNS_TYPE_INVALID;
4443

45-
*type = sc->id;
46-
return 0;
44+
return sc->id;
4745
}

src/resolve/dns-type.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121

2222
#pragma once
2323

24-
#include <inttypes.h>
25-
2624
#include "macro.h"
2725

28-
const char *dns_type_to_string(uint16_t type);
29-
int dns_type_from_string(const char *s, uint16_t *type);
26+
const char *dns_type_to_string(int type);
27+
int dns_type_from_string(const char *s);
3028

3129
/* DNS record types, taken from
3230
* http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.

0 commit comments

Comments
 (0)