Hi,
i made some template code using mib2c filled the blanks and modified
NET-SNMP-EXAMPLES-MIB like this:
netSnmpExampleString OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"This is a simple object which merely houses a writable
String. It's only purposes is to hold the value of a single
String. Writing to it will simply change the value for
subsequent GET/GETNEXT/GETBULK retrievals.
"
DEFVAL { hallo }
::= { netSnmpExampleScalars 1 }
this is my sample code netSnmpExampleString.c
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf,v 1.8 2004/10/14 12:57:34 dts12 Exp $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "netSnmpExampleString.h"
#define BUF_LEN 51
/** Initializes the netSnmpExampleString module */
static char netSnmpExampleString[BUF_LEN];
char *tmp_ptr;
void init_control_vars(void)
{
strcpy(netSnmpExampleString, "hallo");
}
void
init_netSnmpExampleString(void)
{
static oid netSnmpExampleString_oid[] = { 1,3,6,1,4,1,8072,2,1,1 };
DEBUGMSGTL(("netSnmpExampleString", "Initializing\n"));
init_control_vars();
netsnmp_register_scalar(
netsnmp_create_handler_registration("netSnmpExampleString",
handle_netSnmpExampleString,
netSnmpExampleString_oid, OID_LENGTH(netSnmpExampleString_oid),
HANDLER_CAN_RWRITE
));
}
int
handle_netSnmpExampleString(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
/* a instance handler also only hands us one request at a time, so
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
(u_char *)netSnmpExampleString,strlen(netSnmpExampleString));
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
tmp_ptr = NULL;
if (requests->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
return SNMP_ERR_WRONGTYPE;
if (requests->requestvb->val.integer < 0 ) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);
return SNMP_ERR_WRONGVALUE;
}
break;
case MODE_SET_RESERVE2:
tmp_ptr = (char *)malloc(requests->requestvb->val_len + 1);
if (tmp_ptr == NULL)
{
printf("SNMP_ERR_RESOURCEUNAVAILABLE!\n");
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
return (SNMP_ERR_RESOURCEUNAVAILABLE);
}
printf("memory alloced!\n");
break;
case MODE_SET_FREE:
if (tmp_ptr)
{
free(tmp_ptr);
printf("memory freed!\n");
}
break;
case MODE_SET_ACTION:
if (tmp_ptr == NULL)
{
printf("SNMP_ERR_RESOURCEUNAVAILABLE!\n");
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
return (SNMP_ERR_RESOURCEUNAVAILABLE);
}
memset(tmp_ptr, 0, BUF_LEN);
strncpy(tmp_ptr, (char *)requests->requestvb->val.integer, (BUF_LEN-1));
break;
case MODE_SET_COMMIT:
if (sizeof(tmp_ptr) >= BUF_LEN)
{
printf("SNMP_ERR_COMMITFAILED!\n");
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
return (SNMP_ERR_COMMITFAILED);
}
strcpy(netSnmpExampleString, tmp_ptr);
free(tmp_ptr);
printf("memory freed in commit!\n");
break;
case MODE_SET_UNDO:
free(tmp_ptr);
printf("memory freed in undo!\n");
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_netSnmpExampleString\n",
reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
}
i compile this code (it is in agent/mibgoup/examples) into the agent and
get always packet error messages.
snmpget -v 1 -c psi 127.0.0.1 netSnmpExampleString.0
Error in packet
Reason:(noSuchName) There is no such variable name in this MIB
Failed object: NET-SNMP-EXAMPLES-MIB::netSnmpExampleString.0
i use net-snmp 5.2.1.2 and the win32sdk.dsw in the win32 folder to compile
the package. On the VS.NET Environment screen it looks like this
-win32sdk (Projectmap)
|-+ encode_keychange (the project folders)
|-+ libagent
|-+ libhelpers
|-+ libnetsnmptrapd
|-+ libsnmp
|-+ netsnmpmibssdk (the code is in the examples folder of this project)
|-+ snmpbulkget
|-+ snmpbulkwalk
|-+ snmpdelta
|-+ snmpdf
|-+ snmpdsdk
|-+ snmpget
|-+ snmpgetnext
|-+ snmpnetstat
|-+ snmpset
|-+ snmptranslate
|-+ snmptrap
|-+ snmptrapd
|-+ snmpusm
|-+ snmpvacm
|-+ snmpwalk
i follow always follow the instructions in the win32 README to install the
compiled package
Is something wrong with the code or do i compile the code in a wrong
projectfolder?
with best regards
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
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