]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add support for int8 and uint8 data types.
authorRoy Marples <roy@marples.name>
Mon, 11 Apr 2016 16:25:54 +0000 (16:25 +0000)
committerRoy Marples <roy@marples.name>
Mon, 11 Apr 2016 16:25:54 +0000 (16:25 +0000)
Rename SINT* to INT* to match C semantics.

dhcp-common.c
dhcp-common.h
if-options.c

index eede4be7a32a02362530e2dd49ecd99c538ceff1..6951a569def913285122fbdefa619c31fc1dc29f 100644 (file)
@@ -100,15 +100,17 @@ dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols)
        if (opt->type & ARRAY)
                printf(" array");
        if (opt->type & UINT8)
-               printf(" byte");
+               printf(" uint8");
+       else if (opt->type & INT8)
+               printf(" int8");
        else if (opt->type & UINT16)
                printf(" uint16");
-       else if (opt->type & SINT16)
-               printf(" sint16");
+       else if (opt->type & INT16)
+               printf(" int16");
        else if (opt->type & UINT32)
                printf(" uint32");
-       else if (opt->type & SINT32)
-               printf(" sint32");
+       else if (opt->type & INT32)
+               printf(" int32");
        else if (opt->type & ADDRIPV4)
                printf(" ipaddress");
        else if (opt->type & ADDRIPV6)
@@ -589,11 +591,11 @@ dhcp_optlen(const struct dhcp_opt *opt, size_t dl)
 
        if (opt->type & ADDRIPV6)
                sz = ADDR6SZ;
-       else if (opt->type & (UINT32 | ADDRIPV4))
+       else if (opt->type & (INT32 | UINT32 | ADDRIPV4))
                sz = sizeof(uint32_t);
-       else if (opt->type & UINT16)
+       else if (opt->type & (INT16 | UINT16))
                sz = sizeof(uint16_t);
-       else if (opt->type & (UINT8 | BITFLAG))
+       else if (opt->type & (INT8 | UINT8 | BITFLAG))
                sz = sizeof(uint8_t);
        else if (opt->type & FLAG)
                return 0;
