mib2c를 이용하여 만든 소스에서 table값을 초기화 하려고 하는데 잘 안됩니다.
글쓴이: bakdorazi / 작성시간: 목, 2010/01/21 - 4:59오후
제가 snmp테스트용으로 MIB을 만들고 그 MIB을 가지고 mib2c를 이용하여 소스를 생성하였습니다.
아래는 소스 일부입니다.
/** Initializes the exam module */
char *firstname[] = {"choi", "kim", "lee", "kang", "han"};
//일단 테이블의 entry는 아래와 같습니다. 간단하게 name, num1, num2 입니다.
struct examNEXTable_entry {
char name;
char old_name;
long num1;
long old_num1;
long num2;
long old_num2;
int valid;
struct examNEXTable_entry *next;
};
struct examNEXTable_entry *examNEXTable_head;
// create a new row in the (unsorted) table
//저는 여기를 테이블의 entry를 생성하는 함수라고 생각했습니다. 그리하여 제 나름대로의 함수값을 넣어줍니다.
struct examNEXTable_entry *examNEXTable_createEntry(char *fname, int i)
{
struct examNEXTable_entry *entry;
entry = SNMP_MALLOC_TYPEDEF(struct examNEXTable_entry);
if (!entry)
return NULL;
entry->name = *fname;
entry->num1= i;
entry->num2= i;
entry->next = examNEXTable_head;
examNEXTable_head = entry;
return entry;
}
char *getname(int i)
{
return firstname[i];
}
void firstval(void)
{
struct examNEXTable_entry *tmpentry;
char *fname;
int i;
for(i=0; i < 5; i++) {
fname = getname(i);
tmpentry = examNEXTable_createEntry(fname, i);
tmpentry->valid=1;
}
}
void initialize_table_examNEXTable(void)
{
static oid examNEXTable_oid[] = { 1, 3, 6, 1, 4, 1, 50000, 3 };
size_t examNEXTable_oid_len = OID_LENGTH(examNEXTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
reg = netsnmp_create_handler_registration("examNEXTable",
examNEXTable_handler,
examNEXTable_oid,
examNEXTable_oid_len,
HANDLER_CAN_RWRITE);
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
netsnmp_table_helper_add_indexes(table_info, 0);
table_info->min_column = COLUMN_NAME;
table_info->max_column = COLUMN_NUM2;
iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
iinfo->get_first_data_point = examNEXTable_get_first_data_point;
iinfo->get_next_data_point = examNEXTable_get_next_data_point;
iinfo->table_reginfo = table_info;
netsnmp_register_table_iterator(reg, iinfo);
// Initialise the contents of the table herete a new row in the (unsorted) table
// 여기에 테이블을 초기화 하여 생성하는 함수를 넣어주었습니다.
firstval();
}
//여기는 net-snmp가 get/set 등의 명령에 대하여 값을 넘겨주는 부분입니다.
int examNEXTable_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
struct examNEXTable_entry *table_entry;
int len;
char strval[128];
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
//GET 명령이 왔을때 처리해 주는 부분입니다.
case MODE_GET:
for (request = requests; request; request = request->next) {
table_entry = (struct examNEXTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_NAME:
sprintf(strval, "a");
len = strlen((char*)strval);
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
//아래의 함수가 GET요청이 들어왔을때 값을 전달해 주는 부분입니다.
<span>snmp_set_var_typed_value</span>(request->requestvb, ASN_OCTET_STR,
(u_char *)table_entry->name, sizeof(table_entry->name));
break;
case COLUMN_NUM1:
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
(u_char*)&table_entry->num1 , sizeof(table_entry->num1));
break;저는 대충 소스를 위와 같이 하였습니다.
위의 소스를 컴파일 하였을때 아래와 같은 경고가 뜹니다.
단순히 하나의 경고 이므로 실행파일은 무사히 만들어 졌습니다.
[root@localhost Test]# net-snmp-config --compile-subagent nex exam.c generating the tmporary code file: netsnmptmp.3961.c void init_exam(void); checking for init_exam in exam.c init_exam(void) running: gcc -g -O2 -Dlinux -I/usr/include/rpm -I. -I/usr/local/include -o nex netsnmptmp.3961.c exam.c -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lrpm -lrpmio -lpopt -lz -lcrypto -lm exam.c: In function ‘examNEXTable_handler’: exam.c:241: warning: cast to pointer from integer of different size removing the tmporary code file: netsnmptmp.3961.c subagent program nex created
그러나 그 실행파일을 실행해 보면 실제로 리턴되는 값이 없습니다.
[root@localhost Test]# ./nex & [1] 3985 [root@localhost Test]# NET-SNMP version 5.3.3 AgentX subagent connected [root@localhost Test]# snmpwalk -v 1 -c public localhost exam improperly registered table found name: table, table info: 0x828ee88, indexes: (nil) improperly registered table found name: table, table info: 0x828ee88, indexes: (nil) Error in packet. Reason: (genError) A general failure occured <span>Failed object: NEXCOMM-EXAM-MIB::exam</span>
소스를 가만히 뜯어 보아도 잘 몰라서 여기다 올립니다.
월요일까지 해야 하는 일입니다.
좀 도와주세요.
Forums:


댓글 달기