成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

教你如何在ucd-snmp中定義MIB

網(wǎng)絡(luò) 網(wǎng)絡(luò)管理
文章摘要:mib2c是ucd-snmp 4.2加入的工具。那么就可以在ucd-snmp中進(jìn)行MIB的編寫了。那么具體的代碼,我們?cè)谖闹幸呀?jīng)為大家詳細(xì)寫好了。

我們知道在SNMP協(xié)議中具有MIB模塊,這個(gè)模塊的功能是進(jìn)行性管理的。那么在mib2c工具中如何進(jìn)行MIB的寫入呢?今天我們就來(lái)簡(jiǎn)單介紹一下。mib2c是ucd-snmp 4.2新加入的由perl語(yǔ)言編寫的工具程序. 該工具程序需要SNMP perl擴(kuò)展模塊支持. 首先, 將上面的MIB定義文件拷貝到目錄/usr/local/share/snmp/mibs下. 然后, 以如下命令運(yùn)行mib2c工具:

/usr/local/bin/mib2c ustScalarSet

mib2c在當(dāng)前目錄下生成兩個(gè)文件: ustScalarSet.h 和ustScalarSet.c. 文件如下.

ustScalarSet.h :

1) /* This file was generated by mib2c and is intended for use as a mib module
for the ucd-snmp snmpd agent. */

2) #ifndef _MIBGROUP_USTSCALARSET_H
3) #define _MIBGROUP_USTSCALARSET_H

4) /* we may use header_generic and header_simple_table from the util_funcs module */
5) config_require(util_funcs)

6) /* function prototypes */
7) void init_ustScalarSet(void);
8) FindVarMethod var_ustScalarSet;
9) WriteMethod write_ustSSSimpleString;

10) #endif /* _MIBGROUP_USTSCALARSET_H */

ustScalarSet.c :

1) /* Most of this file was generated by the mib2c perl script. */

2) #ifdef IN_UCD_SNMP_SOURCE
3) /* If we're compiling this file inside the ucd-snmp source tree */
4) /* This should always be included first before anything else */
5) #include <config.h>;

6) /* minimal include directives */
7) #include "mibincl.h"
8) #include "util_funcs.h"

9) #else /* !IN_UCD_SNMP_SOURCE */

10) #include <ucd-snmp/ucd-snmp-config.h>;
11) #include <ucd-snmp/ucd-snmp-includes.h>;
12) #include <ucd-snmp/ucd-snmp-agent-includes.h>;

13) #endif /* !IN_UCD_SNMP_SOURCE */

14) #if HAVE_STRING_H
15) #include <string.h>;
16) #else
17) #include <strings.h>;
18) #endif

19) #include "ustScalarSet.h"

20) /*
21) ustScalarSet_variables_oid:
22) this is the top level oid that we want to register under. This
23) is essentially a prefix, with the suffix appearing in the
24) variable below.
25) */

26) static oid ustScalarSet_variables_oid[] =
27) { 1,3,6,1,4,1,2021,13,4242,1,1 };

28) /*
29) Global variables to store data we're interesting in serving:
30) */
31) static char *ustSSSimpleString;
32) static size_t ustSSSimpleString_len;
33) static time_t lastChanged=0;

34) /*
35) variable2 ustScalarSet_variables:
36) this variable defines function callbacks and type return information
37) for the ustScalarSet mib section
38) */

39) struct variable2 ustScalarSet_variables[] = {
40) #define USTSSSIMPLESTRING 1
41) { USTSSSIMPLESTRING , ASN_OCTET_STR , RWRITE, var_ustScalarSet, 1, { 1 } },
42) #define USTSSSECONDSSINCECHANGED 2
43) { USTSSSECONDSSINCECHANGED, ASN_TIMETICKS , RONLY , var_ustScalarSet, 1, { 2 } },

44) };
45) /* (L = length of the oidsuffix) */

46) /* deinit call for supporting dynamic shared object loading/unloading */
47) void deinit_ustScalarSet(void) {
48) DEBUGMSGTL(("ustScalarSet","unloading\n"));
49) unregister_mib(ustScalarSet_variables_oid,
50) sizeof(ustScalarSet_variables_oid)/sizeof(oid));
51) }

52) /*
53) init_ustScalarSet():
54) Initialization routine. This is called when the agent starts up.
55) At a minimum, registration of your variables should take place here.
56) */
57) void init_ustScalarSet(void) {
58) DEBUGMSGTL(("ustScalarSet","initializing\n"));

59) /* register ourselves with the agent to handle our mib tree */
60) REGISTER_MIB("ustScalarSet", ustScalarSet_variables, variable2,
61) ustScalarSet_variables_oid);

62) /* place any other initialization junk you need here */
63) ustSSSimpleString = strdup("Hello World");
64) ustSSSimpleString_len = strlen(ustSSSimpleString);
65) lastChanged = time(NULL);
66) }

67) /*
68) var_ustScalarSet():
69) This function is called every time the agent gets a request for
70) a scalar variable that might be found within your mib section
71) registered above. It is up to you to do the right thing and
72) return the correct value.
73) You should also correct the value of "var_len" if necessary.
74) *
75) Please see the documentation for more information about writing
76) module extensions, and check out the examples in the examples
77) and mibII directories.
78) */

#p#

79) unsigned char *
80) var_ustScalarSet(struct variable *vp,
81) oid *name,
82) size_t *length,
83) int exact,
84) size_t *var_len,
85) WriteMethod **write_method)
86) {
87) /* variables we may use later */
88) static long long_ret;

89) if (header_generic(vp,name,length,exact,var_len,write_method)
90) == MATCH_FAILED )
91) return NULL;

