From: Roy Marples Date: Sat, 8 Feb 2014 00:29:02 +0000 (+0000) Subject: Move vendor out of global scope. X-Git-Tag: v6.3.0~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d074b2494f8418ad169aa9f6a90388fa206afb75;p=thirdparty%2Fdhcpcd.git Move vendor out of global scope. --- diff --git a/dhcp-common.c b/dhcp-common.c index c8db0738..0ab77531 100644 --- a/dhcp-common.c +++ b/dhcp-common.c @@ -25,6 +25,8 @@ * SUCH DAMAGE. */ +#include + #include #include #include @@ -37,6 +39,7 @@ #include "common.h" #include "dhcp-common.h" #include "dhcp.h" +#include "platform.h" /* DHCP Enterprise options, RFC3925 */ struct dhcp_opt *vivso = NULL; @@ -63,6 +66,22 @@ vivso_find(uint16_t iana_en, const void *arg) return NULL; } +size_t +dhcp_vendor(char *str, size_t strlen) +{ + struct utsname utn; + char *p; + + if (uname(&utn) != 0) + return snprintf(str, strlen, "%s-%s", PACKAGE, VERSION); + p = str; + p += snprintf(str, strlen, + "%s-%s:%s-%s:%s", PACKAGE, VERSION, + utn.sysname, utn.release, utn.machine); + p += hardware_platform(p, strlen - (p - str)); + return p - str; +} + int make_option_mask(const struct dhcp_opt *dopts, size_t dopts_len, uint8_t *mask, const char *opts, int add) diff --git a/dhcp-common.h b/dhcp-common.h index d9ccea9c..df3083de 100644 --- a/dhcp-common.h +++ b/dhcp-common.h @@ -85,6 +85,8 @@ extern size_t vivso_len; struct dhcp_opt *vivso_find(uint16_t, const void *); +size_t dhcp_vendor(char *, size_t); + #define add_option_mask(var, val) (var[val >> 3] |= 1 << (val & 7)) #define del_option_mask(var, val) (var[val >> 3] &= ~(1 << (val & 7))) #define has_option_mask(var, val) (var[val >>3] & (1 << (val & 7))) diff --git a/dhcp6.c b/dhcp6.c index 623e2db8..033036b8 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -184,6 +184,7 @@ dhcp6_makevendor(struct dhcp6_option *o, const struct interface *ifp) uint32_t u32; size_t vlen, i; const struct vivco *vivco; + char vendor[VENDORCLASSID_MAX_LEN]; ifo = ifp->options; len = sizeof(uint32_t); /* IANA PEN */ @@ -194,7 +195,7 @@ dhcp6_makevendor(struct dhcp6_option *o, const struct interface *ifp) len += sizeof(uint16_t) + vivco->len; vlen = 0; /* silence bogus gcc warning */ } else { - vlen = strlen(vendor); + vlen = dhcp_vendor(vendor, sizeof(vendor)); len += sizeof(uint16_t) + vlen; } diff --git a/dhcpcd.c b/dhcpcd.c index 41f13970..6a5ec71c 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -33,7 +33,6 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples"; #include #include #include -#include #include #include @@ -67,7 +66,6 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples"; #include "script.h" struct if_head *ifaces = NULL; -char vendor[VENDORCLASSID_MAX_LEN]; struct if_options *if_options = NULL; int ifac = 0; char **ifav = NULL; @@ -1063,14 +1061,13 @@ signal_init(void (*func)(int, siginfo_t *, void *), sigset_t *oldset) int main(int argc, char **argv) { - char *pidfile, *p; + char *pidfile; struct interface *ifp; uint16_t family = 0; int opt, oi = 0, sig = 0, i; size_t len; pid_t pid; struct timespec ts; - struct utsname utn; struct control_ctx control_ctx; pidfile = NULL; @@ -1089,16 +1086,6 @@ main(int argc, char **argv) } } - if (uname(&utn) == 0) { - p = vendor; - p += snprintf(vendor, VENDORCLASSID_MAX_LEN, - "%s-%s:%s-%s:%s", PACKAGE, VERSION, - utn.sysname, utn.release, utn.machine); - hardware_platform(p, VENDORCLASSID_MAX_LEN - (p - vendor)); - } else - snprintf(vendor, VENDORCLASSID_MAX_LEN, - "%s-%s", PACKAGE, VERSION); - i = 0; while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1) { diff --git a/dhcpcd.h b/dhcpcd.h index e16fec6c..bf90042a 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -69,7 +69,6 @@ struct interface { }; extern TAILQ_HEAD(if_head, interface) *ifaces; -extern char vendor[VENDORCLASSID_MAX_LEN]; extern sigset_t dhcpcd_sigset; extern int ifac; extern char **ifav; diff --git a/if-options.c b/if-options.c index 95313cd2..3c1ddabc 100644 --- a/if-options.c +++ b/if-options.c @@ -1825,8 +1825,8 @@ read_config(const char *file, TAILQ_INIT(&ifo->auth.tokens); strlcpy(ifo->script, SCRIPT, sizeof(ifo->script)); - ifo->vendorclassid[0] = strlen(vendor); - memcpy(ifo->vendorclassid + 1, vendor, ifo->vendorclassid[0]); + ifo->vendorclassid[0] = dhcp_vendor((char *)ifo->vendorclassid + 1, + sizeof(ifo->vendorclassid) - 1); buf = NULL; buflen = 0;