On Thu, 17 May 2007 08:26:18 -0700 (PDT) Need wrote:
NH> In order to learn how to use NetSNMP I was reading through the MFD ifTable tutorial. Part of the code generated for the "ifTable" table (when using the "mib2c" command with the MFD configuration file) is the following:
NH>
NH> if ((rowreq_ctx->data.ifDescr == NULL) ||
NH> (rowreq_ctx->data.ifDescr_len < (ifDescr_len * sizeof(ifDescr[0])))) {
NH> snmp_log(LOG_ERR, "not enough space for value\n");
NH> return MFD_ERROR;
NH> }
NH> rowreq_ctx->data.ifDescr_len = ifDescr_len * sizeof(ifDescr[0]);
NH> memcpy(rowreq_ctx->data.ifDescr, ifDescr, ifDescr_len * sizeof(ifDescr[0]));

Unfortunately, because of the multitude of options available with the mfd
config, simply presenting this code snippet doesn't help. I either need the
source files, or the mfd configuration files ('default' directory). Without
those, I'm going to guess that this code is in your 'container_load' function.

NH> When runnnig this code I get the "not enough space for value" error being produced. The reason why it fails is due to the length check which is being performed (shown below):
NH>
NH> (rowreq_ctx->data.ifDescr_len < (ifDescr_len * sizeof(ifDescr[0])))
NH>
NH> It seems to me that this will always fail since the "rowreq_ctx->data.ifDescr_len" variable does not get populated until "after" the "If" check is performed (see code snipet above).
NH>
NH> Question:
NH> What am I missing? How can this check (which is generated for me automatically using mib2c) actually ever work?

Remember, this code is a template, not a finished product. Note that the
initial code generated for container_load doesn't even define the variables
used in this snipped (ifDescr, ifDescr_len).

Anyways, in other places where this code is used, it is prefixed with

rowreq_ctx->data.ifDescr_len = sizeof(rowreq_ctx->data.ifDescr);

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders