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

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

網絡 網絡管理
文章摘要:mib2c是ucd-snmp 4.2加入的工具。那么就可以在ucd-snmp中進行MIB的編寫了。那么具體的代碼,我們在文中已經為大家詳細寫好了。

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

/usr/local/bin/mib2c ustScalarSet

mib2c在當前目錄下生成兩個文件: 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模塊是如此的簡單,我們只需要在mib2c生成的代碼上作黑體標識的修改即可.

責任編輯:佟健 來源: 互聯網
相關推薦

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擴展

2010-06-29 13:58:17

SNMPMIB

2010-07-02 14:04:06

SNMP MIB

2010-06-30 10:31:34

SNMP MIB

2010-07-01 14:05:43

SNMPMIB

2010-06-29 14:06:49

SNMP MIB

2010-05-24 17:18:54

Linux SNMP

2010-06-29 16:29:52

SNMP協議管理

2022-04-27 08:55:01

Spring外部化配置

2009-07-28 08:39:56

Linux應用軟件Linux應用

2021-04-04 22:56:47

Linux循環用戶

2022-11-28 08:23:14

IDEAGradle配置

2009-09-25 11:06:38

Hibernate實例

2009-11-13 14:19:06

ADO.NET事務

2021-08-31 08:01:40

STM32DSP指令

2022-04-22 09:20:06

FreeBSD 13MySQL數據庫
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美lesbianxxxxhd视频社区 | 精品国产一区二区三区成人影院 | 99久久免费精品国产免费高清 | 不卡一二三区 | 欧产日产国产精品v | 欧美一级在线观看 | 欧美日韩1区 | 成年人在线观看 | 精品一区二区三区在线观看国产 | 国产二区三区 | 国产一区二区三区在线 | 久久国产精品视频 | 午夜久久久 | 中文字幕99 | 久久视频一区 | 色综合久久久久 | 国产成人精品在线播放 | 久久这里只有精品首页 | 日日噜噜噜夜夜爽爽狠狠视频, | 国产精品久久国产精品久久 | 欧美jizzhd精品欧美巨大免费 | 伊人欧美视频 | 又黄又爽的网站 | 黄色三级免费网站 | 精品蜜桃一区二区三区 | 99精品久久 | 亚洲一一在线 | 国产欧美一区二区三区日本久久久 | 亚洲精品在线免费 | 亚洲精品乱码久久久久久按摩 | 日日夜精品视频 | 九九热精品在线 | 国产免费一区 | 国产精品久久久久久久粉嫩 | 免费看黄色片 | 岛国av一区二区三区 | 国产精品美女在线观看 | 中文字幕国产一区 | 日日日日日日bbbbb视频 | 婷婷在线视频 | 久久蜜桃资源一区二区老牛 |