From: Roy Marples Date: Wed, 29 Jan 2014 18:33:43 +0000 (+0000) Subject: If no status message given, supply a default. X-Git-Tag: v6.3.0~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=699660fba0971b03c65654fa760cee7e3577c9ed;p=thirdparty%2Fdhcpcd.git If no status message given, supply a default. --- diff --git a/dhcp6.c b/dhcp6.c index 4e696e59..ec585883 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -122,6 +122,15 @@ const struct dhcp_compat dhcp_compats[] = { { 0, 0 } }; +static const char * const dhcp6_statuses[] = { + "Success", + "Unspecified Failure", + "No Addresses Available", + "No Binding", + "Not On Link", + "Use Multicast" +}; + #if DEBUG_MEMORY static void dhcp6_cleanup(void) @@ -1191,12 +1200,13 @@ dhcp6_startrelease(struct interface *ifp) static int dhcp6_getstatus(const struct dhcp6_option *o) { + uint16_t code; char *nstatus; - const struct dhcp6_status *s; size_t len; + const uint8_t *p; len = ntohs(o->len); - if (len < sizeof(uint16_t)) { + if (len < sizeof(code)) { syslog(LOG_ERR, "status truncated"); return -1; } @@ -1205,8 +1215,21 @@ static int dhcp6_getstatus(const struct dhcp6_option *o) syslog(LOG_ERR, "not a status"); return -1; } - s = (const struct dhcp6_status *)o; - len = ntohs(s->len) - sizeof(s->len); + p = D6_COPTION_DATA(o); + len = ntohs(o->len); + memcpy(&code, p, sizeof(code)); + code = ntohs(code); + len -= sizeof(code); + + if (len == 0) { + if (code < sizeof(dhcp6_statuses) / sizeof(char *)) { + p = (const uint8_t *)dhcp6_statuses[code]; + len = strlen((const char *)p); + } else + p = NULL; + } else { + p = D6_COPTION_DATA(o) + sizeof(uint16_t); + } if (status == NULL || len + 1 > status_len) { status_len = len; nstatus = realloc(status, status_len + 1); @@ -1217,10 +1240,10 @@ static int dhcp6_getstatus(const struct dhcp6_option *o) status = nstatus; } if (status) { - memcpy(status, (const char *)s + sizeof(*s), len); + memcpy(status, p, len); status[len] = '\0'; } - return ntohs(s->status); + return code; } static int diff --git a/dhcp6.h b/dhcp6.h index dc2b527f..4c53d427 100644 --- a/dhcp6.h +++ b/dhcp6.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2013 Roy Marples + * Copyright (c) 2006-2014 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -104,13 +104,6 @@ struct dhcp6_option { /* followed by data */ } __packed; -struct dhcp6_status { - uint16_t code; - uint16_t len; - uint16_t status; - /* followed by message */ -} __packed; - #define D6_STATUS_OK 0 #define D6_STATUS_FAIL 1 #define D6_STATUS_NOADDR 2