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

📄 ipaddresstable_interface.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
 * * GET processing * ***********************************************************************//* * @internal * Retrieve the value for a particular column */NETSNMP_STATIC_INLINE int_ipAddressTable_get_column(ipAddressTable_rowreq_ctx * rowreq_ctx,                           netsnmp_variable_list * var, int column){    int             rc = SNMPERR_SUCCESS;    DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_column",                "called for %d\n", column));    netsnmp_assert(NULL != rowreq_ctx);    switch (column) {        /*         * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H          */    case COLUMN_IPADDRESSIFINDEX:        var->val_len = sizeof(long);        var->type = ASN_INTEGER;        rc = ipAddressIfIndex_get(rowreq_ctx, (long *) var->val.string);        break;        /*         * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h          */    case COLUMN_IPADDRESSTYPE:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipAddressType_get(rowreq_ctx, (u_long *) var->val.string);        break;        /*         * ipAddressPrefix(5)/RowPointer/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/D/h          */    case COLUMN_IPADDRESSPREFIX:        var->type = ASN_OBJECT_ID;        rc = ipAddressPrefix_get(rowreq_ctx, (oid **) & var->val.string,                                 &var->val_len);        break;        /*         * ipAddressOrigin(6)/IpAddressOriginTC/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h          */    case COLUMN_IPADDRESSORIGIN:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipAddressOrigin_get(rowreq_ctx, (u_long *) var->val.string);        break;        /*         * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h          */    case COLUMN_IPADDRESSSTATUS:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipAddressStatus_get(rowreq_ctx, (u_long *) var->val.string);        break;        /*         * ipAddressCreated(8)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IPADDRESSCREATED:        var->val_len = sizeof(u_long);        var->type = ASN_TIMETICKS;        rc = ipAddressCreated_get(rowreq_ctx, (u_long *) var->val.string);        break;        /*         * ipAddressLastChanged(9)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IPADDRESSLASTCHANGED:        var->val_len = sizeof(u_long);        var->type = ASN_TIMETICKS;        rc = ipAddressLastChanged_get(rowreq_ctx,                                      (u_long *) var->val.string);        break;        /*         * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h          */    case COLUMN_IPADDRESSROWSTATUS:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipAddressRowStatus_get(rowreq_ctx,                                    (u_long *) var->val.string);        break;        /*         * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h          */    case COLUMN_IPADDRESSSTORAGETYPE:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipAddressStorageType_get(rowreq_ctx,                                      (u_long *) var->val.string);        break;    default:        snmp_log(LOG_ERR,                 "unknown column %d in _ipAddressTable_get_column\n",                 column);        break;    }    return rc;}                               /* _ipAddressTable_get_column */int_mfd_ipAddressTable_get_values(netsnmp_mib_handler *handler,                               netsnmp_handler_registration *reginfo,                               netsnmp_agent_request_info *agtreq_info,                               netsnmp_request_info *requests){    ipAddressTable_rowreq_ctx *rowreq_ctx =        netsnmp_container_table_row_extract(requests);    netsnmp_table_request_info *tri;    u_char         *old_string;    void            (*dataFreeHook) (void *);    int             rc;    DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_values",                "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    for (; requests; requests = requests->next) {        /*         * save old pointer, so we can free it if replaced         */        old_string = requests->requestvb->val.string;        dataFreeHook = requests->requestvb->dataFreeHook;        if (NULL == requests->requestvb->val.string) {            requests->requestvb->val.string = requests->requestvb->buf;            requests->requestvb->val_len =                sizeof(requests->requestvb->buf);        } else if (requests->requestvb->buf ==                   requests->requestvb->val.string) {            if (requests->requestvb->val_len !=                sizeof(requests->requestvb->buf))                requests->requestvb->val_len =                    sizeof(requests->requestvb->buf);        }        /*         * get column data         */        tri = netsnmp_extract_table_info(requests);        if (NULL == tri)            continue;        rc = _ipAddressTable_get_column(rowreq_ctx, requests->requestvb,                                        tri->colnum);        if (rc) {            if (MFD_SKIP == rc) {                requests->requestvb->type = SNMP_NOSUCHINSTANCE;                rc = SNMP_ERR_NOERROR;            }        } else if (NULL == requests->requestvb->val.string) {            snmp_log(LOG_ERR, "NULL varbind data pointer!\n");            rc = SNMP_ERR_GENERR;        }        if (rc)            netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));        /*         * if the buffer wasn't used previously for the old data (i.e. it         * was allcoated memory)  and the get routine replaced the pointer,         * we need to free the previous pointer.         */        if (old_string && (old_string != requests->requestvb->buf) &&            (requests->requestvb->val.string != old_string)) {            if (dataFreeHook)                (*dataFreeHook) (old_string);            else                free(old_string);        }    }                           /* for results */    return SNMP_ERR_NOERROR;}                               /* _mfd_ipAddressTable_get_values */NETSNMP_STATIC_INLINE int_ipAddressTable_check_indexes(ipAddressTable_rowreq_ctx * rowreq_ctx){    int             rc = SNMPERR_SUCCESS;    DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_indexes",                "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    /*     * (INDEX) ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h      */    /*     * check that the value is one of defined enums      */    if ((SNMPERR_SUCCESS == rc)        && (rowreq_ctx->tbl_idx.ipAddressAddrType !=            INETADDRESSTYPE_UNKNOWN)        && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV4)        && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV6)        && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV4Z)        && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_IPV6Z)        && (rowreq_ctx->tbl_idx.ipAddressAddrType != INETADDRESSTYPE_DNS)        ) {        rc = SNMP_ERR_WRONGVALUE;    }    if (MFD_SUCCESS != rc)        return rc;    rc = ipAddressAddrType_check_index(rowreq_ctx);    if (MFD_SUCCESS != rc)        return SNMP_ERR_NOCREATION;    /*     * (INDEX) ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h      */    /*     * check defined range(s).      */    if ((SNMPERR_SUCCESS == rc)        && ((rowreq_ctx->tbl_idx.ipAddressAddr_len < 0)            || (rowreq_ctx->tbl_idx.ipAddressAddr_len > 255))        ) {        rc = SNMP_ERR_WRONGLENGTH;    }    if (MFD_SUCCESS != rc)        return rc;    rc = ipAddressAddr_check_index(rowreq_ctx);    if (MFD_SUCCESS != rc)        return SNMP_ERR_NOCREATION;    /*     * if individual parts look ok, check them as a whole     */    return ipAddressTable_validate_index(ipAddressTable_if_ctx.user_ctx,                                         rowreq_ctx);}                               /* _ipAddressTable_check_indexes *//*********************************************************************** * * SET processing * ***********************************************************************//*---------------------------------------------------------------------- * * SET: Syntax checks * *---------------------------------------------------------------------*//* * @internal * Check the syntax for a particular column */NETSNMP_STATIC_INLINE int_ipAddressTable_check_column(ipAddressTable_rowreq_ctx * rowreq_ctx,                             netsnmp_variable_list * var, int column){    int             rc = SNMPERR_SUCCESS;    DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_column",                "called for %d\n", column));    netsnmp_assert(NULL != rowreq_ctx);    switch (column) {        /*         * (INDEX) ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h          */    case COLUMN_IPADDRESSADDRTYPE:        rc = SNMP_ERR_NOTWRITABLE;      /* can not change index of active row */        break;        /*         * (INDEX) ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h          */    case COLUMN_IPADDRESSADDR:        rc = SNMP_ERR_NOTWRITABLE;      /* can not change index of active row */        break;        /*         * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H          */    case COLUMN_IPADDRESSIFINDEX:        rc = netsnmp_check_vb_type(var, ASN_INTEGER);        /*         * check defined range(s).          */        if ((SNMPERR_SUCCESS == rc)            && ((*var->val.integer < 1)                || (*var->val.integer > 2147483647))            ) {            rc = SNMP_ERR_WRONGVALUE;        }        if (SNMPERR_SUCCESS != rc) {            DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressIfIndex", "varbind validation failed (eg bad type or size)\n"));        } else {            rc = ipAddressIfIndex_check_value(rowreq_ctx,                                              *((long *) var->val.string));            if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)                && (MFD_NOT_VALID_NOW != rc)) {                snmp_log(LOG_ERR,                         "bad rc %d from ipAddressIfIndex_check_value\n",                         rc);                rc = SNMP_ERR_GENERR;            }        }        break;        /*         * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h          */    case COLUMN_IPADDRESSTYPE:        rc = netsnmp_check_vb_type(var, ASN_INTEGER);        /*         * check that the value is one of defined enums          */        if ((SNMPERR_SUCCESS == rc)            && (*var->val.integer != IPADDRESSTYPE_UNICAST)            && (*var->val.integer != IPADDRESSTYPE_ANYCAST)            && (*var->val.integer != IPADDRESSTYPE_BROADCAST)            ) {            rc = SNMP_ERR_WRONGVALUE;        }        if (SNMPERR_SUCCESS != rc) {            DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressType", "varbind validation failed (eg bad type or size)\n"));        } else {            rc = ipAddressType_check_value(rowreq_ctx,                                           *((u_long *) var->val.string));            if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)                && (MFD_NOT_VALID_NOW != rc)) {                snmp_log(LOG_ERR,                         "bad rc %d from ipAddressType_check_value\n", rc);                rc = SNMP_ERR_GENERR;            }        }        break;        /*         * ipAddressPrefix(5)/RowPointer/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/D/h          */    case COLUMN_IPADDRESSPREFIX:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ipAddressOrigin(6)/IpAddressOriginTC/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h          */    case COLUMN_IPADDRESSORIGIN:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h          */    case COLUMN_IPADDRESSSTATUS:        rc = netsnmp_check_vb_type(var, ASN_INTEGER);        /*         * check that the value is one of defined enums          */        if ((SNMPERR_SUCCESS == rc)            && (*var->val.integer != IPADDRESSSTATUSTC_PREFERRED)            && (*var->val.integer != IPADDRESSSTATUSTC_INVALID)            && (*var->val.integer != IPADDRESSSTATUSTC_INACCESSIBLE)            && (*var->val.integer != IPADDRESSSTATUSTC_UNKNOWN)            && (*var->val.integer != IPADDRESSSTATUSTC_TENTATIVE)            && (*var->val.integer != IPADDRESSSTATUSTC_DUPLICATE)            ) {            rc = SNMP_ERR_WRONGVALUE;        }        if (SNMPERR_SUCCESS != rc) {            DEBUGMSGTL(("ipAddressTable:_ipAddressTable_check_column:ipAddressStatus", "varbind validation failed (eg bad type or size)\n"));        } else {            rc = ipAddressStatus_check_value(rowreq_ctx,                                             *((u_long *) var->val.                                               string));            if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)                && (MFD_NOT_VALID_NOW != rc)) {                snmp_log(LOG_ERR,                         "bad rc %d from ipAddressStatus_check_value\n",                         rc);                rc = SNMP_ERR_GENERR;            }        }        break;        /*         * ipAddressCreated(8)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IPADDRESSCREATED:        rc = SNMP_ERR_NOTWRITABLE;        break;

⌨️ 快捷键说明

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