On Mon, Feb 12, 2018 at 03:03:07PM -0500, Rob Pierce wrote: > This reduces the diff with relayd/agentx.c.
A little bit closer now. ok? Index: agentx.c =================================================================== RCS file: /cvs/src/usr.sbin/snmpd/agentx.c,v retrieving revision 1.11 diff -u -p -r1.11 agentx.c --- agentx.c 5 Jan 2018 08:13:32 -0000 1.11 +++ agentx.c 12 Feb 2018 22:08:34 -0000 @@ -18,12 +18,8 @@ #include <sys/types.h> #include <sys/socket.h> #include <sys/queue.h> -#include <sys/uio.h> #include <sys/un.h> -#include <arpa/inet.h> - -#include <err.h> #include <errno.h> #include <stdlib.h> #include <stdio.h> @@ -217,9 +213,14 @@ snmp_agentx_response(struct agentx_handl { struct agentx_response_data resp; - if (snmp_agentx_read_response(pdu, &resp) == -1) + if (snmp_agentx_read_raw(pdu, &resp, sizeof(resp)) == -1) return (-1); + if (!snmp_agentx_byteorder_native(pdu->hdr)) { + resp.error = snmp_agentx_int16_byteswap(resp.error); + resp.index = snmp_agentx_int16_byteswap(resp.index); + } + h->error = resp.error; if (resp.error != AGENTX_ERR_NONE) return (-1); @@ -227,20 +228,6 @@ snmp_agentx_response(struct agentx_handl return (0); } -int -snmp_agentx_read_response(struct agentx_pdu *pdu, struct agentx_response_data *resp) -{ - if (snmp_agentx_read_raw(pdu, resp, sizeof(*resp)) == -1) - return (-1); - - if (!snmp_agentx_byteorder_native(pdu->hdr)) { - resp->error = snmp_agentx_int16_byteswap(resp->error); - resp->index = snmp_agentx_int16_byteswap(resp->index); - } - - return (0); -} - /* * Read the response PDU for an open operation. */ @@ -341,7 +328,7 @@ snmp_agentx_recv(struct agentx_handle *h if (h->r == NULL) { if ((h->r = snmp_agentx_pdu_alloc()) == NULL) return (NULL); - h->r->datalen = 0; /* XXX -- force this for receive buffers */ + h->r->datalen = 0; /* XXX force this for receive buffers */ } pdu = h->r; @@ -962,7 +949,8 @@ snmp_agentx_do_read_oid(struct agentx_pd } int -snmp_agentx_read_searchrange(struct agentx_pdu *pdu, struct agentx_search_range *sr) +snmp_agentx_read_searchrange(struct agentx_pdu *pdu, + struct agentx_search_range *sr) { if (snmp_agentx_do_read_oid(pdu, &sr->start, &sr->include) == -1 || snmp_agentx_read_oid(pdu, &sr->end) == -1) @@ -1037,7 +1025,7 @@ snmp_oid2string(struct snmp_oid *o, char bzero(buf, len); for (i = 0; i < o->o_n; i++) { - snprintf(str, sizeof(str), "%d", o->o_id[i]); + snprintf(str, sizeof(str), "%u", o->o_id[i]); strlcat(buf, str, len); if (i < (o->o_n - 1)) strlcat(buf, ".", len); @@ -1124,7 +1112,7 @@ snmp_agentx_dump_hdr(struct agentx_hdr * return; } - fprintf(stderr, + fprintf(stderr, "agentx: version %d type %s flags %d reserved %d" " sessionid %d transactid %d packetid %d length %d", hdr->version, snmp_agentx_type2name(hdr->type), hdr->flags, Index: control.c =================================================================== RCS file: /cvs/src/usr.sbin/snmpd/control.c,v retrieving revision 1.42 diff -u -p -r1.42 control.c --- control.c 21 Apr 2017 13:50:23 -0000 1.42 +++ control.c 12 Feb 2018 22:08:34 -0000 @@ -537,7 +537,7 @@ control_dispatch_agentx(int fd, short ev struct agentx_varbind_hdr vbhdr; struct ber_element **elm, **iter; - if (snmp_agentx_read_response(pdu, &resp) == -1) { + if (snmp_agentx_read_raw(pdu, &resp, sizeof(resp)) == -1) { msg->sm_error = SNMP_ERROR_GENERR; goto dispatch; } Index: snmp.h =================================================================== RCS file: /cvs/src/usr.sbin/snmpd/snmp.h,v retrieving revision 1.14 diff -u -p -r1.14 snmp.h --- snmp.h 11 Jun 2015 18:49:09 -0000 1.14 +++ snmp.h 12 Feb 2018 22:08:34 -0000 @@ -369,7 +369,6 @@ struct agentx_handle * struct agentx_handle * snmp_agentx_fdopen(int, char *, struct snmp_oid *); int snmp_agentx_response(struct agentx_handle *, struct agentx_pdu *); -int snmp_agentx_read_response(struct agentx_pdu *, struct agentx_response_data *); int snmp_agentx_open_response(struct agentx_handle *, struct agentx_pdu *); struct agentx_pdu * snmp_agentx_open_pdu(struct agentx_handle *, char *descr,