From: Felix Fietkau Date: Mon, 9 Jun 2014 22:11:50 +0000 (+0200) Subject: use lookup array for dns_type_string() X-Git-Url: http://git.archive.openwrt.org/?a=commitdiff_plain;h=5e7c65b68ada5a07228ccb83a3b151f633c4725f;p=project%2Fmdnsd.git use lookup array for dns_type_string() Signed-off-by: Felix Fietkau --- diff --git a/dns.c b/dns.c index c8d2100..9c7b7de 100644 --- a/dns.c +++ b/dns.c @@ -44,24 +44,22 @@ static char name_buffer[MAX_NAME_LEN + 1]; const char* dns_type_string(uint16_t type) { - switch (type) { - case TYPE_A: - return "A"; - - case TYPE_AAAA: - return "AAAA"; - - case TYPE_PTR: - return "PTR"; - - case TYPE_TXT: - return "TXT"; - - case TYPE_SRV: - return "SRV"; + static const struct { + uint16_t type; + char str[5]; + } type_str[] = { + { TYPE_A, "A" }, + { TYPE_AAAA, "AAAA" }, + { TYPE_PTR, "PTR" }, + { TYPE_TXT, "TXT" }, + { TYPE_SRV, "SRV" }, + { TYPE_ANY, "ANY" }, + }; + int i; - case TYPE_ANY: - return "ANY"; + for (i = 0; i < ARRAY_SIZE(type_str); i++) { + if (type == type_str[i].type) + return type_str[i].str; } return "N/A";