×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Hello,
following up to my own post on Tue, 28 Dec 2021 00:11:50 +0100 (
https://archive.midrange.com/c400-l/202112/msg00024.html):
A friend of mine finally took some time analyzing the code mix of me and an IBM provided example (
https://www.ibm.com/docs/en/i/7.1?topic=ssw_ibm_i_71/apis/snmpexmp.htm) to get this to run.
Good news: It wasn't me. It's not a bug in the API. But the code example "AddVarbind()" provided by IBM is flawed.
- The "switch" statement has a typo. It's "default:", not "defaults:".
- The first memset references the first array element wrong. Must be:
memset( (snmppdu *) pdu[0], 0, sizeof(*pdu[0]) );
- Just before the first else in the major if() branch, API_MAX_VALUE_SIZE+1 is malloc()'ed, but the holding variable for the allocated size is not set to that value. Must be:
t->val_len = API_MAX_VALUE_SIZE+1;
However, this is handled correctly in the else branch.
The last point was the crucial one. When t->val_len is left uninitialized (assumedly being 0), the API function simply uses this designation of "no space" to copy 0 bytes of the the result data of snmpGet() into the final storage location.
Apparently this example has not been tested before being published. And it isn't the first time that I'm caught by apparently untested code examples from IBM. Lesson learned: Don't assume example code has been tested.
Huge thanks to Andy from the local hacker space for taking valuable time to pin down this issue!
:wq! PoC
As an Amazon Associate we earn from qualifying purchases.