Problem solved.
It took me some time to figure out that requests->requestvb->val.string is not 
a string terminated by NULL. All the latest valid information is in the first 
'requests->requestvb->val.len' characters. 
Cheers!
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lin, Zihui
Sent: 2005年7月29日 23:01
To: [email protected]
Subject: Question for Handling the WRONGVALUE error

Hello list,

I'm new to net-snmp. Following the mib2c man page, I generated a pair of

souce code, and modified them a little bit.
The management object is an OCTET STRING, and the idea is, I want to
verify 
the string when people SETing the value. If a malformed IPadress was
set, 
then a WRONGVALUE error should be returned.

The handler works well when the verification success, but if it failed
for 
once, even I SET some good strings after that, it fails also. I have
tried
to put the verify code to RESERVE2, but the result is the same.
So now if my subagent detected a wrong value once, it fails for ever. :(
What's problem? What can I do in this situation?

Thanks in advance, 
Zihui

Here is the implementation code:

int
handle_observedNetworks(netsnmp_mib_handler *handler,
                        netsnmp_handler_registration *reginfo,
                        netsnmp_agent_request_info *reqinfo,
                        netsnmp_request_info *requests)

{
    DEBUGMSGTL(("observedNetworks",
                "continuing  request, mode = %d\n",
                reqinfo->mode));
    switch (reqinfo->mode) {

    /** GET is simple here */
    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                 (u_char *) observedNetworks_str,
                 strlen(observedNetworks_str));
        break;    

    case MODE_SET_RESERVE1:

        if ( requests->requestvb->type != ASN_OCTET_STR)   {

            netsnmp_set_request_error(
            reqinfo,
            requests,
            SNMP_ERR_WRONGVALUE //some error
            );
            return;
        }
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        break;

    case MODE_SET_ACTION:

        if (!verify_ip_range(requests->requestvb->val.string) ){
            netsnmp_set_request_error(reqinfo, requests,
                    SNMP_ERR_BADVALUE);
        }

     strncpy(observedNetworks_str, requests->requestvb->val.string,
256);
        break;

    case MODE_SET_COMMIT:
        break;

    case MODE_SET_UNDO:
        break;

    default:
        snmp_log(LOG_ERR, "unknown mode (%d) in
handle_observedNetworks\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to