@@ -732,16 +734,18 @@ print_option(char *s, size_t len, const struct dhcp_opt *opt,
        if (!s) {
                if (opt->type & UINT8)
                        l = 3;
+               else if (opt->type & INT8)
+                       l = 4;
                else if (opt->type & UINT16) {
                        l = 5;
                        dl /= 2;
-               } else if (opt->type & SINT16) {
+               } else if (opt->type & INT16) {
                        l = 6;
                        dl /= 2;
                } else if (opt->type & UINT32) {
                        l = 10;
                        dl /= 4;
-               } else if (opt->type & SINT32) {
+               } else if (opt->type & INT32) {
                        l = 11;
                        dl /= 4;
                } else if (opt->type & ADDRIPV4) {
@@ -778,12 +782,15 @@ print_option(char *s, size_t len, const struct dhcp_opt *opt,
                if (opt->type & UINT8) {
                        sl = snprintf(s, len, "%u", *data);
                        data++;
+               } else if (opt->type & INT8) {
+                       sl = snprintf(s, len, "%d", *data);
+                       data++;
                } else if (opt->type & UINT16) {
                        memcpy(&u16, data, sizeof(u16));
                        u16 = ntohs(u16);
                        sl = snprintf(s, len, "%u", u16);
                        data += sizeof(u16);
-               } else if (opt->type & SINT16) {
+               } else if (opt->type & INT16) {
                        memcpy(&u16, data, sizeof(u16));
                        s16 = (int16_t)ntohs(u16);
                        sl = snprintf(s, len, "%d", s16);
@@ -793,7 +800,7 @@ print_option(char *s, size_t len, const struct dhcp_opt *opt,
                        u32 = ntohl(u32);
                        sl = snprintf(s, len, "%u", u32);
                        data += sizeof(u32);
-               } else if (opt->type & SINT32) {
+               } else if (opt->type & INT32) {
                        memcpy(&u32, data, sizeof(u32));
                        s32 = (int32_t)ntohl(u32);
                        sl = snprintf(s, len, "%d", s32);
index 5f9f9e60458b883f32dade587d06bdc142fffdb8..466c5221c98729e961cf0534b4a2b5d9106df25e 100644 (file)
 
 #define REQUEST                (1 << 0)
 #define UINT8          (1 << 1)
-#define UINT16         (1 << 2)
-#define SINT16         (1 << 3)
-#define UINT32         (1 << 4)
-#define SINT32         (1 << 5)
-#define ADDRIPV4       (1 << 6)
-#define STRING         (1 << 7)
-#define ARRAY          (1 << 8)
-#define RFC3361                (1 << 9)
-#define RFC1035                (1 << 10)
-#define RFC3442                (1 << 11)
-#define OPTIONAL       (1 << 12)
-#define ADDRIPV6       (1 << 13)
-#define BINHEX         (1 << 14)
-#define FLAG           (1 << 15)
-#define NOREQ          (1 << 16)
-#define EMBED          (1 << 17)
-#define ENCAP          (1 << 18)
-#define INDEX          (1 << 19)
-#define OPTION         (1 << 20)
-#define DOMAIN         (1 << 21)
-#define ASCII          (1 << 22)
-#define RAW            (1 << 23)
-#define ESCSTRING      (1 << 24)
-#define ESCFILE                (1 << 25)
-#define BITFLAG                (1 << 26)
-#define RESERVED       (1 << 27)
+#define INT8           (1 << 2)
+#define UINT16         (1 << 3)
+#define INT16          (1 << 4)
+#define UINT32         (1 << 5)
+#define INT32          (1 << 6)
+#define ADDRIPV4       (1 << 7)
+#define STRING         (1 << 8)
+#define ARRAY          (1 << 9)
+#define RFC3361                (1 << 10)
+#define RFC1035                (1 << 11)
+#define RFC3442                (1 << 12)
+#define OPTIONAL       (1 << 13)
+#define ADDRIPV6       (1 << 14)
+#define BINHEX         (1 << 15)
+#define FLAG           (1 << 16)
+#define NOREQ          (1 << 17)
+#define EMBED          (1 << 18)
+#define ENCAP          (1 << 19)
+#define INDEX          (1 << 20)
+#define OPTION         (1 << 21)
+#define DOMAIN         (1 << 22)
+#define ASCII          (1 << 23)
+#define RAW            (1 << 24)
+#define ESCSTRING      (1 << 25)
+#define ESCFILE                (1 << 26)
+#define BITFLAG                (1 << 27)
+#define RESERVED       (1 << 28)
 
 struct dhcp_opt {
        uint32_t option; /* Also used for IANA Enterpise Number */
index 2653937a7b7009b7f0b0a4135f57dbe327ffb10e..fce74f88436b8da87bfc950b5088067f374b4711 100644 (file)
@@ -1683,14 +1683,18 @@ err_sla:
                        t |= UINT8;
                else if (strcasecmp(arg, "bitflags") == 0)
                        t |= BITFLAG;
+               else if (strcasecmp(arg, "uint8") == 0)
+                       t |= UINT8;
+               else if (strcasecmp(arg, "int8") == 0)
+                       t |= INT8;
                else if (strcasecmp(arg, "uint16") == 0)
                        t |= UINT16;
                else if (strcasecmp(arg, "int16") == 0)
-                       t |= SINT16;
+                       t |= INT16;
                else if (strcasecmp(arg, "uint32") == 0)
                        t |= UINT32;
                else if (strcasecmp(arg, "int32") == 0)
-                       t |= SINT32;
+                       t |= INT32;
                else if (strcasecmp(arg, "flag") == 0)
                        t |= FLAG;
                else if (strcasecmp(arg, "raw") == 0)