Hi,
for a project I'm working on, I need to set the value contained in a
netsnmp_variable_list getting type and value from a "generic" variable
implemented as a C++ class. I could do something like create a buffer of
the right size, fill it with the value and the call snmp_set_var_value,
but this would mean copying the value two times (once to fill the
buffer, plus another copy in snmp_set_var_value itself). Thus I thought
to mimic the behaviour of snmp_set_var_value and set the value directly.
Looking into the code of this routine I had to wonder... How does it
work if the given value is an Object Identifier of length (= number of
subidentifiers) less than 10?

>From the first lines of code, if the parameter len (i.e. the size of the
value measured in bytes) is less than 40 (which does happen if the value
is an objid with less than 10 subidentifiers), the local variable
largeval is set to 0 and vars->val.string field is made point to the 40
characters array vars->buf. Nothing is done about vars->val.objid. Then,
in the relevant case of the switch there is the following code:

|        if (largeval) {
            vars->val.objid = (oid *) malloc(vars->val_len);
        }
        if (vars->val.objid == NULL) {
            snmp_log(LOG_ERR,"no storage for OID\n");
            return 1;
        }
|
Thus my question is... How does it work (and work it does) when largeval
as been set to 0, len being less than 40? In other words, where does it
points vars->val.objid? to vars->buff? And if it so, who ensured it?
Shouldn't we have a

|vars->val.objid = (oid *) vars->buf;
|
in the body of the if at line 774 of snmp_client.c?

By the way, is reimplementing this function the right approach to the
problem or should I accept the overhead of the double-copy approach? Or
someone on the list has a different approach to suggest?

Leo

-- 
Leo Cacciari
Aliae nationes servitutem pati possunt populi romani est propria libertas

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to