NETSNMP服务端添加自定义节点.docx

上传人:b****7 文档编号:9209274 上传时间:2023-02-03 格式:DOCX 页数:10 大小:133.52KB
下载 相关 举报
NETSNMP服务端添加自定义节点.docx_第1页
第1页 / 共10页
NETSNMP服务端添加自定义节点.docx_第2页
第2页 / 共10页
NETSNMP服务端添加自定义节点.docx_第3页
第3页 / 共10页
NETSNMP服务端添加自定义节点.docx_第4页
第4页 / 共10页
NETSNMP服务端添加自定义节点.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

NETSNMP服务端添加自定义节点.docx

《NETSNMP服务端添加自定义节点.docx》由会员分享,可在线阅读,更多相关《NETSNMP服务端添加自定义节点.docx(10页珍藏版)》请在冰豆网上搜索。

NETSNMP服务端添加自定义节点.docx

NETSNMP服务端添加自定义节点

NET-SNMP服务端添加自定义节点

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;

WriteMethodwrite_bluenum;

#endif/*BLUE_H*/

我们会发现生成的C文件,其实只是一个模版。

其中功能实现的地方,以及某些关键地方都留了空,并且有较为详细的英文注释。

只需要修改两处即可通过编译,其余部分可根据情况决定是否修改,以及如何修改。

 

blue.c

/*

*Note:

thisfileoriginallyauto-generatedbymib2cusing

*:

mib2c.old-api.conf144762006-04-1817:

36:

51Zhardaker$

*/

#include

#include

#include

#include"blue.h"

/*

*blue_variables_oid:

*thisisthetopleveloidthatwewanttoregisterunder.This

*isessentiallyaprefix,withthesuffixappearinginthe

*variablebelow.

*/

oidblue_variables_oid[]={1,3,6,1,4,1,1,1};

/*

*variable4blue_variables:

*thisvariabledefinesfunctioncallbacksandtypereturninformation

*forthebluemibsection

*/

structvariable7blue_variables[]={

/*

*magicnumber,variabletype,ro/rw,callbackfn,L,oidsuffix

*/

#defineBLUENUM1

{BLUENUM,ASN_INTEGER,RWRITE,var_blue,1,{4}},

};

/*

*(L=lengthoftheoidsuffix)

*/

 

/**Initializesthebluemodule*/

void

init_blue(void)

{

DEBUGMSGTL(("blue","Initializing\n"));

/*

*registerourselveswiththeagenttohandleourmibtree

*/

REGISTER_MIB("blue",blue_variables,variable4,blue_variables_oid);

/*

*placeanyotherinitializationjunkyouneedhere

*/

}

/*

*var_blue():

*Thisfunctioniscalledeverytimetheagentgetsarequestfor

*ascalarvariablethatmightbefoundwithinyourmibsection

*registeredabove.Itisuptoyoutodotherightthingand

*returnthecorrectvalue.

*Youshouldalsocorrectthevalueof"var_len"ifnecessary.

*

*Pleaseseethedocumentationformoreinformationaboutwriting

*moduleextensions,andcheckouttheexamplesintheexamples

*andmibIIdirectories.

*/

unsignedchar*

var_blue(structvariable*vp,

oid*name,

size_t*length,

intexact,size_t*var_len,WriteMethod**write_method)

{

/*

*variableswemayuselater

*/

staticlonglong_ret;

staticu_longulong_ret;

staticunsignedcharstring[SPRINT_MAX_LEN];

staticoidobjid[MAX_OID_LEN];

staticstructcounter64c64;

if(header_generic(vp,name,length,exact,var_len,write_method)

==MATCH_FAILED)

returnNULL;

/*

*thisiswherewedothevalueassignmentsforthemibresults.

*/

switch(vp->magic){

caseBLUENUM:

*write_method=write_bluenum;

VAR=VALUE;/*XXX*//*编译时此两处会报错。

注释此行

return(u_char*)&VAR;/*修改完毕可正常编译安装将&VAR修

default:

/*改为固定值

ERROR_MSG("");

}

returnNULL;

}

int

write_bluenum(intaction,

u_char*var_val,

u_charvar_val_type,

size_tvar_val_len,

u_char*statP,oid*name,size_tname_len)

{

longvalue;

intsize;

switch(action){

caseRESERVE1:

if(var_val_type!

=ASN_INTEGER){

fprintf(stderr,"writetobluenotASN_INTEGER\n");

returnSNMP_ERR_WRONGTYPE;

}

if(var_val_len>sizeof(long)){

fprintf(stderr,"writetoblue:

badlength\n");

returnSNMP_ERR_WRONGLENGTH;

}

break;

caseRESERVE2:

size=var_val_len;

value=*(long*)var_val;

break;

caseFREE:

/*

*Releaseanyresourcesthathavebeenallocated

*/

break;

caseACTION:

/*

*Thevariablehasbeenstoredin'value'foryoutouse,

*andyouhavejustbeenaskedtodosomethingwithit.

*NotethatanythingdoneheremustbereversableintheUNDOcase

*/

break;

caseUNDO:

/*

*BackoutanychangesmadeintheACTIONcase

*/

break;

caseCOMMIT:

/*

*Thingsareworkingwell,soit'snowsafetomakethechange

*permanently.Makesurethatanythingdoneherecan'tfail!

*/

break;

}

returnSNMP_ERR_NOERROR;

}

 

2mib的加载:

上面的

NEW-MIB

BLACK-MIB

GREEN-MIB

BLUE-MIB

NEW-MIB2

WHITE-MIB

由于都是按照SNMP概要设计_0.1.doc进行生成,因此都是在此路径下。

每次只能加载排在首位的NEW-MIB中的节点。

例如现在加载BLACK-MIB中的节点则把原来在前面的NEW-MIB

右键卸载

 

则有如下结果

mib生成的C代码模板,具体修改方法正在学习中。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 职业教育 > 中职中专

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1