📄 ipaddresstable.c
字号:
/** WARNING: this code might not work for netsnmp_ipaddress_entry */ /* * make sure there is enough space for ipAddressAddr data */ if (tbl_idx->ipAddressAddr_len < ipAddressAddr_val_ptr_len) { snmp_log(LOG_ERR, "not enough space for value\n"); return MFD_ERROR; } tbl_idx->ipAddressAddr_len = ipAddressAddr_val_ptr_len; memcpy(tbl_idx->ipAddressAddr, ipAddressAddr_val_ptr, ipAddressAddr_val_ptr_len * sizeof(ipAddressAddr_val_ptr[0])); return MFD_SUCCESS;} /* ipAddressTable_indexes_set_tbl_idx *//** * @internal * set row context indexes * * @param reqreq_ctx the row context that needs updated indexes * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error. * * @remark * This function sets the mib indexs, then updates the oid indexs * from the mib index. */intipAddressTable_indexes_set(ipAddressTable_rowreq_ctx * rowreq_ctx, u_long ipAddressAddrType_val, char *ipAddressAddr_val_ptr, size_t ipAddressAddr_val_ptr_len){ DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_indexes_set", "called\n")); if (MFD_SUCCESS != ipAddressTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx, ipAddressAddrType_val, ipAddressAddr_val_ptr, ipAddressAddr_val_ptr_len)) return MFD_ERROR; /* * convert mib index to oid index */ rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); if (0 != ipAddressTable_index_to_oid(&rowreq_ctx->oid_idx, &rowreq_ctx->tbl_idx)) { return MFD_ERROR; } return MFD_SUCCESS;} /* ipAddressTable_indexes_set *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressIfIndex * ipAddressIfIndex is subid 3 of ipAddressEntry. * Its status is Current, and its access level is Create. * OID: .1.3.6.1.2.1.4.34.1.3 * Description:The index value which uniquely identifies the interface to which this entry is applicable. The interface identified by a particular value of this index is the same interface as identified by the same value of the IF-MIB's ifIndex. * * Attributes: * accessible 1 isscalar 0 enums 0 hasdefval 0 * readable 1 iscolumn 1 ranges 1 hashint 1 * settable 1 * hint: d * * Ranges: 1 - 2147483647; * * Its syntax is InterfaceIndex (based on perltype INTEGER32) * The net-snmp type is ASN_INTEGER. The C type decl is long (long) *//** * Extract the current value of the ipAddressIfIndex data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ipAddressIfIndex_val_ptr * Pointer to storage for a long variable * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error */intipAddressIfIndex_get(ipAddressTable_rowreq_ctx * rowreq_ctx, long *ipAddressIfIndex_val_ptr){ /** we should have a non-NULL pointer */ netsnmp_assert(NULL != ipAddressIfIndex_val_ptr); DEBUGMSGTL(("verbose:ipAddressTable:ipAddressIfIndex_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:231:o: |-> Extract the current value of the ipAddressIfIndex data. * copy (* ipAddressIfIndex_val_ptr ) from rowreq_ctx->data */ (*ipAddressIfIndex_val_ptr) = rowreq_ctx->data->if_index; return MFD_SUCCESS;} /* ipAddressIfIndex_get *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressType * ipAddressType is subid 4 of ipAddressEntry. * Its status is Current, and its access level is Create. * OID: .1.3.6.1.2.1.4.34.1.4 * Description:The type of address. broadcast(3) is not a valid value for IPv6 addresses (RFC3513). * * Attributes: * accessible 1 isscalar 0 enums 1 hasdefval 1 * readable 1 iscolumn 1 ranges 0 hashint 0 * settable 1 * defval: unicast * * Enum range: 2/8. Values: unicast(1), anycast(2), broadcast(3) * * Its syntax is INTEGER (based on perltype INTEGER) * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) *//** * Extract the current value of the ipAddressType data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ipAddressType_val_ptr * Pointer to storage for a long variable * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error */intipAddressType_get(ipAddressTable_rowreq_ctx * rowreq_ctx, u_long * ipAddressType_val_ptr){ /** we should have a non-NULL pointer */ netsnmp_assert(NULL != ipAddressType_val_ptr); DEBUGMSGTL(("verbose:ipAddressTable:ipAddressType_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:231:o: |-> Extract the current value of the ipAddressType data. * copy (* ipAddressType_val_ptr ) from rowreq_ctx->data */ (*ipAddressType_val_ptr) = rowreq_ctx->data->ia_type; return MFD_SUCCESS;} /* ipAddressType_get *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressPrefix * ipAddressPrefix is subid 5 of ipAddressEntry. * Its status is Current, and its access level is ReadOnly. * OID: .1.3.6.1.2.1.4.34.1.5 * Description:A pointer to the row in the prefix table to which this address belongs. May be { 0 0 } if there is no such row. * * Attributes: * accessible 1 isscalar 0 enums 0 hasdefval 1 * readable 1 iscolumn 1 ranges 0 hashint 0 * settable 0 * defval: zeroDotZero * * * Its syntax is RowPointer (based on perltype OBJECTID) * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid) * This data type requires a length. *//** * Extract the current value of the ipAddressPrefix data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ipAddressPrefix_val_ptr_ptr * Pointer to storage for a oid variable * @param ipAddressPrefix_val_ptr_len_ptr * Pointer to a size_t. On entry, it will contain the size (in bytes) * pointed to by ipAddressPrefix. * On exit, this value should contain the data size (in bytes). * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error* * @note If you need more than (*ipAddressPrefix_val_ptr_len_ptr) bytes of memory, * allocate it using malloc() and update ipAddressPrefix_val_ptr_ptr. * <b>DO NOT</b> free the previous pointer. * The MFD helper will release the memory you allocate. * * @remark If you call this function yourself, you are responsible * for checking if the pointer changed, and freeing any * previously allocated memory. (Not necessary if you pass * in a pointer to static memory, obviously.) */intipAddressPrefix_get(ipAddressTable_rowreq_ctx * rowreq_ctx, oid ** ipAddressPrefix_val_ptr_ptr, size_t * ipAddressPrefix_val_ptr_len_ptr){ oid *dst, tmp_oid[MAX_OID_LEN] = { 1, 3, 6, 1, 2, 1, 4, 32, 1, 5 }; u_char tmp_buf[NETSNMP_ACCESS_IPADDRESS_BUF_SIZE]; int len; /** we should have a non-NULL pointer and enough storage */ netsnmp_assert((NULL != ipAddressPrefix_val_ptr_ptr) && (NULL != *ipAddressPrefix_val_ptr_ptr)); netsnmp_assert(NULL != ipAddressPrefix_val_ptr_len_ptr); DEBUGMSGTL(("verbose:ipAddressTable:ipAddressPrefix_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:231:o: |-> Extract the current value of the ipAddressPrefix data. * copy (* ipAddressPrefix_val_ptr_ptr ) data and (* ipAddressPrefix_val_ptr_len_ptr ) from rowreq_ctx->data */ dst = &tmp_oid[10]; *(dst++) = rowreq_ctx->data->if_index; *(dst++) = rowreq_ctx->tbl_idx.ipAddressAddrType; *(dst++) = rowreq_ctx->data->ia_address_len; netsnmp_ipaddress_prefix_copy(tmp_buf, rowreq_ctx->tbl_idx.ipAddressAddr, rowreq_ctx->data->ia_address_len, rowreq_ctx->data->ia_prefix_len); for (len = 0; len < rowreq_ctx->data->ia_address_len; ++len) *(dst++) = tmp_buf[len]; *(dst++) = rowreq_ctx->data->ia_prefix_len; len = dst - tmp_oid; len *= sizeof((*ipAddressPrefix_val_ptr_ptr)[0]); if ((*ipAddressPrefix_val_ptr_len_ptr) < len) { (*ipAddressPrefix_val_ptr_ptr) = malloc(len); if (NULL == (*ipAddressPrefix_val_ptr_ptr)) { snmp_log(LOG_ERR, "could not allocate memory\n"); return MFD_ERROR; } } (*ipAddressPrefix_val_ptr_len_ptr) = len; memcpy((*ipAddressPrefix_val_ptr_ptr), tmp_oid, len); return MFD_SUCCESS;} /* ipAddressPrefix_get *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressOrigin * ipAddressOrigin is subid 6 of ipAddressEntry. * Its status is Current, and its access level is ReadOnly. * OID: .1.3.6.1.2.1.4.34.1.6 * Description:The origin of the address. * * Attributes: * accessible 1 isscalar 0 enums 1 hasdefval 0 * readable 1 iscolumn 1 ranges 0 hashint 0 * settable 0 * * Enum range: 4/8. Values: other(1), manual(2), dhcp(4), linklayer(5), random(6) * * Its syntax is IpAddressOriginTC (based on perltype INTEGER) * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) *//** * Extract the current value of the ipAddressOrigin data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ipAddressOrigin_val_ptr * Pointer to storage for a long variable * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error */intipAddressOrigin_get(ipAddressTable_rowreq_ctx * rowreq_ctx, u_long * ipAddressOrigin_val_ptr){ /** we should have a non-NULL pointer */ netsnmp_assert(NULL != ipAddressOrigin_val_ptr); DEBUGMSGTL(("verbose:ipAddressTable:ipAddressOrigin_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:231:o: |-> Extract the current value of the ipAddressOrigin data. * copy (* ipAddressOrigin_val_ptr ) from rowreq_ctx->data */ (*ipAddressOrigin_val_ptr) = rowreq_ctx->data->ia_origin; return MFD_SUCCESS;} /* ipAddressOrigin_get *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressStatus * ipAddressStatus is subid 7 of ipAddressEntry. * Its status is Current, and its access level is Create. * OID: .1.3.6.1.2.1.4.34.1.7 * Description:The status of the address, describing if the address can be used for communication. In the absence of other information, an IPv4 address is always preferred(1). * * Attributes: * accessible 1 isscalar 0 enums 1 hasdefval 1 * readable 1 iscolumn 1 ranges 0 hashint 0 * settable 1 * defval: preferred * * Enum range: 5/8. Values: preferred(1), invalid(3), inaccessible(4), unknown(5), tentative(6), duplicate(7) * * Its syntax is IpAddressStatusTC (based on perltype INTEGER) * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) *//** * Extract the current value of the ipAddressStatus data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ipAddressStatus_val_ptr * Pointer to storage for a long variable * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error */intipAddressStatus_get(ipAddressTable_rowreq_ctx * rowreq_ctx, u_long * ipAddressStatus_val_ptr){ /** we should have a non-NULL pointer */ netsnmp_assert(NULL != ipAddressStatus_val_ptr); DEBUGMSGTL(("verbose:ipAddressTable:ipAddressStatus_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:231:o: |-> Extract the current value of the ipAddressStatus data. * copy (* ipAddressStatus_val_ptr ) from rowreq_ctx->data */ (*ipAddressStatus_val_ptr) = rowreq_ctx->data->ia_status; return MFD_SUCCESS;} /* ipAddressStatus_get *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressCreated * ipAddressCreated is subid 8 of ipAddressEntry. * Its status is Current, and its access level is ReadOnly. * OID: .1.3.6.1.2.1.4.34.1.8 * Description:The value of sysUpTime at the time this entry was created. If this entry was created prior to the last re- initialization of the local network management subsystem, then this object contains a zero value. * * Attributes: * accessible 1 isscalar 0 enums 0 hasdefval 0 * readable 1 iscolumn 1 ranges 0 hashint 0 * settable 0 * *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -