⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pass.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <net-snmp/net-snmp-config.h>#if HAVE_STDLIB_H#include <stdlib.h>#endif#include <stdio.h>#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#include <ctype.h>#include <sys/types.h>#if HAVE_NETINET_IN_H#include <netinet/in.h>#endif#if HAVE_SYS_WAIT_H# include <sys/wait.h>#endif#if HAVE_WINSOCK_H#include <winsock.h>#endif#if HAVE_DMALLOC_H#include <dmalloc.h>#endif#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "struct.h"#include "pass.h"#include "extensible.h"#include "util_funcs.h"struct extensible *passthrus = NULL;int             numpassthrus = 0;/* * the relocatable extensible commands variables  */struct variable2 extensible_passthru_variables[] = {    /*     * bogus entry.  Only some of it is actually used.      */    {MIBINDEX, ASN_INTEGER, RWRITE, var_extensible_pass, 0, {MIBINDEX}},};/* * lexicographical compare two object identifiers. * * Returns -1 if name1 < name2, * *          0 if name1 = name2, * *          1 if name1 > name2 * * * * This method differs from snmp_oid_compare * * in that the comparison stops at the length * * of the smallest object identifier. */intsnmp_oid_min_compare(const oid * in_name1,                     size_t len1, const oid * in_name2, size_t len2){    register int    len;    register const oid *name1 = in_name1;    register const oid *name2 = in_name2;    /*     * len = minimum of len1 and len2      */    if (len1 < len2)        len = len1;    else        len = len2;    /*     * find first non-matching OID      */    while (len-- > 0) {        /*         * these must be done in seperate comparisons, since         * subtracting them and using that result has problems with         * subids > 2^31.          */        if (*(name1) < *(name2))            return -1;        if (*(name1++) > *(name2++))            return 1;    }    /*     * both OIDs equal up to length of shorter OID      */    return 0;}/* * This is also called from pass_persist.c  */intasc2bin(char *p){    char           *r, *q = p;    char            c;    int             n = 0;    for (;;) {        c = (char) strtol(q, &r, 16);        if (r == q)            break;        *p++ = c;        q = r;        n++;    }    return n;}/* * This is also called from pass_persist.c  */intbin2asc(char *p, size_t n){    int             i, flag = 0;    char            buffer[SNMP_MAXBUF];    /* prevent buffer overflow */    if ((int)n > (sizeof(buffer) - 1))        n = sizeof(buffer) - 1;    for (i = 0; i < (int) n; i++) {        buffer[i] = p[i];        if (!isprint(p[i]))            flag = 1;    }    if (flag == 0) {        p[n] = 0;        return n;    }    for (i = 0; i < (int) n; i++) {        sprintf(p, "%02x ", (unsigned char) (buffer[i] & 0xff));        p += 3;    }    *--p = 0;    return 3 * n - 1;}voidinit_pass(void){    snmpd_register_config_handler("pass", pass_parse_config,                                  pass_free_config, "miboid command");}voidpass_parse_config(const char *token, char *cptr){    struct extensible **ppass = &passthrus, **etmp, *ptmp;    char           *tcptr;    int             i;    if (*cptr == '.')        cptr++;    if (!isdigit(*cptr)) {        config_perror("second token is not a OID");        return;    }    numpassthrus++;    while (*ppass != NULL)        ppass = &((*ppass)->next);    (*ppass) = (struct extensible *) malloc(sizeof(struct extensible));    if (*ppass == NULL)        return;    (*ppass)->type = PASSTHRU;    (*ppass)->miblen = parse_miboid(cptr, (*ppass)->miboid);    while (isdigit(*cptr) || *cptr == '.')        cptr++;    /*     * name      */    cptr = skip_white(cptr);    if (cptr == NULL) {        config_perror("No command specified on pass line");        (*ppass)->command[0] = 0;    } else {        for (tcptr = cptr; *tcptr != 0 && *tcptr != '#' && *tcptr != ';';             tcptr++);        strncpy((*ppass)->command, cptr, tcptr - cptr);        (*ppass)->command[tcptr - cptr] = 0;    }    strncpy((*ppass)->name, (*ppass)->command, sizeof((*ppass)->name));    (*ppass)->name[ sizeof((*ppass)->name)-1 ] = 0;    (*ppass)->next = NULL;    register_mib("pass", (struct variable *) extensible_passthru_variables,                 sizeof(struct variable2),                 1, (*ppass)->miboid, (*ppass)->miblen);    /*     * argggg -- pasthrus must be sorted      */    if (numpassthrus > 1) {        etmp = (struct extensible **)            malloc(((sizeof(struct extensible *)) * numpassthrus));        if (etmp == NULL)            return;        for (i = 0, ptmp = (struct extensible *) passthrus;             i < numpassthrus && ptmp != 0; i++, ptmp = ptmp->next)            etmp[i] = ptmp;        qsort(etmp, numpassthrus, sizeof(struct extensible *),              pass_compare);        passthrus = (struct extensible *) etmp[0];        ptmp = (struct extensible *) etmp[0];        for (i = 0; i < numpassthrus - 1; i++) {            ptmp->next = etmp[i + 1];            ptmp = ptmp->next;        }        ptmp->next = NULL;        free(etmp);    }}voidpass_free_config(void){    struct extensible *etmp, *etmp2;    for (etmp = passthrus; etmp != NULL;) {        etmp2 = etmp;        etmp = etmp->next;        unregister_mib(etmp2->miboid, etmp2->miblen);        free(etmp2);    }    passthrus = NULL;    numpassthrus = 0;}u_char         *var_extensible_pass(struct variable *vp,                    oid * name,                    size_t * length,                    int exact,                    size_t * var_len, WriteMethod ** write_method){    oid             newname[MAX_OID_LEN];    int             i, rtest, fd, newlen;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -