Re:Re: why ucd-snmp agent can only be get, can't be set always
ye_cl <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <1857302532.163491187842284550.JavaMail.coremail@bj163app97.163.com> |
Hi,Dave, I use ./snmpd& to run the agent in mine target board, use "snmpget -v2c -c public 200.162.162.190 .1.3.6.1.4.1.19176.1.1.20.3.0.0" to get,and use "snmpset -v2c -c private 200.162.162.190 .1.3.6.1.4.1.19176.1.1.20.3.0.0 i 333" to set. I find there is always no response UDP packet sent from the agent,and the uClinux on target board will lose some memory every time I do set operation.
my 'my_mib.c' looks like, I only set DESTPORT: #include <config.h>#if TIME_WITH_SYS_TIME
# ifdef WIN32
# include <sys/timeb.h>
# else
# include <sys/time.h>
# endif
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif#if HAVE_WINSOCK_H
#include <winsock.h>
#endif#include "mibincl.h"
#include "snmpv3.h"
#include "snmpusm.h"
#include "agent_read_config.h"
#include "util_funcs.h"
#include "my_mib.h"static unsigned long dest_port = 3020;struct variable7 my_mib_variables[] = {
/* magic number , variable type , ro/rw , callback fn , L, oidsuffix */
#define TSOVERIPSTATUS 1
{ TSOVERIPSTATUS , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,1,0 } },
#define DESTIPADDR 2
{ DESTIPADDR , ASN_OCTET_STR , RWRITE, var_my_mib, 5, { 1,1,20,2,0 } },
#define DESTPORT 3
{ DESTPORT , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,3,0 } },
#define RESET 4
{ RESET , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,4,0 } },
#define DEVICESTATUS 5
{ DEVICESTATUS , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,5,0 } },
#define SYSTEMBITRATE 6
{ SYSTEMBITRATE , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,6,0 } },
#define EFFECTIVEBITRATE 7
{ EFFECTIVEBITRATE , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,7,0 } },
#define UDPUARTPORT 8
{ UDPUARTPORT , ASN_INTEGER , RWRITE, var_my_mib, 5, { 1,1,20,8,0 } },
#define DESCRIPTION 9
{ DESCRIPTION , ASN_OCTET_STR , RONLY , var_my_mib, 2, { 2,1 } },
#define LOCATED 10
{ LOCATED , ASN_OCTET_STR , RONLY , var_my_mib, 2, { 2,2 } },};/* Define the OID pointer to the top of the mib tree that we're
registering underneath */
oid my_mib_variables_oid[] = { 1,3,6,1,4,1,19176 };//void init_ucdDemoPublic(void) {
void init_my_mib(void) {
REGISTER_MIB("my_mib", my_mib_variables, variable7,
my_mib_variables_oid);
}unsigned char *
var_my_mib(struct variable *vp,
oid *name,
size_t *length,
int exact,
size_t *var_len,
WriteMethod **write_method)
{
/* variables we may use later */
static long long_ret;
static u_long ulong_ret;
static unsigned char string[SPRINT_MAX_LEN];
static oid objid[MAX_OID_LEN];
static struct counter64 c64;
if (header_generic(vp,name,length,exact,var_len,write_method)
== MATCH_FAILED )
return NULL;
/*
* this is where we do the value assignments for the mib results.
*/
switch(vp->magic) {
case TSOVERIPSTATUS:
*write_method = write_tsoveripstatus;
long_ret = 0;
return (unsigned char *) &long_ret; case DESTIPADDR:
*write_method = write_destipaddr;
*string = 0;
*var_len = strlen(string);
return (unsigned char *) string; case DESTPORT:
*write_method = write_destport;
return (u_char *) & dest_port; case RESET:
*write_method = write_reset;
long_ret = 0;
return (unsigned char *) &long_ret; case DEVICESTATUS:
*write_method = write_devicestatus;
long_ret = 0;
return (unsigned char *) &long_ret; case SYSTEMBITRATE:
*write_method = write_systembitrate;
long_ret = 0;
return (unsigned char *) &long_ret; case EFFECTIVEBITRATE:
*write_method = write_effectivebitrate;
long_ret = 0;
return (unsigned char *) &long_ret; case UDPUARTPORT:
*write_method = write_udpuartport;
long_ret = 0;
return (unsigned char *) &long_ret; case DESCRIPTION:
*string = 0;
*var_len = strlen(string);
return (unsigned char *) string; case LOCATED:
*string = 0;
*var_len = strlen(string);
return (unsigned char *) string;
default:
ERROR_MSG("");
}
return NULL;
}
int
write_destport(int action,
u_char *var_val,
u_char var_val_type,
size_t var_val_len,
u_char *statP,
oid *name,
size_t name_len)
{
static long *long_ret;
int size; switch ( action ) {
case RESERVE1:
if (var_val_type != ASN_INTEGER){
fprintf(stderr, "write to destport not ASN_INTEGER\n");
return SNMP_ERR_WRONGTYPE;
}
if (var_val_len > sizeof(long_ret)){
fprintf(stderr,"write to destport: bad length\n");
return SNMP_ERR_WRONGLENGTH;
}
if (var_val < 0) {
fprintf(stderr, "write to destport: bad value\n");
return SNMP_ERR_WRONGVALUE;
}
break;
case RESERVE2:
size = var_val_len;
long_ret = (long *) var_val;
break;
case FREE:
// Release any resources that have been allocated
break;
case ACTION:
// The variable has been stored in long_ret for
//you to use, and you have just been asked to do something with
//it. Note that anything done here must be reversable in the UNDO case
break;
case UNDO:
// Back out any changes made in the ACTION case
break;
case COMMIT:
// Things are working well, so it's now safe to make the change
// permanently. Make sure that anything done here can't fail!
dest_port = (unsigned long)*long_ret;
break;
}
return SNMP_ERR_NOERROR;
}....../*..And other write functions......*/
......
在2007-08-22,"Dave Shield" <[email protected]> 写道:
On 22/08/07, ye_cl <[email protected]> wrote: > I have a question about using ucd-snmp-4.1.2 on uClinux. That's a *VERY* old version of the code, and is no longer being maintained. That shouldn't affect your particular problem, but you should strongly consider upgrading to a more recent version. > When my snmpd is running on uClinux, I can only do get operation, > there is always the response of "request timed out" for set. What is the command that you are running? What does your file 'my_mib.c' look like? Dave ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ 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
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
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