Re: about modifying files generated by mib2c
"蔷<Qiang Hu>" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
hi,all!
Very thank you for the reply! With it ,i solved that problem! thank you Dave
and net-snmp again!
but i got another problem.after my simple test mib(jmtest) mentioned last
time,i tried another much more complex mib(m3uaMIB,it's almost a standard
mib ,so you can see it at IETF website).i did the similar modifying to the
files generated by mib2c as the simple test mib (jmtest),but it's odd that
when i snmpwalk it i got such result(why m3uaManagement became the leaf
nod?):
[root@localhost root]# snmpwalk -v 1 -c public localhost m3uaMIB
M3UA-MIB::m3uaManagement.0 = Gauge32: 200
M3UA-MIB::m3uaConformance.0 = INTEGER: 2
M3UA-MIB::m3uaMIB.3.0 = Gauge32: 2905
M3UA-MIB::m3uaMIB.4.0 = Gauge32: 123
M3UA-MIB::m3uaMIB.5.0 = Gauge32: 1
M3UA-MIB::m3uaMIB.6.0 = INTEGER: 1
M3UA-MIB::m3uaMIB.7.0 = Gauge32: 20
and i also paste my snmptranslate result and modified codes(because the mib
is so large,so i just paste part of them);i just give part of values of the
mib for test,and comment out other values ! note that this complex mib is
with both scalars and tables,and is there something particular to modify
such mib codes generated by mib2c?
+--m3uaMIB(31)
|
+--m3uaManagement(1)
| |
| +--m3uaAttributes(1)
| | |
| | +--m3uaConfig(1)
| | | |
| | | +-- -R-- Unsigned m3uaVersion(1)
| | | +-- -R-- EnumVal m3uaProcType(2)
| | | | Values: sgp(1), asp(2), ipsp(3)
| | | +-- -R-- Unsigned m3uaLocalPort(3)
| | | +-- -RW- Unsigned m3uaTrValue(4)
| | | +-- -RW- Unsigned m3uaTPaudValue(5)
| | | +-- -RW- EnumVal m3uaHeartBeat(6)
| | | | Values: on(0), off(1)
| | | +-- -RW- Unsigned m3uaTBeatValue(7)
m3uaMIB.c:
.
.
.
switch (vp->magic) {
case M3UAVERSION:
*var_len=sizeof(long);
long_ret=200;
return (u_char *) & long_ret;
case M3UAPROCTYPE:
long_ret= 2; //sgp(1)asp(2) ipsp(3)
*var_len=sizeof(long);
return (u_char *) & long_ret;
case M3UALOCALPORT:
*var_len=sizeof(long);
long_ret=2905;
return (u_char *) & long_ret;
case M3UATRVALUE:
*write_method = write_m3uaTrValue;
*var_len=sizeof(long);
long_ret=123;
return (u_char *) & long_ret;
case M3UATPAUDVALUE:
*write_method = write_m3uaTPaudValue;
//VAR = VALUE; /* XXX */
//return (u_char *) & VAR;
case M3UAHEARTBEAT:
*write_method = write_m3uaHeartBeat;
*var_len=sizeof(long);
long_ret=1;//heartbeat on(0),off(1)
return (u_char *) & long_ret;
case M3UATBEATVALUE:
*write_method = write_m3uaTBeatValue;
*var_len=sizeof(long);
long_ret=20;
return (u_char *) & long_ret;
.
.
.
at last i want to offer my question about the C code for set action
generated by mib2c,in "write_***** "function i saw that the definition of
variable"value" is just "long value;" why not "static long value"?because
if i use this variable in case ACTION,it will change since i just "value =
*(long *) var_val;" in case RESERVE2;i'm puzzle about that.why?
thanks!
On 7/26/06, Dave Shield <*****@csc.liv.ac.uk> wrote:
> On 26/07/06, <Qiang Hu> <[email protected]> wrote:
> > unsigned char *
> > var_jmtest(...)
> > {
> > static long long_ret;
> > int VAR;
>
> > switch (vp->magic) {
> > case FIRSTKEY:
> > *write_method = write_firstKey;
> > VAR = 1; /* XXX */
> > *var_len =sizeof(VAR);
> > return (u_char *) & VAR;
>
>
> Two comments.
> a) "VAR" *must* be declared as "static", if you are going to return a
> reference to it, which will then be accessed by external code. This
> is probably why you are getting different results each time.
>
> b) The old API (and probably the new one too), expects to use 'long'
> variables for integer values. Why not just use the 'long_ret'
> variable that has already been declared for you?
> It *might* not matter if you use int instead, but I wouldn't like to
> make any promises.
> I'd suggest you play safe and use 'long_ret'.
>
> Dave
>
--
Qiang
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
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