本文整理汇总了C++中snmp_set_var_objid函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_set_var_objid函数的具体用法?C++ snmp_set_var_objid怎么用?C++ snmp_set_var_objid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_set_var_objid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: netsnmp_table_data_build_result
/* builds a result given a row, a varbind to set and the data */
int
netsnmp_table_data_build_result(netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *request,
netsnmp_table_row *row,
int column,
u_char type,
u_char * result_data,
size_t result_data_len)
{
oid build_space[MAX_OID_LEN];
if (!reginfo || !reqinfo || !request)
return SNMPERR_GENERR;
if (reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK) {
/*
* only need to do this for getnext type cases where oid is changing
*/
memcpy(build_space, reginfo->rootoid, /* registered oid */
reginfo->rootoid_len * sizeof(oid));
build_space[reginfo->rootoid_len] = 1; /* entry */
build_space[reginfo->rootoid_len + 1] = column; /* column */
memcpy(build_space + reginfo->rootoid_len + 2, /* index data */
row->index_oid, row->index_oid_len * sizeof(oid));
snmp_set_var_objid(request->requestvb, build_space,
reginfo->rootoid_len + 2 + row->index_oid_len);
}
snmp_set_var_typed_value(request->requestvb, type,
result_data, result_data_len);
return SNMPERR_SUCCESS; /* WWWXXX: check for bounds */
}
示例2: register_string_index
char *
register_string_index(oid * name, size_t name_len, char *cp)
{
netsnmp_variable_list varbind, *res;
memset(&varbind, 0, sizeof(netsnmp_variable_list));
varbind.type = ASN_OCTET_STR;
snmp_set_var_objid(&varbind, name, name_len);
if (cp != ANY_STRING_INDEX) {
snmp_set_var_value(&varbind, (u_char *) cp, strlen(cp));
res = register_index(&varbind, ALLOCATE_THIS_INDEX, main_session);
} else {
res = register_index(&varbind, ALLOCATE_ANY_INDEX, main_session);
}
if (res == NULL) {
return NULL;
} else {
char *rv = (char *)malloc(res->val_len + 1);
if (rv) {
memcpy(rv, res->val.string, res->val_len);
rv[res->val_len] = 0;
}
free(res);
return rv;
}
}
示例3: register_int_index
int
register_int_index(oid * name, size_t name_len, int val)
{
netsnmp_variable_list varbind, *res;
memset(&varbind, 0, sizeof(netsnmp_variable_list));
varbind.type = ASN_INTEGER;
snmp_set_var_objid(&varbind, name, name_len);
varbind.val.string = varbind.buf;
if (val != ANY_INTEGER_INDEX) {
varbind.val_len = sizeof(long);
*varbind.val.integer = val;
res = register_index(&varbind, ALLOCATE_THIS_INDEX, main_session);
} else {
res = register_index(&varbind, ALLOCATE_ANY_INDEX, main_session);
}
if (res == NULL) {
return -1;
} else {
int rv = *(res->val.integer);
free(res);
return rv;
}
}
示例4: build_new_oid
void
build_new_oid(netsnmp_handler_registration *reginfo,
netsnmp_table_request_info *tblreq_info,
netsnmp_index *row, netsnmp_request_info *current)
{
oid coloid[MAX_OID_LEN];
if (!tblreq_info || !reginfo || !row || !current)
return;
memcpy(coloid, reginfo->rootoid, reginfo->rootoid_len * sizeof(oid));
/** table.entry */
coloid[reginfo->rootoid_len] = 1;
/** table.entry.column */
coloid[reginfo->rootoid_len + 1] = tblreq_info->colnum;
/** table.entry.column.index */
memcpy(&coloid[reginfo->rootoid_len + 2], row->oids,
row->len * sizeof(oid));
snmp_set_var_objid(current->requestvb, coloid,
reginfo->rootoid_len + 2 + row->len);
}
示例5: _expObject_buildList
netsnmp_variable_list *
_expObject_buildList( oid *root, size_t root_len, size_t prefix_len,
netsnmp_variable_list *template_list )
{
netsnmp_variable_list *query_list = NULL;
netsnmp_variable_list *vp1, *vp2 = NULL;
oid name[ MAX_OID_LEN ];
int i;
if ( prefix_len ) {
/*
* For wildcarded objects, build a list of all relevant
* instances, using the template_list to provide the
* necessary instance suffixes.
*/
memset( name, 0, sizeof(name));
memcpy( name, root, root_len*sizeof(oid));
for ( vp1 = template_list; vp1; vp1=vp1->next_variable ) {
/*
* Append a new varbind to the list for this object ...
*/
if ( !query_list ) {
query_list = (netsnmp_variable_list*)
SNMP_MALLOC_TYPEDEF( netsnmp_variable_list );
vp2 = query_list;
} else {
vp2->next_variable = (netsnmp_variable_list*)
SNMP_MALLOC_TYPEDEF( netsnmp_variable_list );
vp2 = vp2->next_variable;
}
/*
* ... and set the OID using the template suffix
*/
for ( i=0; i <= vp1->name_length - prefix_len; i++)
name[ root_len+i ] = vp1->name[ prefix_len+i ];
snmp_set_var_objid( vp2, name, root_len+i );
}
} else {
/*
* Otherwise, just use the (single) OID provided.
*/
query_list = (netsnmp_variable_list*)
SNMP_MALLOC_TYPEDEF( netsnmp_variable_list );
snmp_set_var_objid( query_list, root, root_len );
}
return query_list;
}
示例6: memset
void AlarmTrapSender::send_trap(AlarmTableDef& alarm_table_def)
{
static const oid snmp_trap_oid[] = {1,3,6,1,6,3,1,1,4,1,0};
static const oid clear_oid[] = {1,3,6,1,2,1,118,0,3};
static const oid active_oid[] = {1,3,6,1,2,1,118,0,2};
static const oid model_ptr_oid[] = {1,3,6,1,2,1,118,1,2,2,1,13,0};
static const oid model_row_oid[] = {1,3,6,1,2,1,118,1,1,2,1,3,0,1,2};
static const oid resource_id_oid[] = {1,3,6,1,2,1,118,1,2,2,1,10,0};
static const oid zero_dot_zero[] = {0,0};
netsnmp_variable_list var_trap;
netsnmp_variable_list var_model_row;
netsnmp_variable_list var_resource_id;
memset(&var_trap, 0x00, sizeof(var_trap));
memset(&var_model_row, 0x00, sizeof(var_model_row));
memset(&var_resource_id, 0x00, sizeof(var_resource_id));
var_trap.next_variable = &var_model_row;
var_model_row.next_variable = &var_resource_id;
var_resource_id.next_variable = NULL;
snmp_set_var_objid(&var_trap, snmp_trap_oid, OID_LENGTH(snmp_trap_oid));
if (alarm_table_def.severity() == AlarmDef::CLEARED)
{
snmp_set_var_typed_value(&var_trap, ASN_OBJECT_ID, (u_char*) clear_oid, sizeof(clear_oid));
}
else
{
snmp_set_var_typed_value(&var_trap, ASN_OBJECT_ID, (u_char*) active_oid, sizeof(active_oid));
}
snmp_set_var_objid(&var_model_row, model_ptr_oid, OID_LENGTH(model_ptr_oid));
snmp_set_var_typed_value(&var_model_row, ASN_OBJECT_ID, (u_char*) model_row_oid, sizeof(model_row_oid));
var_model_row.val.objid[ALARMMODELTABLEROW_INDEX] = alarm_table_def.index();
var_model_row.val.objid[ALARMMODELTABLEROW_STATE] = alarm_table_def.state();
snmp_set_var_objid(&var_resource_id, resource_id_oid, OID_LENGTH(resource_id_oid));
snmp_set_var_typed_value(&var_resource_id, ASN_OBJECT_ID, (u_char*) zero_dot_zero, sizeof(zero_dot_zero));
send_v2trap(&var_trap);
snmp_reset_var_buffers(&var_trap);
}
示例7: unregister_string_index
int
unregister_string_index(oid * name, size_t name_len, char *cp)
{
netsnmp_variable_list varbind;
memset(&varbind, 0, sizeof(netsnmp_variable_list));
varbind.type = ASN_OCTET_STR;
snmp_set_var_objid(&varbind, name, name_len);
snmp_set_var_value(&varbind, (u_char *) cp, strlen(cp));
return (unregister_index(&varbind, FALSE, main_session));
}
示例8: my_test_handler
int
my_test_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
oid myoid1[] = { 1, 2, 3, 4, 5, 6 };
static u_long accesses = 0;
DEBUGMSGTL(("testhandler", "Got request:\n"));
/*
* loop through requests
*/
while (requests) {
netsnmp_variable_list *var = requests->requestvb;
DEBUGMSGTL(("testhandler", " oid:"));
DEBUGMSGOID(("testhandler", var->name, var->name_length));
DEBUGMSG(("testhandler", "\n"));
switch (reqinfo->mode) {
case MODE_GET:
if (netsnmp_oid_equals(var->name, var->name_length, myoid1, 6)
== 0) {
snmp_set_var_typed_value(var, ASN_INTEGER,
(u_char *) & accesses,
sizeof(accesses));
return SNMP_ERR_NOERROR;
}
break;
case MODE_GETNEXT:
if (snmp_oid_compare(var->name, var->name_length, myoid1, 6)
< 0) {
snmp_set_var_objid(var, myoid1, 6);
snmp_set_var_typed_value(var, ASN_INTEGER,
(u_char *) & accesses,
sizeof(accesses));
return SNMP_ERR_NOERROR;
}
break;
default:
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
break;
}
requests = requests->next;
}
return SNMP_ERR_NOERROR;
}
示例9: unregister_int_index
int
unregister_int_index(oid * name, size_t name_len, int val)
{
netsnmp_variable_list varbind;
memset(&varbind, 0, sizeof(netsnmp_variable_list));
varbind.type = ASN_INTEGER;
snmp_set_var_objid(&varbind, name, name_len);
varbind.val.string = varbind.buf;
varbind.val_len = sizeof(long);
*varbind.val.integer = val;
return (unregister_index(&varbind, FALSE, main_session));
}
示例10: unregister_oid_index
int
unregister_oid_index(oid * name, size_t name_len,
oid * value, size_t value_len)
{
netsnmp_variable_list varbind;
memset(&varbind, 0, sizeof(netsnmp_variable_list));
varbind.type = ASN_OBJECT_ID;
snmp_set_var_objid(&varbind, name, name_len);
snmp_set_var_value(&varbind, (u_char *) value,
value_len * sizeof(oid));
return (unregister_index(&varbind, FALSE, main_session));
}
示例11: register_oid_index
struct variable_list *
register_oid_index( oid *name, size_t name_len,
oid *value, size_t value_len )
{
struct variable_list varbind;
memset( &varbind, 0, sizeof(struct variable_list));
varbind.type = ASN_OBJECT_ID;
snmp_set_var_objid( &varbind, name, name_len );
if ( value != ANY_OID_INDEX ) {
snmp_set_var_value( &varbind, (u_char*)value, value_len*sizeof(oid) );
return( register_index( &varbind, ALLOCATE_THIS_INDEX, main_session ));
}
else
return( register_index( &varbind, ALLOCATE_ANY_INDEX, main_session ));
}
示例12: snmp_clone_var
/*
* Clone an SNMP variable data structure.
* Sets pointers to structure private storage, or
* allocates larger object identifiers and values as needed.
*
* Caller must make list association for cloned variable.
*
* Returns 0 if successful.
*/
int
snmp_clone_var(netsnmp_variable_list * var, netsnmp_variable_list * newvar)
{
if (!newvar || !var)
return 1;
memmove(newvar, var, sizeof(netsnmp_variable_list));
newvar->next_variable = 0;
newvar->name = 0;
newvar->val.string = 0;
newvar->data = 0;
newvar->dataFreeHook = 0;
newvar->index = 0;
/*
* Clone the object identifier and the value.
* Allocate memory iff original will not fit into local storage.
*/
if (snmp_set_var_objid(newvar, var->name, var->name_length))
return 1;
/*
* need a pointer and a length to copy a string value.
*/
if (var->val.string && var->val_len) {
if (var->val.string != &var->buf[0]) {
if (var->val_len <= sizeof(var->buf))
newvar->val.string = newvar->buf;
else {
newvar->val.string = (u_char *) malloc(var->val_len);
if (!newvar->val.string)
return 1;
}
memmove(newvar->val.string, var->val.string, var->val_len);
} else { /* fix the pointer to new local store */
newvar->val.string = newvar->buf;
}
} else {
newvar->val.string = 0;
newvar->val_len = 0;
}
return 0;
}
示例13: _mteEvent_fire_set
int _mteEvent_fire_set (struct mteEvent *entry, /* The event to fire */
struct mteTrigger *trigger, /* Trigger that fired */
oid * suffix, size_t sfx_len) /* Matching instance */
{
netsnmp_variable_list var;
oid set_oid[MAX_OID_LEN];
size_t set_len;
/*
* Set the basic assignment OID...
*/
memset (set_oid, 0, sizeof (set_oid));
memcpy (set_oid, entry->mteSetOID, entry->mteSetOID_len * sizeof (oid));
set_len = entry->mteSetOID_len;
/*
* ... if the trigger value is wildcarded (sfx_len > 0),
* *and* the SET event entry is wildcarded,
* then add the supplied instance suffix...
*/
if (sfx_len && entry->flags & MTE_SET_FLAG_OBJWILD)
{
memcpy (&set_oid[set_len], suffix, sfx_len * sizeof (oid));
set_len += sfx_len;
}
/*
* ... finally build the assignment varbind,
* and pass it to be acted on.
*
* XXX: Need to handle (remote) targets and non-default contexts
*/
memset (&var, 0, sizeof (var));
snmp_set_var_objid (&var, set_oid, set_len);
snmp_set_var_typed_integer (&var, ASN_INTEGER, entry->mteSetValue);
if (entry->session)
return netsnmp_query_set (&var, entry->session);
else
return netsnmp_query_set (&var, trigger->session);
/* XXX - Need to check result */
}
示例14: oa_bind_var
static netsnmp_variable_list *
oa_bind_var(netsnmp_variable_list * prev,
void *value, int type, size_t sz_val, oid * oid, size_t sz_oid)
{
netsnmp_variable_list *var;
var = (netsnmp_variable_list *) malloc(sizeof(netsnmp_variable_list));
if (!var) {
ag_trace("FATAL: cannot malloc in oa_bind_var\n");
exit(-1); /* Sorry :( */
}
memset(var, 0, sizeof(netsnmp_variable_list));
var->next_variable = prev;
snmp_set_var_objid(var, oid, sz_oid);
snmp_set_var_value(var, (u_char *) value, sz_val);
var->type = type;
return var;
}
示例15: register_string_index
char *
register_string_index( oid *name, size_t name_len, char *cp )
{
struct variable_list varbind, *res;
memset( &varbind, 0, sizeof(struct variable_list));
varbind.type = ASN_OCTET_STR;
snmp_set_var_objid( &varbind, name, name_len );
if ( cp != ANY_STRING_INDEX ) {
snmp_set_var_value( &varbind, (u_char *)cp, strlen(cp) );
res = register_index( &varbind, ALLOCATE_THIS_INDEX, main_session );
}
else
res = register_index( &varbind, ALLOCATE_ANY_INDEX, main_session );
if ( res == NULL )
return NULL;
else
return (char *)res->val.string;
}