欢迎来到天天文库
浏览记录
ID:58821123
大小:171.00 KB
页数:11页
时间:2020-10-25
《NET-SNMP服务端添加自定义节点.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、NET-SNMP服务端添加自定义节点编译生成.c和.h文件后,只是一个mib节点文件模板。1代码修改:blue.h/**Note:thisfileoriginallyauto-generatedbymib2cusing*:mib2c.old-api.conf144762006-04-1817:36:51Zhardaker$*/#ifndefBLUE_H#defineBLUE_H/**functiondeclarations*/voidinit_blue(void);FindVarMethodvar_blue;W
2、riteMethodwrite_bluenum;#endif/*BLUE_H*/我们会发现生成的C文件,其实只是一个模版。其中功能实现的地方,以及某些关键地方都留了空,并且有较为详细的英文注释。只需要修改两处即可通过编译,其余部分可根据情况决定是否修改,以及如何修改。blue.c/**Note:thisfileoriginallyauto-generatedbymib2cusing*:mib2c.old-api.conf144762006-04-1817:36:51Zhardaker$*/#include3、t-snmp/net-snmp-config.h>#include#include#include"blue.h"/**blue_variables_oid:*thisisthetopleveloidthatwewanttoregisterunder.This*isessentiallyaprefix,withthesuffixappearinginthe*variab4、lebelow.*/oidblue_variables_oid[]={1,3,6,1,4,1,1,1};/**variable4blue_variables:*thisvariabledefinesfunctioncallbacksandtypereturninformation*forthebluemibsection*/structvariable7blue_variables[]={/**magicnumber,variabletype,ro/rw,callbackfn,L,oidsuffix*/#def5、ineBLUENUM1{BLUENUM,ASN_INTEGER,RWRITE,var_blue,1,{4}},};/**(L=lengthoftheoidsuffix)*//**Initializesthebluemodule*/voidinit_blue(void){DEBUGMSGTL(("blue","Initializing"));/**registerourselveswiththeagenttohandleourmibtree*/REGISTER_MIB("blue",blue_variable6、s,variable4,blue_variables_oid);/**placeanyotherinitializationjunkyouneedhere*/}/**var_blue():*Thisfunctioniscalledeverytimetheagentgetsarequestfor*ascalarvariablethatmightbefoundwithinyourmibsection*registeredabove.Itisuptoyoutodotherightthingand*returnthec7、orrectvalue.*Youshouldalsocorrectthevalueof"var_len"ifnecessary.**Pleaseseethedocumentationformoreinformationaboutwriting*moduleextensions,andcheckouttheexamplesintheexamples*andmibIIdirectories.*/unsignedchar*var_blue(structvariable*vp,oid*name,size_t*lengt8、h,intexact,size_t*var_len,WriteMethod**write_method){/**variableswemayuselater*/staticlonglong_ret;staticu_longulong_ret;staticunsignedcharstring[SPRINT_MAX_LEN];staticoidobjid[MAX_OID_LEN];stat
3、t-snmp/net-snmp-config.h>#include#include#include"blue.h"/**blue_variables_oid:*thisisthetopleveloidthatwewanttoregisterunder.This*isessentiallyaprefix,withthesuffixappearinginthe*variab
4、lebelow.*/oidblue_variables_oid[]={1,3,6,1,4,1,1,1};/**variable4blue_variables:*thisvariabledefinesfunctioncallbacksandtypereturninformation*forthebluemibsection*/structvariable7blue_variables[]={/**magicnumber,variabletype,ro/rw,callbackfn,L,oidsuffix*/#def
5、ineBLUENUM1{BLUENUM,ASN_INTEGER,RWRITE,var_blue,1,{4}},};/**(L=lengthoftheoidsuffix)*//**Initializesthebluemodule*/voidinit_blue(void){DEBUGMSGTL(("blue","Initializing"));/**registerourselveswiththeagenttohandleourmibtree*/REGISTER_MIB("blue",blue_variable
6、s,variable4,blue_variables_oid);/**placeanyotherinitializationjunkyouneedhere*/}/**var_blue():*Thisfunctioniscalledeverytimetheagentgetsarequestfor*ascalarvariablethatmightbefoundwithinyourmibsection*registeredabove.Itisuptoyoutodotherightthingand*returnthec
7、orrectvalue.*Youshouldalsocorrectthevalueof"var_len"ifnecessary.**Pleaseseethedocumentationformoreinformationaboutwriting*moduleextensions,andcheckouttheexamplesintheexamples*andmibIIdirectories.*/unsignedchar*var_blue(structvariable*vp,oid*name,size_t*lengt
8、h,intexact,size_t*var_len,WriteMethod**write_method){/**variableswemayuselater*/staticlonglong_ret;staticu_longulong_ret;staticunsignedcharstring[SPRINT_MAX_LEN];staticoidobjid[MAX_OID_LEN];stat
此文档下载收益归作者所有