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

📄 header_complex.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
        *var_len = sizeof(long);    for (nptr = datalist; nptr != NULL && found == NULL; nptr = nptr->next) {        if (vp) {            memcpy(indexOid, vp->name, vp->namelen * sizeof(oid));            memcpy(indexOid + vp->namelen, nptr->name,                   nptr->namelen * sizeof(oid));            len = vp->namelen + nptr->namelen;        } else {            memcpy(indexOid, nptr->name, nptr->namelen * sizeof(oid));            len = nptr->namelen;        }        result = snmp_oid_compare(name, *length, indexOid, len);        DEBUGMSGTL(("header_complex", "Checking: "));        DEBUGMSGOID(("header_complex", indexOid, len));        DEBUGMSG(("header_complex", "\n"));        if (exact) {            if (result == 0) {                found = nptr;            }        } else {            if (result == 0) {                /*                 * found an exact match.  Need the next one for !exact                  */                if (nptr->next)                    found = nptr->next;            } else if (result == -1) {                found = nptr;            }        }    }    if (found) {        if (vp) {            memcpy(name, vp->name, vp->namelen * sizeof(oid));            memcpy(name + vp->namelen, found->name,                   found->namelen * sizeof(oid));            *length = vp->namelen + found->namelen;        } else {            memcpy(name, found->name, found->namelen * sizeof(oid));            *length = found->namelen;        }        return found->data;    }    return NULL;}struct header_complex_index *header_complex_add_data(struct header_complex_index **thedata,                        netsnmp_variable_list * var, void *data){    oid             newoid[MAX_OID_LEN];    size_t          newoid_len;    struct header_complex_index *ret;    if (thedata == NULL || var == NULL || data == NULL)        return NULL;    header_complex_generate_oid(newoid, &newoid_len, NULL, 0, var);    ret =        header_complex_add_data_by_oid(thedata, newoid, newoid_len, data);    /*     * free the variable list, but not the enclosed data!  it's not ours!      */    snmp_free_varbind(var);    return (ret);}struct header_complex_index *header_complex_add_data_by_oid(struct header_complex_index **thedata,                               oid * newoid, size_t newoid_len, void *data){    struct header_complex_index *hciptrn, *hciptrp, *ourself;    if (thedata == NULL || newoid == NULL || data == NULL)        return NULL;    for (hciptrn = *thedata, hciptrp = NULL;         hciptrn != NULL; hciptrp = hciptrn, hciptrn = hciptrn->next)        /*         * XXX: check for == and error (overlapping table entries)          */        if (snmp_oid_compare            (hciptrn->name, hciptrn->namelen, newoid, newoid_len)            > 0)            break;    /*     * nptr should now point to the spot that we need to add ourselves     * in front of, and pptr should be our new 'prev'.      */    /*     * create ourselves      */    ourself = (struct header_complex_index *)        SNMP_MALLOC_STRUCT(header_complex_index);    /*     * change our pointers      */    ourself->prev = hciptrp;    ourself->next = hciptrn;    if (ourself->next)        ourself->next->prev = ourself;    if (ourself->prev)        ourself->prev->next = ourself;    ourself->data = data;    ourself->name = snmp_duplicate_objid(newoid, newoid_len);    ourself->namelen = newoid_len;    /*     * rewind to the head of the list and return it (since the new head     * could be us, we need to notify the above routine who the head now is.      */    for (hciptrp = ourself; hciptrp->prev != NULL;         hciptrp = hciptrp->prev);    *thedata = hciptrp;    DEBUGMSGTL(("header_complex_add_data", "adding something...\n"));    return hciptrp;}/* * extracts an entry from the storage space (removing it from future * accesses) and returns the data stored there *  * Modifies "thetop" pointer as needed (and if present) if were * extracting the first node. */void           *header_complex_extract_entry(struct header_complex_index **thetop,                             struct header_complex_index *thespot){    struct header_complex_index *hciptrp, *hciptrn;    void           *retdata = thespot->data;    if (thespot == NULL) {        DEBUGMSGTL(("header_complex_extract_entry",                    "Null pointer asked to be extracted\n"));        return NULL;    }    hciptrp = thespot->prev;    hciptrn = thespot->next;    if (hciptrp)        hciptrp->next = hciptrn;    else if (thetop)        *thetop = hciptrn;    if (hciptrn)        hciptrn->prev = hciptrp;    if (thespot->name)        free(thespot->name);    free(thespot);    return retdata;}/* * wipe out a single entry  */voidheader_complex_free_entry(struct header_complex_index *theentry,                          HeaderComplexCleaner * cleaner){    void           *data;    data = header_complex_extract_entry(NULL, theentry);    (*cleaner) (data);}/* * completely wipe out all entries in our data store  */voidheader_complex_free_all(struct header_complex_index *thestuff,                        HeaderComplexCleaner * cleaner){    struct header_complex_index *hciptr, *hciptrn;    for (hciptr = thestuff; hciptr != NULL; hciptr = hciptrn) {        hciptrn = hciptr->next; /* need to extract this before deleting it */        header_complex_free_entry(hciptr, cleaner);    }}struct header_complex_index *header_complex_find_entry(struct header_complex_index *thestuff,                          void *theentry){    struct header_complex_index *hciptr;    for (hciptr = thestuff; hciptr != NULL && hciptr->data != theentry;         hciptr = hciptr->next);    return hciptr;}#ifdef TESTINGvoidheader_complex_dump(struct header_complex_index *thestuff){    struct header_complex_index *hciptr;    oid             oidsave[MAX_OID_LEN];    size_t          len;    for (hciptr = thestuff; hciptr != NULL; hciptr = hciptr->next) {        DEBUGMSGTL(("header_complex_dump", "var:  "));        header_complex_generate_oid(oidsave, &len, NULL, 0, hciptr->);        DEBUGMSGOID(("header_complex_dump", oidsave, len));        DEBUGMSG(("header_complex_dump", "\n"));    }}main(){    oid             oidsave[MAX_OID_LEN];    int             len = MAX_OID_LEN, len2;    netsnmp_variable_list *vars;    long            ltmp = 4242, ltmp2 = 88, ltmp3 = 1, ltmp4 = 4200;    oid             ourprefix[] = { 1, 2, 3, 4 };    oid             testparse[] = { 4, 116, 101, 115, 116, 4200 };    int             ret;    char           *string = "wes", *string2 = "dawn", *string3 = "test";    struct header_complex_index *thestorage = NULL;    debug_register_tokens("header_complex");    snmp_set_do_debugging(1);    vars = NULL;    len2 = sizeof(ltmp);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_INTEGER, (char *) &ltmp,                              len2);    header_complex_add_data(&thestorage, vars, ourprefix);    vars = NULL;    len2 = strlen(string);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, string, len2);    header_complex_add_data(&thestorage, vars, ourprefix);    vars = NULL;    len2 = sizeof(ltmp2);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_INTEGER, (char *) &ltmp2,                              len2);    header_complex_add_data(&thestorage, vars, ourprefix);    vars = NULL;    len2 = strlen(string2);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, string2,                              len2);    header_complex_add_data(&thestorage, vars, ourprefix);    vars = NULL;    len2 = sizeof(ltmp3);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_INTEGER, (char *) &ltmp3,                              len2);    header_complex_add_data(&thestorage, vars, ourprefix);    vars = NULL;    len2 = strlen(string3);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, string3,                              len2);    len2 = sizeof(ltmp4);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_INTEGER, (char *) &ltmp4,                              len2);    header_complex_add_data(&thestorage, vars, ourprefix);    header_complex_dump(thestorage);    vars = NULL;    snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0);    snmp_varlist_add_variable(&vars, NULL, 0, ASN_INTEGER, NULL, 0);    ret =        header_complex_parse_oid(testparse,                                 sizeof(testparse) / sizeof(oid), vars);    DEBUGMSGTL(("header_complex_test", "parse returned %d...\n", ret));}#endif

⌨️ 快捷键说明

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