Any takers?
On Tue, 2021-03-02 at 22:50 +0100, Martijn van Duren wrote:
> Live and learn. While working on a regress test I found that I
> misunderstood some types when I wrote this code. According to RFC2578:
> - timeticks is a 32 bit unsigned int
> - counter32 is a 32 bit unsigned int
> - unsigned is "indistinguishable from Gauge32"
> - integer is a 32 bit integer
>
> OK?
>
> martijn@
>
> Index: snmp.1
> ===================================================================
> RCS file: /cvs/src/usr.bin/snmp/snmp.1,v
> retrieving revision 1.15
> diff -u -p -r1.15 snmp.1
> --- snmp.1 14 Sep 2020 15:12:27 -0000 1.15
> +++ snmp.1 2 Mar 2021 21:48:35 -0000
> @@ -524,7 +524,6 @@ A regular string.
> Timeticks in centiseconds.
> .It Cm u
> Unsigned integer.
> -Actually a normal integer for compatibility with netsnmp.
> .It Cm x
> A hex string.
> Similar to a decimal string, but in hexadecimal format.
> Index: snmpc.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/snmp/snmpc.c,v
> retrieving revision 1.31
> diff -u -p -r1.31 snmpc.c
> --- snmpc.c 2 Dec 2020 15:45:51 -0000 1.31
> +++ snmpc.c 2 Mar 2021 21:48:35 -0000
> @@ -801,7 +801,7 @@ snmpc_trap(int argc, char *argv[])
> if (clock_gettime(CLOCK_UPTIME, &ts) == -1)
> err(1, "clock_gettime");
> } else {
> - lval = strtonum(argv[1], 0, LLONG_MAX, &errstr);
> + lval = strtonum(argv[1], 0, UINT32_MAX, &errstr);
> if (errstr != NULL)
> errx(1, "Bad value notation (%s)", argv[1]);
> ts.tv_sec = lval / 100;
> @@ -1439,7 +1439,7 @@ snmpc_varbindparse(int argc, char *argv[
> */
> goto pastestring;
> case 'c':
> - lval = strtonum(argv[i + 2], INT32_MIN, INT32_MAX,
> + lval = strtonum(argv[i + 2], 0, UINT32_MAX,
> &errstr);
> if (errstr != NULL)
> errx(1, "%s: Bad value notation (%s)",
> argv[i],
> @@ -1472,9 +1472,8 @@ snmpc_varbindparse(int argc, char *argv[
> tmpstr = endstr + 1;
> } while (endstr[0] != '\0');
> goto pastestring;
> - case 'u':
> case 'i':
> - lval = strtonum(argv[i + 2], LLONG_MIN, LLONG_MAX,
> + lval = strtonum(argv[i + 2], INT32_MIN, INT32_MAX,
> &errstr);
> if (errstr != NULL)
> errx(1, "%s: Bad value notation (%s)",
> argv[i],
> @@ -1508,7 +1507,7 @@ pastestring:
> free(str);
> break;
> case 't':
> - lval = strtonum(argv[i + 2], LLONG_MIN, LLONG_MAX,
> + lval = strtonum(argv[i + 2], 0, UINT32_MAX,
> &errstr);
> if (errstr != NULL)
> errx(1, "%s: Bad value notation (%s)",
> argv[i],
> @@ -1516,6 +1515,17 @@ pastestring:
> if ((varbind = ober_printf_elements(varbind, "{Oit}",
> &oid, lval, BER_CLASS_APPLICATION,
> SNMP_T_TIMETICKS)) == NULL)
> + err(1, "ober_printf_elements");
> + break;
> + case 'u':
> + lval = strtonum(argv[i + 2], 0, UINT32_MAX,
> + &errstr);
> + if (errstr != NULL)
> + errx(1, "%s: Bad value notation (%s)",
> argv[i],
> + argv[i + 2]);
> + if ((varbind = ober_printf_elements(varbind, "{Oit}",
> + &oid, lval, BER_CLASS_APPLICATION,
> + SNMP_T_GAUGE32)) == NULL)
> err(1, "ober_printf_elements");
> break;
> case 'x':
>
>