92) /*
93) this is where we do the value assignments for the mib results.
94) */
95) switch(vp->;magic) {
96) case USTSSSIMPLESTRING:
97) *write_method = write_ustSSSimpleString;
98) *var_len = ustSSSimpleString_len;
99) return (unsigned char *) ustSSSimpleString;

100) case USTSSSECONDSSINCECHANGED:
101) /* TimeTicks are seconds*100 */
102) long_ret = (time(NULL) - lastChanged)*100;
103) *var_len = sizeof(long_ret);
104) return (unsigned char *) &long_ret;

105) default:
106) ERROR_MSG("");
107) }
108) return NULL;
109) }

110) int
111) write_ustSSSimpleString(int action,
112) u_char *var_val,
113) u_char var_val_type,
114) size_t var_val_len,
115) u_char *statP,
116) oid *name,
117) size_t name_len)
118) {
119) static unsigned char *new_string = 0, *old_string = 0;
120) static size_t size, old_size;

121) /* this long complex series of "action"s is to preserve proper
122) transaction handling with other transactions in the same set
123) request. */

124) switch ( action ) {
125) case RESERVE1:
126) /* check to see that everything is possible */
127) if (var_val_type != ASN_OCTET_STR){
128) fprintf(stderr,
129) "write to ustSSSimpleString not ASN_OCTET_STR\n");
130) return SNMP_ERR_WRONGTYPE;
131) }
132) break;

133) case RESERVE2:
134) /* allocate memory needed here. */
135) size = var_val_len;
136) new_string = (char *) malloc(size+1);
137) if (new_string == NULL) {
138) return SNMP_ERR_GENERR; /* malloc failed! */
139) }
140) break;

141) case ACTION:
142) /* Actually make the change requested. Note that
143) anything done here must be reversable in the UNDO case */
144) if (new_string) {
145) old_string = ustSSSimpleString;
146) old_size = ustSSSimpleString_len;
147) memcpy(new_string, var_val, var_val_len);
148) new_string[var_val_len] = 0;
149) ustSSSimpleString = new_string;
150) ustSSSimpleString_len = size;
151) new_string = NULL;
152) } else {
153) /* something seriously wrong if we got here */
154) return SNMP_ERR_GENERR;
155) }
156) break;

157) case UNDO:
158) /* Back out any changes made in the ACTION case */
159) if (old_string == NULL) {
160) return SNMP_ERR_UNDOFAILED;
161) }
162) if (ustSSSimpleString)
163) free(ustSSSimpleString);
164) ustSSSimpleString = old_string;
165) ustSSSimpleString_len = old_size;
166) break;

167) case COMMIT:
168) /* Things are working well, so it's now safe to make the change
169) permanently. Make sure that anything done here can't fail! */
170) lastChanged = time(NULL);
171) break;

172) /* Treat the rest the same as FREE */
173) case FREE:
174) // break;
175) /* Release any resources that have been allocated */
176) if (new_s tring) {
177) free(new_string);
178) new_string = NULL;
179) }
180) if (old_string) {
181) free(old_string);
182) old_string = NULL;
183) }
184) break;

185) }
186) return SNMP_ERR_NOERROR;
187) }

我們定義的MIB模塊是如此的簡(jiǎn)單,我們只需要在mib2c生成的代碼上作黑體標(biāo)識(shí)的修改即可.

責(zé)任編輯:佟健 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-07-01 14:53:09

SNMPMIBUCD-SNMP

2010-07-01 12:38:31

ucd-snmp

2010-07-01 13:58:50

UCD-SNMP

2010-07-05 10:16:31

ucd-snmpSNMP Agent

2010-07-05 09:37:19

ucd-snmpsnmpd擴(kuò)展

2010-06-29 13:58:17

SNMPMIB

2010-07-02 14:04:06

SNMP MIB

2010-06-30 10:31:34

SNMP MIB

2010-06-29 14:06:49

SNMP MIB

2010-07-01 14:05:43

SNMPMIB

2010-05-24 17:18:54

Linux SNMP

2010-06-29 16:29:52

SNMP協(xié)議管理

2022-04-27 08:55:01

Spring外部化配置

2009-07-28 08:39:56

Linux應(yīng)用軟件Linux應(yīng)用

2021-04-04 22:56:47

Linux循環(huán)用戶

2022-11-28 08:23:14

IDEAGradle配置

2009-09-25 11:06:38

Hibernate實(shí)例

2009-11-13 14:19:06

ADO.NET事務(wù)

2020-12-15 09:26:20

LinuxVLAN命令

2021-08-31 08:01:40

STM32DSP指令
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 日韩在线播放av | 久久久精 | 国产一区视频在线 | 欧美精品福利 | 97精品一区二区 | 国产综合久久 | 国产女人与拘做视频免费 | 亚洲精品一区中文字幕 | 综合色婷婷 | 亚洲精品日韩在线 | 久久久久成人精品免费播放动漫 | 午夜视频一区二区 | 欧美aaaa视频 | 国产精品久久国产精品99 | 中文字幕视频在线看 | 久久久久国产一区二区三区 | 国产成人综合久久 | 精品国产精品三级精品av网址 | 免费黄色的网站 | 午夜激情在线 | 精品色 | 国产成人自拍一区 | 精品一区二区三区四区视频 | 超碰在线人人 | 国产成人综合亚洲欧美94在线 | 国产精品久久国产精品 | 国产精品自产拍 | 伊人中文字幕 | 日韩精品一区二区三区 | 亚洲精品一区中文字幕 | 日韩一二区 | av片免费 | 国产精品视频久久久久 | 91精品国产色综合久久不卡98 | 精品国产欧美一区二区 | www国产成人免费观看视频 | 成人久久 | 免费a网站 | 岛国一区| 成年人在线观看视频 | av黄色免费 |