]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move vendor out of global scope.
authorRoy Marples <roy@marples.name>
Sat, 8 Feb 2014 00:29:02 +0000 (00:29 +0000)
committerRoy Marples <roy@marples.name>
Sat, 8 Feb 2014 00:29:02 +0000 (00:29 +0000)
dhcp-common.c
dhcp-common.h
dhcp6.c
dhcpcd.c
dhcpcd.h
if-options.c

index c8db0738a2881d1e619816d0233cec57ba57f5aa..0ab77531aca42f7e9110c830d21c5c787a4cd516 100644 (file)
@@ -25,6 +25,8 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/utsname.h>
+
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -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)
index d9ccea9c09706732d97c2f47fc2eadab92b4fde6..df3083dee080e374fae1101f0e93303d360583bb 100644 (file)
@@ -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 623e2db86c3e7785af0fc8ce33d3e549b569e14f..033036b8a805ee3f8dd5e050bf0b72133fa5008a 100644 (file)
--- 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;
        }
 
index 41f13970aef01ba141561a0d23bc05e3bef7cb0f..6a5ec71c44699d2d769c6b831bed9167caef7150 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -33,7 +33,6 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples";
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/uio.h>
-#include <sys/utsname.h>
 
 #include <ctype.h>
 #include <errno.h>
@@ -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)
        {
index e16fec6c5dd4882f8bce682088a819509b67a74b..bf90042ae4a757e380b2472f96bf9648c362ef98 100644 (file)
--- 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;
index 95313cd23cac725442958233dc200906fbcb7078..3c1ddabcad83cb4da94ba8d74be304c01d41e750 100644 (file)
@@ -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;