Rob Pierce(r...@2keys.ca) on 2018.06.10 13:25:23 -0400: > This brings snmpd agentx.c closer to relayd agentx.c. > > In the remaining delta, I am not sure if the pdu context code should be > removed > from the snmpd version or added to the relayd version. > > Anyway, this is one step closer. > > Ok?
ok > Rob > > Index: agentx.c > =================================================================== > RCS file: /cvs/src/usr.sbin/snmpd/agentx.c,v > retrieving revision 1.12 > diff -u -p -r1.12 agentx.c > --- agentx.c 14 Feb 2018 12:43:07 -0000 1.12 > +++ agentx.c 10 Jun 2018 16:59:01 -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; > > @@ -1038,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); > 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 10 Jun 2018 16:59:01 -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 10 Jun 2018 16:59:01 -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, >