Hello,

On Thursday 15 October 2009 12:18:35 Karthikeyan N wrote:
> In interfaces.c file, I could see the following code.
>
> case IFINOCTETS:
>         long_return = (u_long) if_msg.ifm_data.ifi_ibytes;
>         return (u_char *) & long_return;
>
> I could see a possiblity of 2 different issues with the above code.
>
> 1. global variable 'long return' is defined as long (signed) in
> snmp_vars.c which can take even negative values. Does it correct as
> per SNMP standard? The code has to generate a unsigned long variable
> since Counter32 can hold only positive values?

Type of global variable 'long_return' does not matter here at all. 
Signed and unsigned variables differs only in the sense of its high bit, and 
same bytes can be interpreted either as signed integer or as unsigned. 

Callback 'var_ifEntry' returns only pointer to the data, which should be put 
into SNMP response. Way to interpret this data depends on ASN type of MIB
entry, specified in array 'interfaces_variables' in the same file.

For ensure that variables with ASN_COUNTER type will be put into 
PDU as unsigned integer, you may see at implementation of function 
'snmp_build_var_op()' in file snmplib/snmp.c; which called for all variables. 

Only question here is to avoid possible loss of some highest bits at the 
assignment, which you included in your letter.
According to C language specification, in assignment of variables with the
same length, no information is lost, and all bits will be copied.


> 2. As per the SNMP Standard, Counter32 values when it reaches the
> maximum, it has to reset to zero, but in the above code snippet in
> interfaces.c, there is no such syntax to reset the value to zero if it
> reaches maximum.

There is no code to support changes of this counter at all in SNMP agent. 
Its value is copied from internal kernel structures after each SNMP request, 
and its increase and reset to zero if it reaches maximum should be supported 
somewhere near hardware device driver. 

>
> Please clarify.
>
> Thank You.
>
> Regards,
> Karthik N



-- 
Konstantin V.Abramenko
OKTET Labs Ltd. 
http://www.oktetlabs.ru

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
  • ifInOctets Karthikeyan N
    • Re: ifInOctets Konstantin Abramenko

Reply via email to