本文整理汇总了C++中snmp_sess_perror函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_sess_perror函数的具体用法?C++ snmp_sess_perror怎么用?C++ snmp_sess_perror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_sess_perror函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: snmp_init
int
snmp_init(selector_t *sel)
{
struct snmp_session session;
#ifdef HAVE_NETSNMP
netsnmp_transport *transport = NULL;
static char *snmp_default_port = "udp:162";
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_MIB_ERRORS,
0);
init_snmp("ipmi_ui");
transport = netsnmp_tdomain_transport(snmp_default_port, 1, "udp");
if (!transport) {
snmp_sess_perror("ipmi_ui", &session);
return -1;
}
#else
void *transport = NULL;
#endif
snmp_sess_init(&session);
session.peername = SNMP_DEFAULT_PEERNAME;
session.version = SNMP_DEFAULT_VERSION;
session.community_len = SNMP_DEFAULT_COMMUNITY_LEN;
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.local_port = SNMP_TRAP_PORT;
session.callback = snmp_input;
session.callback_magic = transport;
session.authenticator = NULL;
session.isAuthoritative = SNMP_SESS_UNKNOWNAUTH;
#ifdef HAVE_NETSNMP
snmp_session = snmp_add(&session, transport, snmp_pre_parse, NULL);
#else
snmp_session = snmp_open_ex(&session, snmp_pre_parse,
NULL, NULL, NULL, NULL);
#endif
if (snmp_session == NULL) {
snmp_sess_perror("ipmi_ui", &session);
return -1;
}
ipmi_sel_set_read_fds_handler(sel,
snmp_add_read_fds,
snmp_check_read_fds,
snmp_check_timeout,
NULL);
return 0;
}
开发者ID:ystk,项目名称:debian-openipmi,代码行数:53,代码来源:basic_ui.c
示例2: send_trap_to_sess
/*
* send_trap_to_sess: sends a trap to a session but assumes that the
* pdu is constructed correctly for the session type.
*/
void
send_trap_to_sess(netsnmp_session * sess, netsnmp_pdu *template_pdu)
{
netsnmp_pdu *pdu;
if (!sess || !template_pdu)
return;
DEBUGMSGTL(("trap", "sending trap type=%d, version=%d\n",
template_pdu->command, sess->version));
if (sess->version == SNMP_VERSION_1 &&
(template_pdu->command == SNMP_MSG_TRAP2 ||
template_pdu->command == SNMP_MSG_INFORM))
return; /* Skip v1 sinks for v2 only traps */
template_pdu->version = sess->version;
pdu = snmp_clone_pdu(template_pdu);
pdu->sessid = sess->sessid; /* AgentX only ? */
if (snmp_send(sess, pdu) == 0) {
snmp_sess_perror("snmpd: send_trap", sess);
snmp_free_pdu(pdu);
} else {
snmp_increment_statistic(STAT_SNMPOUTTRAPS);
snmp_increment_statistic(STAT_SNMPOUTPKTS);
}
}
开发者ID:TheTypoMaster,项目名称:AH4222,代码行数:30,代码来源:agent_trap.c
示例3: create_trap_session
int
create_trap_session(char *sink, u_short sinkport,
char *com, int version, int pdutype)
{
netsnmp_session session, *sesp;
char *peername = NULL;
if ((peername = malloc(strlen(sink) + 4 + 32)) == NULL) {
return 0;
} else {
snprintf(peername, strlen(sink) + 4 + 32, "udp:%s:%hu", sink,
sinkport);
}
memset(&session, 0, sizeof(netsnmp_session));
session.peername = peername;
session.version = version;
if (com) {
session.community = (u_char *) com;
session.community_len = strlen(com);
}
sesp = snmp_open(&session);
free(peername);
if (sesp) {
return add_trap_session(sesp, pdutype,
(pdutype == SNMP_MSG_INFORM), version);
}
/*
* diagnose snmp_open errors with the input netsnmp_session pointer
*/
snmp_sess_perror("snmpd: create_trap_session", &session);
return 0;
}
开发者ID:TheTypoMaster,项目名称:AH4222,代码行数:35,代码来源:agent_trap.c
示例4: init_master_agent
int
init_master_agent(int dest_port,
int (*pre_parse) (struct snmp_session *, snmp_ipaddr),
int (*post_parse) (struct snmp_session *, struct snmp_pdu *,int))
{
struct snmp_session sess, *session;
if ( ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) != MASTER_AGENT )
return 0; /* no error if ! MASTER_AGENT */
DEBUGMSGTL(("snmpd","installing master agent on port %d\n", dest_port));
snmp_sess_init( &sess );
sess.version = SNMP_DEFAULT_VERSION;
sess.peername = SNMP_DEFAULT_PEERNAME;
sess.community_len = SNMP_DEFAULT_COMMUNITY_LEN;
sess.local_port = dest_port;
sess.callback = handle_snmp_packet;
sess.authenticator = NULL;
sess.flags = ds_get_int(DS_APPLICATION_ID, DS_AGENT_FLAGS);
session = snmp_open_ex( &sess, pre_parse, 0, post_parse, 0, 0 );
if ( session == NULL ) {
/* diagnose snmp_open errors with the input struct snmp_session pointer */
snmp_sess_perror("init_master_agent", &sess);
return 1;
}
main_session = session;
return 0;
}
开发者ID:Palantir555,项目名称:ecos-mars-zx3,代码行数:32,代码来源:snmp_agent.c
示例5: open_session_helper
/**
* Helper for snmp_init
*/
static void open_session_helper(netsnmp_session *local, netsnmp_session **remote)
{
*remote = snmp_open(local);
if (!*remote) {
snmp_sess_perror("SNMP ack", local);
exit(EXIT_FAILURE);
}
}
开发者ID:limasierra,项目名称:SatelliteConnectionMonitor,代码行数:12,代码来源:snmplib.c
示例6: send_trap_to_sess
/*
* send_trap_to_sess: sends a trap to a session but assumes that the
* pdu is constructed correctly for the session type.
*/
void
send_trap_to_sess(netsnmp_session * sess, netsnmp_pdu *template_pdu)
{
netsnmp_pdu *pdu;
int result;
int len;
if (!sess || !template_pdu)
return;
DEBUGMSGTL(("trap", "sending trap type=%d, version=%ld\n",
template_pdu->command, sess->version));
#ifndef NETSNMP_DISABLE_SNMPV1
if (sess->version == SNMP_VERSION_1 &&
(template_pdu->command != SNMP_MSG_TRAP))
return; /* Skip v1 sinks for v2 only traps */
if (sess->version != SNMP_VERSION_1 &&
(template_pdu->command == SNMP_MSG_TRAP))
return; /* Skip v2+ sinks for v1 only traps */
#endif
template_pdu->version = sess->version;
pdu = snmp_clone_pdu(template_pdu);
pdu->sessid = sess->sessid; /* AgentX only ? */
if ( template_pdu->command == SNMP_MSG_INFORM
#ifdef USING_AGENTX_PROTOCOL_MODULE
|| template_pdu->command == AGENTX_MSG_NOTIFY
#endif
) {
result =
snmp_async_send(sess, pdu, &handle_inform_response, NULL);
} else {
if ((sess->version == SNMP_VERSION_3) &&
(pdu->command == SNMP_MSG_TRAP2) &&
(sess->securityEngineIDLen == 0)) {
u_char tmp[SPRINT_MAX_LEN];
len = snmpv3_get_engineID(tmp, sizeof(tmp));
memdup(&pdu->securityEngineID, tmp, len);
pdu->securityEngineIDLen = len;
}
result = snmp_send(sess, pdu);
}
if (result == 0) {
snmp_sess_perror("snmpd: send_trap", sess);
snmp_free_pdu(pdu);
} else {
snmp_increment_statistic(STAT_SNMPOUTTRAPS);
snmp_increment_statistic(STAT_SNMPOUTPKTS);
}
}
开发者ID:RasmusKoldsoe,项目名称:performand.k70.2,代码行数:60,代码来源:agent_trap.c
示例7: setMainSwitch
/** Write on/off status
*/
double setMainSwitch(HSNMP m_sessp,float value) {
struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_SET); // prepare set-request pdu
pdu->community = (u_char*)strdup(writeCommunity);
pdu->community_len = strlen(writeCommunity);
// for(each SET request to one crate) {
int v = (int) value;
snmp_pdu_add_variable(pdu,oidSysMainSwitch,lengthSysMainSwitch,ASN_INTEGER,(u_char*)&v,sizeof(v));
// } // endfor
struct snmp_pdu* response;
int status = snmp_sess_synch_response(m_sessp,pdu,&response);
/*
* Process the response.
*/
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list *vars;
// debug print
//for(vars = response->variables; vars; vars = vars->next_variable)
// print_variable(vars->name, vars->name_length, vars);
/* manipuate the information ourselves */
for(vars = response->variables; vars; vars = vars->next_variable) {
if (vars->type == ASN_OPAQUE_FLOAT) { // 0x78
value = *vars->val.floatVal;
}
else if (vars->type == ASN_OPAQUE_DOUBLE) { // 0x79
value = *vars->val.doubleVal;
}
else if(vars->type == ASN_INTEGER) { // 0x02
value = (double)*vars->val.integer;
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status == STAT_SUCCESS)
fprintf(stderr, "Error in packet\nReason: %s\n",
snmp_errstring(response->errstat));
else
snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
return 0;
}
snmp_free_pdu(response);
return value;
}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:58,代码来源:WIENER_SNMP.cpp
示例8: getCurrentMeasurement
/** Get current from power supply
*/
double getCurrentMeasurement(HSNMP m_sessp, int channel) {
double value;
struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_GET); // prepare get-request pdu
// for(each GET request to one crate) {
snmp_add_null_var(pdu,oidOutputMeasurementCurrent[channel],lengthOutputMeasurementCurrent[channel]); // generate request data
// } // endfor
struct snmp_pdu* response;
int status = snmp_sess_synch_response(m_sessp,pdu,&response);
/*
* Process the response.
*/
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list *vars;
// debug print
//for(vars = response->variables; vars; vars = vars->next_variable)
// print_variable(vars->name, vars->name_length, vars);
/* manipuate the information ourselves */
for(vars = response->variables; vars; vars = vars->next_variable) {
if (vars->type == ASN_OPAQUE_FLOAT) { // 0x78
value = *vars->val.floatVal;
}
else if (vars->type == ASN_OPAQUE_DOUBLE) { // 0x79
value = *vars->val.doubleVal;
}
else if(vars->type == ASN_INTEGER) { // 0x02
value = (double)*vars->val.integer;
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status == STAT_SUCCESS)
fprintf(stderr, "Error in packet\nReason: %s\n",
snmp_errstring(response->errstat));
else
snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
return 0;
}
snmp_free_pdu(response);
return value;
}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:57,代码来源:WIENER_SNMP.cpp
示例9: init_master
void init_master(void)
{
struct snmp_session sess, *session;
if ( ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) != MASTER_AGENT )
return;
DEBUGMSGTL(("agentx/master","initializing...\n"));
snmp_sess_init( &sess );
sess.version = AGENTX_VERSION_1;
sess.flags |= SNMP_FLAGS_STREAM_SOCKET;
if ( ds_get_string(DS_APPLICATION_ID, DS_AGENT_X_SOCKET) )
sess.peername = strdup(ds_get_string(DS_APPLICATION_ID, DS_AGENT_X_SOCKET));
else
sess.peername = strdup(AGENTX_SOCKET);
if ( sess.peername[0] == '/' ) {
/*
* If this is a Unix pathname,
* try and create the directory first.
*/
if (mkdirhier(sess.peername, AGENT_DIRECTORY_MODE, 1)) {
snmp_log(LOG_ERR,
"Failed to create the directory for the agentX socket: %s\n",
sess.peername);
}
}
/*
* Otherwise, let 'snmp_open' interpret the string.
*/
sess.local_port = AGENTX_PORT; /* Indicate server & set default port */
sess.remote_port = 0;
sess.callback = handle_master_agentx_packet;
session = snmp_open_ex( &sess, 0, agentx_parse, 0, agentx_build,
agentx_check_packet );
if ( session == NULL && sess.s_errno == EADDRINUSE ) {
/*
* Could be a left-over socket (now deleted)
* Try again
*/
session = snmp_open_ex( &sess, 0, agentx_parse, 0, agentx_build,
agentx_check_packet );
}
if ( session == NULL ) {
/* diagnose snmp_open errors with the input struct snmp_session pointer */
snmp_sess_perror("init_master", &sess);
if (!ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS))
exit(1);
}
DEBUGMSGTL(("agentx/master","initializing... DONE\n"));
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:54,代码来源:master.c
示例10: errHandles
// handle err if connection fails
void errHandles(int stat) {
if (status == STAT_SUCCESS)
fprintf(stderr, "Error in packet\nReason: %s\n",
snmp_errstring(response->errstat));
else if (status == STAT_TIMEOUT)
fprintf(stderr, "Timeout: No response from %s.\n",
session.peername);
else
snmp_sess_perror("snmpdemoapp", ss);
}
开发者ID:kenchan13579,项目名称:SNMP,代码行数:12,代码来源:snmp.c
示例11: create_trap_session
int
create_trap_session(char *sink, u_short sinkport,
char *com, int version, int pdutype)
{
netsnmp_session session, *sesp;
char *peername = NULL;
int len;
len = strlen(sink) + 4 + 32;
if ((peername = malloc(len)) == NULL) {
return 0;
} else if (NULL != strchr(sink,':')) {
snprintf(peername, len, "%s", sink);
} else {
snprintf(peername, len, "udp:%s:%hu", sink, sinkport);
}
memset(&session, 0, sizeof(netsnmp_session));
session.peername = peername;
session.version = version;
if (com) {
session.community = (u_char *) com;
session.community_len = strlen(com);
}
/*
* for informs, set retries to default
*/
if (SNMP_MSG_INFORM == pdutype) {
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.retries = SNMP_DEFAULT_RETRIES;
}
/*
* if the sink is localhost, bind to localhost, to reduce open ports.
*/
if ((NULL == netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_CLIENT_ADDR)) &&
((0 == strcmp("localhost",sink)) || (0 == strcmp("127.0.0.1",sink))))
session.localname = "localhost";
sesp = snmp_open(&session);
free(peername);
if (sesp) {
return add_trap_session(sesp, pdutype,
(pdutype == SNMP_MSG_INFORM), version);
}
/*
* diagnose snmp_open errors with the input netsnmp_session pointer
*/
snmp_sess_perror("snmpd: create_trap_session", &session);
return 0;
}
开发者ID:Nymphetaminer,项目名称:dsl-n55u,代码行数:54,代码来源:agent_trap.c
示例12: collect
netsnmp_variable_list *
collect(netsnmp_session * ss, netsnmp_pdu *pdu,
oid * base, size_t base_length)
{
netsnmp_pdu *response;
int running = 1;
netsnmp_variable_list *saved = NULL, **vlpp = &saved;
int status;
while (running) {
/*
* gotta catch em all, gotta catch em all!
*/
status = snmp_synch_response(ss, pdu, &response);
if (status != STAT_SUCCESS || !response) {
snmp_sess_perror("snmpdf", ss);
exit(1);
}
if (response->errstat != SNMP_ERR_NOERROR) {
fprintf(stderr, "snmpdf: Error in packet: %s\n",
snmp_errstring(response->errstat));
exit(1);
}
if (response && snmp_oid_compare(response->variables->name,
SNMP_MIN(base_length,
response->variables->
name_length), base,
base_length) != 0)
running = 0;
else {
/*
* get response
*/
*vlpp = response->variables;
(*vlpp)->next_variable = NULL; /* shouldn't be any, but just in case */
/*
* create the next request
*/
pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
snmp_add_null_var(pdu, (*vlpp)->name, (*vlpp)->name_length);
/*
* finish loop setup
*/
vlpp = &((*vlpp)->next_variable);
response->variables = NULL; /* ahh, forget about it */
}
snmp_free_pdu(response);
}
return saved;
}
开发者ID:ColdStart,项目名称:SNMPD,代码行数:52,代码来源:snmpdf.c
示例13: snmp_pdu_create
bool Session::getVariables(const QStringList &oids, QValueVector<QVariant> &retvars, uint32_t &status, int startIndex)
{
struct snmp_pdu *response = NULL;
if ( ! m_session )
{
status = 0xFFFFFFFF;
return false;
}
struct snmp_pdu *pdu = snmp_pdu_create(SNMP_MSG_GET);
u_long anOID[MAX_OID_LEN];
QStringList::const_iterator it = oids.begin();
for(int i = 0; i < startIndex; i++) it++; // rough hack, but works
for(int i = 0; it != oids.end() && i < 5; it++, i++ )
{
size_t anOID_len = MAX_OID_LEN;
get_node((*it).latin1(), anOID, &anOID_len);
snmp_add_null_var(pdu, anOID, anOID_len);
}
status = snmp_synch_response(m_session, pdu, &response);
//! @todo Error handling should be changed in a more OO way.
if ( status != STAT_SUCCESS )
{
snmp_sess_perror("snmpget", m_session);
return false;
}
if ( response->errstat != SNMP_ERR_NOERROR )
{
kdWarning() << "Error in packet: " << snmp_errstring(response->errstat) << endl;
snmp_free_pdu(response);
return false;
}
variable_list *var = response->variables;
int i = startIndex;
while( var )
{
retvars[i] = snmpvarToVariant(var);
i++;
var = var->next_variable;
}
snmp_free_pdu(response);
return true;
}
开发者ID:Flameeyes,项目名称:libksnmp,代码行数:52,代码来源:session.cpp
示例14: snmp_getn_bulk
SaErrorT snmp_getn_bulk( struct snmp_session *ss,
oid *bulk_objid,
size_t bulk_objid_len,
struct snmp_pdu *bulk_pdu,
struct snmp_pdu **bulk_response,
int num_repetitions )
{
int status;
SaErrorT rtncode = SA_OK;
// struct variable_list *vars;
bulk_pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
bulk_pdu->non_repeaters = 0;
bulk_pdu->max_repetitions = num_repetitions;
snmp_add_null_var(bulk_pdu, bulk_objid, bulk_objid_len);
/* Send the Request out.*/
status = snmp_synch_response(ss, bulk_pdu, bulk_response);
/*
* Process the response.
*/
#if 0
if (status == STAT_SUCCESS) {
vars = (*bulk_response)->variables;
if ((*bulk_response)->errstat == SNMP_ERR_NOERROR) {
if (!CHECH_END(vars->type)) {
/* This is one of the exception condition */
rtncode = SA_ERR_HPI_NOT_PRESENT;
dbg("snmp exception %d \n",vars->type);
}
} else {
fprintf(stderr, "Error in packet %s\nReason: %s\n",
(char *)bulk_objid, snmp_errstring((*bulk_response)->errstat));
if ((*bulk_response)->errstat == SNMP_ERR_NOSUCHNAME)
(*bulk_response)->errstat = SNMP_NOSUCHOBJECT;
rtncode = (SaErrorT) (SA_ERR_SNMP_BASE - (*bulk_response)->errstat);
}
} else {
snmp_sess_perror("snmpset", ss);
rtncode = (SaErrorT) (SA_ERR_SNMP_BASE - status);
}
#endif
return(rtncode);
}
开发者ID:openhpi1,项目名称:testrepo,代码行数:49,代码来源:snmp_utils.c
示例15: net_snmp_failure
SaErrorT net_snmp_failure(struct snmp_client_hnd *custom_handle, int snmp_status,
struct snmp_pdu *response)
{
if (snmp_status == STAT_SUCCESS) {
dbg("Error in packet, Whilst getting Resources\nReason: %s",
snmp_errstring(response->errstat));
dbg("ERROR: net_snmp_failure %s",
snmp_errstring(response->errstat));
} else {
snmp_sess_perror("snmpget", custom_handle->ss);
dbg("ERROR: net_snmp_failure");
}
return(SA_ERR_HPI_ERROR);
}
开发者ID:openhpi1,项目名称:testrepo,代码行数:15,代码来源:snmp_client_utils.c
示例16: snmp_synch_response
char *session_query(struct snmp_session *ss, struct snmp_pdu *pdu) {
struct snmp_pdu *response;
struct variable_list *vars;
int status;
char buf[SPRINT_MAX_LEN];
char *rbuffer=NULL;
/* Send the Request */
status = snmp_synch_response(ss, pdu, &response);
/* Process the response */
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR )
{
/* Success: Print the results */
/* for (vars=response->variables; vars; vars=vars->next_variable) { */
vars=response->variables;
if (vars!=NULL && vars->type <ASN_LONG_LEN) {
if (vars->type == ASN_INTEGER) {
sprintf(buf,"%ld",*vars->val.integer);
rbuffer=malloc(sizeof(char)*(strlen(buf)+1));
memset(rbuffer,'\0',strlen(buf)+1);
strncpy(rbuffer,buf,strlen(buf));
} else {
snprint_variable(buf, sizeof (buf), vars->name, vars->name_length, vars);
rbuffer=malloc(sizeof(char)*(strlen(buf)+1));
memset(rbuffer,'\0',strlen(buf)+1);
strncpy(rbuffer,buf,strlen(buf));
}
} else rbuffer = NULL;
} else {
/* Failure: print what went wrong */
if (status == STAT_SUCCESS)
fprintf(stderr,"Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
else
snmp_sess_perror("snmpget ", ss);
}
/* Clean up */
if (response) snmp_free_pdu(response);
// printf("Result : %s\n",rbuffer);
return rbuffer;
}
开发者ID:Ancient,项目名称:NetGuard,代码行数:46,代码来源:snmp_layer.c
示例17: snmp_pdu_create
char *session_set( struct snmp_session *ss,const char *name, const char *value ) {
struct snmp_pdu *pdu, *response;
oid anOID[MAX_OID_LEN];
size_t anOID_len = MAX_OID_LEN;
struct variable_list *vars;
int status;
char buf[SPRINT_MAX_LEN];
char *rbuffer=NULL;
/* create PDU for request */
pdu = snmp_pdu_create(SNMP_MSG_SET);
get_node(name, anOID, &anOID_len);
snmp_add_var(pdu, anOID, anOID_len,'i',value);
// snmp_add_null_var(pdu, anOID, anOID_len);
/* Send the Request */
status = snmp_synch_response(ss, pdu, &response);
/* Process the response */
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
/* Success: Print the results */
/* for (vars=response->variables; vars; vars=vars->next_variable) { */
vars=response->variables;
if (vars!=NULL) {
snprint_variable(buf, sizeof (buf), vars->name, vars->name_length, vars);
rbuffer=malloc(sizeof(char)*(strlen(buf)+1));
memset(rbuffer,'\0',strlen(buf)+1);
strncpy(rbuffer,buf,strlen(buf));
} else rbuffer = NULL;
} else {
/* Failure: print what went wrong */
if (status == STAT_SUCCESS)
fprintf(stderr,"Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
else
snmp_sess_perror("snmpset", ss);
}
/* Clean up */
/* if (pdu) snmp_free_pdu(pdu); */
if (response) snmp_free_pdu(response);
return rbuffer;
}
开发者ID:Ancient,项目名称:NetGuard,代码行数:45,代码来源:snmp_layer.c
示例18: create_trap_session2
static int
create_trap_session2(const char *sink, const char* sinkport,
char *com, int version, int pdutype)
{
netsnmp_transport *t;
netsnmp_session session, *sesp;
memset(&session, 0, sizeof(netsnmp_session));
session.version = version;
if (com) {
session.community = (u_char *) com;
session.community_len = strlen(com);
}
/*
* for informs, set retries to default
*/
if (SNMP_MSG_INFORM == pdutype) {
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.retries = SNMP_DEFAULT_RETRIES;
}
/*
* if the sink is localhost, bind to localhost, to reduce open ports.
*/
if ((NULL == netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_CLIENT_ADDR)) &&
((0 == strcmp("localhost",sink)) || (0 == strcmp("127.0.0.1",sink))))
session.localname = "localhost";
t = netsnmp_tdomain_transport_full("snmptrap", sink, 0, NULL, sinkport);
if (t != NULL) {
sesp = snmp_add(&session, t, NULL, NULL);
if (sesp) {
return add_trap_session(sesp, pdutype,
(pdutype == SNMP_MSG_INFORM), version);
}
}
/*
* diagnose snmp_open errors with the input netsnmp_session pointer
*/
snmp_sess_perror("snmpd: create_trap_session", &session);
return 0;
}
开发者ID:grantc,项目名称:ingres-snmp-agent,代码行数:45,代码来源:agent_trap.c
示例19: snmpcommand
// a higher abstraction function takes oid string and SNMP methods and call
void snmpcommand(char* oid,int cmd) {
SOCK_STARTUP;
ss = snmp_open(&session); /* establish the session */
if (!ss) {
snmp_sess_perror("ack", &session);
SOCK_CLEANUP;
exit(1);
}
pdu = snmp_pdu_create(cmd);
if ( cmd == SNMP_MSG_GETBULK) { // for bulkget only
pdu->non_repeaters = 0;
pdu->max_repetitions = 50;
}
anOID_len = MAX_OID_LEN;
get_node(oid, anOID, &anOID_len);
snmp_add_null_var(pdu, anOID, anOID_len);// all OID should be paired with null for out going req
status = snmp_synch_response(ss, pdu, &response); // sent req
}
开发者ID:kenchan13579,项目名称:SNMP,代码行数:19,代码来源:snmp.c
示例20: snmp_sess_init
static netsnmp_session *snmptrapd_add_session(netsnmp_transport *t) {
netsnmp_session sess, *session = &sess, *rc = NULL;
snmp_sess_init(session);
session->peername = SNMP_DEFAULT_PEERNAME; /* Original code had NULL here */
session->version = SNMP_DEFAULT_VERSION;
session->community_len = SNMP_DEFAULT_COMMUNITY_LEN;
session->retries = SNMP_DEFAULT_RETRIES;
session->timeout = SNMP_DEFAULT_TIMEOUT;
session->callback = snmp_input;
session->callback_magic = (void *) t;
session->authenticator = NULL;
sess.isAuthoritative = SNMP_SESS_UNKNOWNAUTH;
rc = snmp_add(session, t, pre_parse, NULL);
if (rc == NULL) {
snmp_sess_perror("snmptrapd", session);
}
return rc;
}
开发者ID:kalombos,项目名称:pynetsnmp,代码行数:18,代码来源:trapd.c
注:本文中的snmp_sess_perror函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论