📄 snmptargetaddrentry.c
字号:
/* snmpTargetAddrEntry MIB This file was generated by mib2c and is intended for use as a mib module for the ucd-snmp snmpd agent. Edited by Michael Baer last changed 2/2/99.*/#include <config.h>#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#include <stdlib.h>#include <ctype.h>#if HAVE_WINSOCK_H#include <winsock.h>#endif#include "mibincl.h"#include "snmpTargetAddrEntry.h"#include "read_config.h"#include "callback.h"#define snmpTargetAddrOIDLen 11 /*This is base+column, i.e. everything but index*/oid snmpTargetAddrOID[snmpTargetAddrOIDLen] = {1,3,6,1,6,3,15,1,2,1,0};static struct targetAddrTable_struct *aAddrTable=0;/* Utility routines *//* TargetAddrTable_create creates and returns a pointer to a targetAddrTable_struct with default values set */struct targetAddrTable_struct *snmpTargetAddrTable_create(void){ struct targetAddrTable_struct *newEntry; newEntry = (struct targetAddrTable_struct *) malloc(sizeof(struct targetAddrTable_struct)); if (newEntry) { newEntry->name = 0; newEntry->tDomainLen = 0; newEntry->tAddress = 0; newEntry->timeout = 1500; newEntry->retryCount = 3; newEntry->tagList = strdup(""); newEntry->params = 0; newEntry->spinLock = 0; newEntry->storageType = SNMP_STORAGE_NONVOLATILE; newEntry->rowStatus = SNMP_ROW_NONEXISTENT; newEntry->next = 0; } return newEntry;} /* snmpTargetAddrTable_create *//* TargetAddrTable_dispose frees the space allocated to a targetAddrTable_struct */void snmpTargetAddrTable_dispose(struct targetAddrTable_struct *reaped){ free(reaped->name); free(reaped->tAddress); free(reaped->tagList); free(reaped->params); free(reaped);} /* snmpTargetAddrTable_dispose *//* snmpTargetAddrTable_addToList adds a targetAddrTable_struct to a list passed in. The list is assumed to be in a sorted order, low to high and this procedure inserts a new struct in the proper location. Sorting uses OID values based on name. A new equal value overwrites a current one. */void snmpTargetAddrTable_addToList( struct targetAddrTable_struct *newEntry, struct targetAddrTable_struct **listPtr){ static struct targetAddrTable_struct *curr_struct, *prev_struct; int i; size_t newOIDLen = 0, currOIDLen = 0; oid newOID[128], currOID[128]; /* if the list is empty, add the new entry to the top */ if ( (prev_struct = curr_struct = *listPtr) == 0 ) { *listPtr = newEntry; return; } else { /* get the 'OID' value of the new entry */ newOIDLen = strlen(newEntry->name); for(i=0; i < (int)newOIDLen ;i++) { newOID[i] = newEntry->name[i]; } /* search through the list for an equal or greater OID value */ while (curr_struct != 0) { currOIDLen = strlen(curr_struct->name); for(i=0; i < (int)currOIDLen ;i++) { currOID[i] = curr_struct->name[i]; } i=snmp_oid_compare(newOID, newOIDLen, currOID, currOIDLen); if (i==0) { /* Exact match, overwrite with new struct */ newEntry->next = curr_struct->next; /* if curr_struct is the top of the list */ if (*listPtr == curr_struct) *listPtr = newEntry; else prev_struct->next = newEntry; snmpTargetAddrTable_dispose(curr_struct); return; } else if (i < 0) { /* Found a greater OID, insert struct in front of it.*/ newEntry->next = curr_struct; /* if curr_struct is the top of the list */ if (*listPtr == curr_struct) *listPtr = newEntry; else prev_struct->next = newEntry; return; } prev_struct = curr_struct; curr_struct = curr_struct->next; } } /* if we're here, no larger OID was ever found, insert on end of list */ prev_struct->next = newEntry;} /* snmpTargeAddrTable_addToList *//* snmpTargetAddrTable_remFromList removes a targetAddrTable_struct from the list passed in */void snmpTargetAddrTable_remFromList( struct targetAddrTable_struct *oldEntry, struct targetAddrTable_struct **listPtr){ struct targetAddrTable_struct *tptr; if ( (tptr = *listPtr) == 0 ) return; else if (tptr == oldEntry) { *listPtr = (*listPtr)->next; snmpTargetAddrTable_dispose(tptr); return; } else { while (tptr->next != 0) { if (tptr->next == oldEntry) { tptr->next = tptr->next->next; snmpTargetAddrTable_dispose(oldEntry); return; } tptr = tptr->next; } } } /* snmpTargetAddrTable_remFromList *//* lookup OID in the link list of Addr Table Entries */struct targetAddrTable_struct *search_snmpTargetAddrTable( oid *baseName, size_t baseNameLen, oid *name, size_t *length, int exact){ static struct targetAddrTable_struct *temp_struct; int i; size_t myOIDLen = 0; oid newNum[128]; /* lookup entry in addrTable linked list, Get Current MIB ID */ memcpy(newNum, baseName, baseNameLen*sizeof(oid)); for( temp_struct = aAddrTable; temp_struct != 0; temp_struct = temp_struct->next) { for(i=0; i < (int)strlen(temp_struct->name) ;i++) { newNum[baseNameLen+i] = temp_struct->name[i]; } myOIDLen = baseNameLen+strlen(temp_struct->name); i=snmp_oid_compare(name, *length, newNum, myOIDLen); /* Assumes that the linked list sorted by OID, low to high */ if ( (i==0 && exact!=0) || (i<0 && exact==0) ) { if (exact == 0) { memcpy(name, newNum, myOIDLen*sizeof(oid)); *length = myOIDLen; } return temp_struct; } } return(0);} /* search_snmpTargetAddrTable *//* snmpTargetAddr_rowStatusCheck is boolean funciton that checks the status of a row's values in order to determine whether the row should be notReady or notInService */int snmpTargetAddr_rowStatusCheck(struct targetAddrTable_struct *entry){ if ( (entry->tDomainLen == 0) || (entry->tAddress == 0) || (entry->params == 0) ) return 0; else return 1;} /* snmtpTargetAddrTable_rowStatusCheck *//* Init routines *//* this variable defines function callbacks and type return information for the snmpTargetAddrEntry mib */struct variable2 snmpTargetAddrEntry_variables[] = { { SNMPTARGETADDRTDOMAIN, ASN_OBJECT_ID , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRTDOMAINCOLUMN } }, { SNMPTARGETADDRTADDRESS, ASN_OCTET_STR , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRTADDRESSCOLUMN } }, { SNMPTARGETADDRTIMEOUT, ASN_INTEGER , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRTIMEOUTCOLUMN } }, { SNMPTARGETADDRRETRYCOUNT, ASN_INTEGER , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRRETRYCOUNTCOLUMN } }, { SNMPTARGETADDRTAGLIST, ASN_OCTET_STR , RWRITE, var_snmpTargetAddrEntry, 1, {SNMPTARGETADDRTAGLISTCOLUMN } }, { SNMPTARGETADDRPARAMS, ASN_OCTET_STR , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRPARAMSCOLUMN } }, { SNMPTARGETADDRSTORAGETYPE, ASN_INTEGER , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRSTORAGETYPECOLUMN } }, { SNMPTARGETADDRROWSTATUS, ASN_INTEGER , RWRITE, var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRROWSTATUSCOLUMN } },};/* now load this mib into the agents mib table */oid snmpTargetAddrEntry_variables_oid[] = { 1,3,6,1,6,3,12,1,2,1 };void init_snmpTargetAddrEntry(void) { aAddrTable = 0; DEBUGMSGTL(("snmpTargetAddrEntry","init\n")); REGISTER_MIB("target/snmpTargetAddrEntry", snmpTargetAddrEntry_variables, variable2, snmpTargetAddrEntry_variables_oid); snmpd_register_config_handler("targetAddr", snmpd_parse_config_targetAddr, 0, ""); /* we need to be called back later */ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, store_snmpTargetAddrEntry, NULL);} /* init_snmpTargetAddrEntry */int snmpTargetAddr_addName( struct targetAddrTable_struct *entry, char *cptr){ size_t len; if (cptr == 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no name in config string\n")); return(0); } else { len = strlen(cptr); /* spec check for string 1-32 */ if (len < 1 || len > 32) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: name out of range in config string\n")); return(0); } entry->name = (char *)malloc(len + 1); strncpy(entry->name, cptr, len); entry->name[len] = '\0'; } return(1);} /* addName */ int snmpTargetAddr_addTDomain( struct targetAddrTable_struct *entry, char *cptr){ size_t len=128; if (cptr == 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no tDomain in config string\n")); return(0); } if ( !read_objid(cptr, entry->tDomain, &len) ) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: tDomain unreadable in config string\n")); return(0); } /* spec check for oid 1-128 */ if (len < 1 || len > 128) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: tDomain out of range in config string\n")); return(0); } entry->tDomainLen = len; return(1);} /* snmpTargetAddr_addTDomain */int snmpTargetAddr_addTAddress( struct targetAddrTable_struct *entry, char *cptr){ size_t len; if (cptr == 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no tAddress in config string\n")); return(0); } else { len = strlen(cptr); /* spec check for string 1-32 */ /* if (len < 1 || len > 32) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: name out of range in config string\n")); return(0); } */ free(entry->tAddress); entry->tAddress = (char *)malloc(len + 1); strncpy(entry->tAddress, cptr, len); entry->tAddress[len] = '\0'; } return(1);} /* snmpTargetAddr_addTAddress */ int snmpTargetAddr_addTimeout( struct targetAddrTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetParamsEntry: no Timeout in config string\n")); return(0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Timeout is not a digit in config string\n")); return(0); } /* check Timeout >= 0 */ else if ( (entry->timeout = (int)strtol(cptr, (char **)NULL, 0)) < 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Timeout out of range in config string\n")); return(0); } return(1);} /* snmpTargetAddr_addTimeout */ int snmpTargetAddr_addRetryCount( struct targetAddrTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetParamsEntry: no Retry Count in config string\n")); return(0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Retry Count is not a digit in config string\n")); return(0); } /* spec check 0..255 */ else { entry->retryCount = (int)strtol(cptr, (char **)NULL, 0); if ( (entry->retryCount < 0) || (entry->retryCount > 255) ) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Retry Count is out of range in config string\n")); return(0); } } return(1);} /* snmpTargetAddr_addRetryCount */ int snmpTargetAddr_addTagList( struct targetAddrTable_struct *entry, char *cptr){ size_t len; if (cptr == 0) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no tag list in config string\n")); return(0); } else { len = strlen(cptr); /* spec check for string 0-255 */ if (len < 0 || len > 255) { DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: tag list out of range in config string\n")); return(0); } free(entry->tagList); entry->tagList = (char *)malloc(len + 1); strncpy(entry->tagList, cptr, len); entry->tagList[len] = '\0'; } return(1);} /* snmpTargetAddr_addTagList */ int snmpTargetAddr_addParams( struct targetAddrTable_struct *entry, char *cptr){ size_t len;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -