From 0475e18804dfd9f5601511b6ffc2556efa5a68a7 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Sat, 26 Dec 2020 21:38:49 +0100 Subject: [PATCH] dhcpv6: display status code as a string For better readibility display the returned status code from the DHCPv6 server as a string Signed-off-by: Hans Dedecker --- src/dhcpv6.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index b9eac43..60c0b24 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -162,6 +162,37 @@ static char *dhcpv6_msg_to_str(enum dhcpv6_msg msg) return "UNKNOWN"; } +static char *dhcpv6_status_code_to_str(uint16_t code) +{ + switch (code) { + case DHCPV6_Success: + return "Success"; + + case DHCPV6_UnspecFail: + return "Unspecified Failure"; + + case DHCPV6_NoAddrsAvail: + return "No Address Available"; + + case DHCPV6_NoBinding: + return "No Binding"; + + case DHCPV6_NotOnLink: + return "Not On Link"; + + case DHCPV6_UseMulticast: + return "Use Multicast"; + + case DHCPV6_NoPrefixAvail: + return "No Prefix Available"; + + default: + break; + } + + return "Unknown"; +} + int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout) { client_options = options; @@ -1487,8 +1518,8 @@ static void dhcpv6_log_status_code(const uint16_t code, const char *scope, *dst = 0; - syslog(LOG_WARNING, "Server returned %s status %i %s", - scope, code, buf); + syslog(LOG_WARNING, "Server returned %s status '%s %s'", + scope, dhcpv6_status_code_to_str(code), buf); } static void dhcpv6_handle_status_code(const enum dhcpv6_msg orig, -- 2.30.2