From: Roy Marples Date: Fri, 2 May 2008 08:25:54 +0000 (+0000) Subject: Keep parsing the duid file until we find a valid duid. This allows comments if the... X-Git-Tag: v4.0.2~438 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3304eae5d60c0a82b3c527d696806ea51f4d2e9;p=thirdparty%2Fdhcpcd.git Keep parsing the duid file until we find a valid duid. This allows comments if the user wants them. --- diff --git a/client.c b/client.c index d5b49e6a..2fc52dc2 100644 --- a/client.c +++ b/client.c @@ -237,23 +237,30 @@ get_duid(unsigned char *duid, const struct interface *iface) time_t t; int x = 0; unsigned char *p = duid; - size_t len = 0; - char *line = NULL; + size_t len = 0, l = 0; + char *buffer = NULL, *line, *option; /* If we already have a DUID then use it as it's never supposed * to change once we have one even if the interfaces do */ if ((f = fopen(DUIDFILE, "r"))) { - get_line(&line, &len, f); - if (line) { - len = hwaddr_aton(NULL, line); - if (len && len <= DUID_LEN) - hwaddr_aton(duid, line); - free(line); - } else - len = 0; + while ((get_line(&buffer, &len, f))) { + line = buffer; + while ((option = strsep(&line, " \t"))) + if (*option != '\0') + break; + if (!option || *option == '\0' || *option == '#') + continue; + l = hwaddr_aton(NULL, option); + if (l && l <= DUID_LEN) { + hwaddr_aton(duid, option); + break; + } + l = 0; + } fclose(f); - if (len) - return len; + free(buffer); + if (l) + return l; } else { if (errno != ENOENT) return 0;