use lookup array for dns_type_string()
[project/mdnsd.git] / dns.c
diff --git a/dns.c b/dns.c
index c8d2100..9c7b7de 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";