Correct the code for SNMPSET/SNMPGET of IPADDRESS datatype
"Raghavendra Prasad" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Dear all,
Below I am attaching a piece of code for handling GET and SET
requests for a node variable "cdsprVpnConcentrator1IpAddress".
Although this piece of code works, I am not confident that it is a
perfect code. I request you to kindly have look and suggest changes,
modification or point out blunders/mistakes if any?
/*Handler function definitions*/
int
handle_cdsprVpnConcentrator1IpAddress(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb, ASN_IPADDRESS,
(u_char
*)&(cdsprVpnConcentrator1IpAddress),
sizeof(cdsprVpnConcentrator1IpAddress));
break;
/*
* SET REQUEST
* multiple states in the transaction.
*/
case MODE_SET_RESERVE1:
/* Check node variable type and size */
ret = netsnmp_check_vb_type_and_size(requests->requestvb,
ASN_IPADDRESS, requests->requestvb->val_len);
/* Found error related to variable type and size? */
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_request_set_error(requests, ret);
}
break;
case MODE_SET_RESERVE2:
/* Create storage buffer to "UNDO" SET operation if required later */
temp_cdsprVpnConcentrator1IpAddress =
cdsprVpnConcentrator1IpAddress;
/*Failed store backup value for undo purpose in Buffer? */
if ( &(temp_cdsprVpnConcentrator1IpAddress) == NULL)
{
netsnmp_request_set_error(requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
break;
case MODE_SET_FREE:
/* Free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
free( &(temp_cdsprVpnConcentrator1IpAddress) );
free( &(cdsprVpnConcentrator1IpAddress) );
break;
case MODE_SET_ACTION:
/*Finally SET the new value*/
/*Failed in SET new value?*/
cdsprVpnConcentrator1IpAddress = *(requests->requestvb->val.integer);
if ( &(cdsprVpnConcentrator1IpAddress) == NULL)
{
netsnmp_request_set_error(requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
break;
case MODE_SET_COMMIT:
break;
case MODE_SET_UNDO:
/*Integer based ASN.1 type*/
cdsprVpnConcentrator1IpAddress =
temp_cdsprVpnConcentrator1IpAddress;
/*Failed to UNDO?*/
if (&(temp_cdsprVpnConcentrator1IpAddress) == NULL)
{
netsnmp_request_set_error(requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
break;
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in
handle_cdsprVpnConcentrator1IpAddress\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users