📄 tcplistenertable_interface.c
字号:
/* * set up varbinds */ memset(&var_tcpListenerLocalAddressType, 0x00, sizeof(var_tcpListenerLocalAddressType)); var_tcpListenerLocalAddressType.type = ASN_INTEGER; memset(&var_tcpListenerLocalAddress, 0x00, sizeof(var_tcpListenerLocalAddress)); var_tcpListenerLocalAddress.type = ASN_OCTET_STR; memset(&var_tcpListenerLocalPort, 0x00, sizeof(var_tcpListenerLocalPort)); var_tcpListenerLocalPort.type = ASN_UNSIGNED; /* * chain temp index varbinds together */ var_tcpListenerLocalAddressType.next_variable = &var_tcpListenerLocalAddress; var_tcpListenerLocalAddress.next_variable = &var_tcpListenerLocalPort; var_tcpListenerLocalPort.next_variable = NULL; DEBUGMSGTL(("verbose:tcpListenerTable:tcpListenerTable_index_to_oid", "called\n")); /* * tcpListenerLocalAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ snmp_set_var_value(&var_tcpListenerLocalAddressType, (u_char *) & mib_idx->tcpListenerLocalAddressType, sizeof(mib_idx->tcpListenerLocalAddressType)); /* * tcpListenerLocalAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ snmp_set_var_value(&var_tcpListenerLocalAddress, (u_char *) & mib_idx->tcpListenerLocalAddress, mib_idx->tcpListenerLocalAddress_len * sizeof(mib_idx->tcpListenerLocalAddress[0])); /* * tcpListenerLocalPort(3)/InetPortNumber/ASN_UNSIGNED/u_long(u_long)//l/a/w/e/R/d/H */ snmp_set_var_value(&var_tcpListenerLocalPort, (u_char *) & mib_idx->tcpListenerLocalPort, sizeof(mib_idx->tcpListenerLocalPort)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_tcpListenerLocalAddressType); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_tcpListenerLocalAddressType); return err;} /* tcpListenerTable_index_to_oid *//** * extract tcpListenerTable indexes from a netsnmp_index * * @retval SNMP_ERR_NOERROR : no error * @retval SNMP_ERR_GENERR : error */inttcpListenerTable_index_from_oid(netsnmp_index * oid_idx, tcpListenerTable_mib_index * mib_idx){ int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * tcpListenerLocalAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ netsnmp_variable_list var_tcpListenerLocalAddressType; /* * tcpListenerLocalAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ netsnmp_variable_list var_tcpListenerLocalAddress; /* * tcpListenerLocalPort(3)/InetPortNumber/ASN_UNSIGNED/u_long(u_long)//l/a/w/e/R/d/H */ netsnmp_variable_list var_tcpListenerLocalPort; /* * set up varbinds */ memset(&var_tcpListenerLocalAddressType, 0x00, sizeof(var_tcpListenerLocalAddressType)); var_tcpListenerLocalAddressType.type = ASN_INTEGER; memset(&var_tcpListenerLocalAddress, 0x00, sizeof(var_tcpListenerLocalAddress)); var_tcpListenerLocalAddress.type = ASN_OCTET_STR; memset(&var_tcpListenerLocalPort, 0x00, sizeof(var_tcpListenerLocalPort)); var_tcpListenerLocalPort.type = ASN_UNSIGNED; /* * chain temp index varbinds together */ var_tcpListenerLocalAddressType.next_variable = &var_tcpListenerLocalAddress; var_tcpListenerLocalAddress.next_variable = &var_tcpListenerLocalPort; var_tcpListenerLocalPort.next_variable = NULL; DEBUGMSGTL(("verbose:tcpListenerTable:tcpListenerTable_index_from_oid", "called\n")); /* * parse the oid into the individual index components */ err = parse_oid_indexes(oid_idx->oids, oid_idx->len, &var_tcpListenerLocalAddressType); if (err == SNMP_ERR_NOERROR) { /* * copy out values */ mib_idx->tcpListenerLocalAddressType = *((u_long *) var_tcpListenerLocalAddressType.val.string); /* * NOTE: val_len is in bytes, tcpListenerLocalAddress_len might not be */ if (var_tcpListenerLocalAddress.val_len > sizeof(mib_idx->tcpListenerLocalAddress)) err = SNMP_ERR_GENERR; else { memcpy(mib_idx->tcpListenerLocalAddress, var_tcpListenerLocalAddress.val.string, var_tcpListenerLocalAddress.val_len); mib_idx->tcpListenerLocalAddress_len = var_tcpListenerLocalAddress.val_len / sizeof(mib_idx->tcpListenerLocalAddress[0]); } mib_idx->tcpListenerLocalPort = *((u_long *) var_tcpListenerLocalPort.val.string); } /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_tcpListenerLocalAddressType); return err;} /* tcpListenerTable_index_from_oid *//* ********************************************************************* * @internal * allocate resources for a tcpListenerTable_rowreq_ctx */tcpListenerTable_rowreq_ctx *tcpListenerTable_allocate_rowreq_ctx(tcpListenerTable_data * data, void *user_init_ctx){ tcpListenerTable_rowreq_ctx *rowreq_ctx = SNMP_MALLOC_TYPEDEF(tcpListenerTable_rowreq_ctx); DEBUGMSGTL(("internal:tcpListenerTable:tcpListenerTable_allocate_rowreq_ctx", "called\n")); if (NULL == rowreq_ctx) { snmp_log(LOG_ERR, "Couldn't allocate memory for a " "tcpListenerTable_rowreq_ctx.\n"); return NULL; } else { if (NULL != data) { /* * track if we got data from user */ rowreq_ctx->rowreq_flags |= MFD_ROW_DATA_FROM_USER; rowreq_ctx->data = data; } else if (NULL == (rowreq_ctx->data = tcpListenerTable_allocate_data())) { SNMP_FREE(rowreq_ctx); return NULL; } } /* * undo context will be allocated when needed (in *_undo_setup) */ rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; rowreq_ctx->tcpListenerTable_data_list = NULL; /* * if we allocated data, call init routine */ if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) { if (SNMPERR_SUCCESS != tcpListenerTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) { tcpListenerTable_release_rowreq_ctx(rowreq_ctx); rowreq_ctx = NULL; } } return rowreq_ctx;} /* tcpListenerTable_allocate_rowreq_ctx *//* * @internal * release resources for a tcpListenerTable_rowreq_ctx */voidtcpListenerTable_release_rowreq_ctx(tcpListenerTable_rowreq_ctx * rowreq_ctx){ DEBUGMSGTL(("internal:tcpListenerTable:tcpListenerTable_release_rowreq_ctx", "called\n")); netsnmp_assert(NULL != rowreq_ctx); tcpListenerTable_rowreq_ctx_cleanup(rowreq_ctx); /* * for non-transient data, don't free data we got from the user */ if ((rowreq_ctx->data) && !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) tcpListenerTable_release_data(rowreq_ctx->data); /* * free index oid pointer */ if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) free(rowreq_ctx->oid_idx.oids); SNMP_FREE(rowreq_ctx);} /* tcpListenerTable_release_rowreq_ctx *//** * @internal * wrapper */static int_mfd_tcpListenerTable_pre_request(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc; DEBUGMSGTL(("internal:tcpListenerTable:_mfd_tcpListenerTable_pre_request", "called\n")); if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:tcpListenerTable", "skipping additional pre_request\n")); return SNMP_ERR_NOERROR; } rc = tcpListenerTable_pre_request(tcpListenerTable_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("tcpListenerTable", "error %d from " "tcpListenerTable_pre_request\n", rc)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } return SNMP_ERR_NOERROR;} /* _mfd_tcpListenerTable_pre_request *//** * @internal * wrapper */static int_mfd_tcpListenerTable_post_request(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ tcpListenerTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); int rc, packet_rc; DEBUGMSGTL(("internal:tcpListenerTable:_mfd_tcpListenerTable_post_request", "called\n")); /* * release row context, if deleted */ if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED)) tcpListenerTable_release_rowreq_ctx(rowreq_ctx); /* * wait for last call before calling user */ if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:tcpListenerTable", "waiting for last post_request\n")); return SNMP_ERR_NOERROR; } packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0); rc = tcpListenerTable_post_request(tcpListenerTable_if_ctx.user_ctx, packet_rc); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("tcpListenerTable", "error %d from " "tcpListenerTable_post_request\n", rc)); } return SNMP_ERR_NOERROR;} /* _mfd_tcpListenerTable_post_request *//** * @internal * wrapper */static int_mfd_tcpListenerTable_object_lookup(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc = SNMP_ERR_NOERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -