I'm developing an app using net-snmp library version 5.5 on 64bit Linux. 
The reading is asynchronous. I have this piece of code:

             if (pdu->errstat == SNMP_ERR_NOERROR) {
                 while (vp) {
                     snprint_variable(buf, sizeof(buf), vp->name, 
vp->name_length, vp);
                     snprint_objid(buf, sizeof(buf), vp->name, vp->name_length);

                     if (vp->type == ASN_OCTET_STR) {
                         if (index((char *)vp->val.string, '.'))
                             snprintf(value, sizeof(value), "%.2f", atof((char 
*)vp->val.string));
                         else
                             snprintf(value, sizeof(value), "%d", atoi((char 
*)vp->val.string));
                     } else if (vp->type == ASN_GAUGE) {
                         snprintf(value, sizeof(value), "%lu", 
*vp->val.integer);
                     } else if (vp->type == ASN_INTEGER) {
                         snprintf(value, sizeof(value), "%li", 
*vp->val.integer);
                     } else if (vp->type == ASN_COUNTER) {
                         snprintf(value, sizeof(value), "%lu", 
*vp->val.integer);
                     } else if (vp->type == ASN_COUNTER64) {
                         long i64 = 0;
                         i64 = vp->val.counter64->low;
                         i64 |= vp->val.counter64->high << 32;
                         snprintf(value, sizeof(value), "%lu", i64);
                     } else if (vp->type == ASN_TIMETICKS) {
                         snprintf(value, sizeof(value), "%lu", 
*vp->val.integer);
                     }

                     vp = vp->next_variable;
                 }
             } else {
                ...

This code goes through the returned values and writes to the buffer the 
*vp->val.XXX.
The problem is with the counter64 structure, containing "low" and "high" 
unsigned long ints.
Is the code
        long i64 = 0;
         i64 = vp->val.counter64->low;
         i64 |= vp->val.counter64->high << 32;
the proper implementation on 64bit system? Or how should I work with 
counter64?

The problem is, that on 64bit system the library shows sizeof(struct 
counter64) = 16 bytes, so I don't know how to work with it.

Or is there any function, that writes the value to the buffer? The 
function snprint_variable() writes more than only the number, so it's 
IMHO useless for my purpose.

Best regards, Tomas


------------------------------------------------------------------------------

_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to