dhcpv6: rework DHCPv6 message to string implementation
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 8 Dec 2020 17:31:25 +0000 (18:31 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Tue, 8 Dec 2020 17:35:15 +0000 (18:35 +0100)
As the DHCPv6 messages handled by odhcp6c are not numerical consecutive
drop the DHCPv6 message string array

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/dhcpv6.c

index e81918935756b08fd0801f3f2778008cb57710a6..312e7aa80c0df266593a2a3af608f548e2254c63 100644 (file)
@@ -124,23 +124,42 @@ static uint32_t ntohl_unaligned(const uint8_t *data)
 
 static char *dhcpv6_msg_to_str(enum dhcpv6_msg msg)
 {
-       static char *dhcpv6_msg_str[] = {
-               "UNKNOWN",
-               "SOLICIT",
-               "ADVERTISE",
-               "REQUEST",
-               "RENEW",
-               "REBIND",
-               "REPLY",
-               "DECLINE",
-               "RECONFIGURE",
-               "INFORMATION REQUEST",
-       };
+       switch (msg) {
+       case DHCPV6_MSG_SOLICIT:
+               return "SOLICIT";
+
+       case DHCPV6_MSG_ADVERT:
+               return "ADVERTISE";
+
+       case DHCPV6_MSG_REQUEST:
+               return "REQUEST";
+
+       case DHCPV6_MSG_RENEW:
+               return "RENEW";
+
+       case DHCPV6_MSG_REBIND:
+               return "REBIND";
 
-       if (msg < _DHCPV6_MSG_MAX)
-               return dhcpv6_msg_str[msg];
+       case DHCPV6_MSG_REPLY:
+               return "REPLY";
+
+       case DHCPV6_MSG_RELEASE:
+               return "RELEASE";
+
+       case DHCPV6_MSG_DECLINE:
+               return "DECLINE";
+
+       case DHCPV6_MSG_RECONF:
+               return "RECONFIGURE";
+
+       case DHCPV6_MSG_INFO_REQ:
+               return "INFORMATION REQUEST";
+
+       default:
+               break;
+       }
 
-       return "Unknown";
+       return "UNKNOWN";
 }
 
 int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout)