NET-SNMP 服务端添加自定义节点编译生成.c 和.h 文件后,只是一个 mib 节点文件模板。1 代码修改:blue.h/* * Note: this file originally auto-generated by mib2c using * : mib2c.old-api.conf 14476 2024-04-18 17:36:51Z hardaker $ */#ifndef BLUE_H#define BLUE_H/* * function declarations */void init_blue(void);FindVarMethod var_blue;WriteMethod write_bluenum;#endif /* BLUE_H */我们会发现生成的 C 文件,其实只是一个模版。其中功能实现的地方,以与某些关键地方都留了空,并且有较为详细的英文注释。只需要修改两处即可通过编译,其余部分可根据情况决定是否修改,以与如何修改。blue.c/* * Note: this file originally auto-generated by mib2c using * : mib2c.old-api.conf 14476 2024-04-18 17:36:51Z hardaker $ */#include #include #include #include "blue.h"/* * blue_variables_oid: * this is the top level oid that we want to register under. This * is essentially a prefix, with the suffix appearing in the * variable below. */oid blue_variables_oid[] = { 1, 3, 6, 1, 4, 1, 1, 1 };/* * variable4 blue_variables: * this variable defines function callbacks and type return information * for the blue mib section */struct variable7 blue_variables[] = { /* * magic number , variable type , ro/rw , callback fn , L, oidsuffix */#define BLUENUM1 {BLUENUM, ASN_INTEGER, RWRITE, var_blue, 1, {4}},};/* * (L = length of the oidsuffix) *//** Initializes the blue module */voidinit_blue(void){ DEBUGMSGTL(("blue", "Initializing\n")); /* * register ourselves with the agent to handle our mib tree */ REGISTER_MIB("blue", blue_variables, variable4, blue_variables_oid); /* * place any other initialization junk you need here */}/* * var_blue(): * This function is called every time the agent gets a request for * a scalar ...