use lookup array for dns_type_string()
authorFelix Fietkau <nbd@openwrt.org>
Mon, 9 Jun 2014 22:11:50 +0000 (00:11 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 9 Jun 2014 22:11:50 +0000 (00:11 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
dns.c

diff --git a/dns.c b/dns.c
index c8d21006220f1fcb8bbef1e0e192724f31c42257..9c7b7ded177a1f31d7139091f1e7fd4cb4a35959 100644 (file)
--- 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";