本文整理汇总了C++中snmp_synch_response函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_synch_response函数的具体用法?C++ snmp_synch_response怎么用?C++ snmp_synch_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_synch_response函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: prsnmpstr
void prsnmpstr(char *stroid) {
struct snmp_pdu *pdu, *resp;
oid tmp_oid[MAX_OID_LEN];
size_t tmp_oid_len=MAX_OID_LEN;
int stat;
char *tmp;
pdu=snmp_pdu_create(SNMP_MSG_GET);
read_objid(stroid, tmp_oid, &tmp_oid_len);
snmp_add_null_var(pdu, tmp_oid, tmp_oid_len);
stat=snmp_synch_response(ses, pdu, &resp);
if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR)
perr(resp);
if(resp->variables->val_len && strlen((char *)resp->variables->val.string)) {
tmp=malloc((resp->variables->val_len+1) * sizeof(char));
memcpy(tmp, resp->variables->val.string, resp->variables->val_len);
tmp[resp->variables->val_len]=0;
printf("%s", tmp);
free(tmp);
}
if(resp)
snmp_free_pdu(resp);
}
开发者ID:xiongshaogang,项目名称:NetAndSysMonitor,代码行数:27,代码来源:ttg-snmp.cpp
示例2: snmp_get_item
static struct snmp_pdu *
snmp_get_item(char *host, char *community, char *mib_item)
{
struct snmp_session session, *ss;
struct snmp_pdu *request = NULL, *result = NULL;
oid Oid[MAX_OID_LEN];
unsigned int oid_len = MAX_OID_LEN;
/* initialize the SNMP session */
snmp_sess_init(&session);
session.peername = host;
session.community = (uchar_t *)community;
session.community_len = strlen((const char *)session.community);
session.version = SNMP_VERSION_1;
session.retries = 0;
if ((ss = snmp_open(&session)) == NULL)
return (NULL);
/* add the requested data */
if (!read_objid(mib_item, Oid, &oid_len))
snmp_perror(mib_item);
/* initialize the request PDU */
request = snmp_pdu_create(SNMP_MSG_GET);
snmp_add_null_var(request, Oid, oid_len);
(void) snmp_synch_response(ss, request, &result);
snmp_close(ss);
return (result);
}
开发者ID:drscream,项目名称:illumos-joyent,代码行数:33,代码来源:probe-snmp.c
示例3: synchronous
/*
* simple synchronous loop
*/
void synchronous (void)
{
struct host *hp;
for (hp = hosts; hp->name; hp++) {
struct snmp_session ss, *sp;
struct oid *op;
snmp_sess_init(&ss); /* initialize session */
ss.version = SNMP_VERSION_2c;
ss.peername = strdup(hp->name);
ss.community = strdup(hp->community);
ss.community_len = strlen(ss.community);
if (!(sp = snmp_open(&ss))) {
snmp_perror("snmp_open");
continue;
}
for (op = oids; op->Name; op++) {
struct snmp_pdu *req, *resp;
int status;
req = snmp_pdu_create(SNMP_MSG_GET);
snmp_add_null_var(req, op->Oid, op->OidLen);
status = snmp_synch_response(sp, req, &resp);
if (!print_result(status, sp, resp)) break;
snmp_free_pdu(resp);
}
snmp_close(sp);
}
}
开发者ID:dear531,项目名称:snmp_source,代码行数:32,代码来源:asyncapp.c
示例4: prifalias
void prifalias(oid inst) {
struct snmp_pdu *pdu, *resp;
oid tmp_oid[] = { 1,3,6,1,2,1,31,1,1,1,18,0 };
int stat;
char *tmp;
if(!extended) {
fprintf(stderr, "ifalias is only available in eXtended mode\n");
snmp_close(ses);
SOCK_CLEANUP;
exit(1);
}
tmp_oid[11]=inst;
pdu=snmp_pdu_create(SNMP_MSG_GET);
snmp_add_null_var(pdu, tmp_oid, sizeof(tmp_oid)/sizeof(oid));
stat=snmp_synch_response(ses, pdu, &resp);
if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR)
perr(resp);
if(resp->variables->val_len && strlen((char *)resp->variables->val.string)) {
tmp=malloc((resp->variables->val_len+1) * sizeof(char));
memcpy(tmp, resp->variables->val.string, resp->variables->val_len);
tmp[resp->variables->val_len]=0;
printf(" \"%s\"", tmp);
free(tmp);
}
if(resp)
snmp_free_pdu(resp);
}
开发者ID:xiongshaogang,项目名称:NetAndSysMonitor,代码行数:33,代码来源:ttg-snmp.cpp
示例5: getcntr32
uint32_t getcntr32(int dir, oid inst) {
struct snmp_pdu *pdu, *resp;
oid iftable_oid[] = { 1,3,6,1,2,1,2,2,1,0,0 }; // dir=9 ; inst=10
int stat;
uint32_t tmp;
pdu=snmp_pdu_create(SNMP_MSG_GET);
iftable_oid[9]=dir;
iftable_oid[10]=inst;
snmp_add_null_var(pdu, iftable_oid, sizeof(iftable_oid)/sizeof(oid));
stat=snmp_synch_response(ses, pdu, &resp);
if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR)
perr(resp);
if(resp->variables->type != ASN_COUNTER) {
fprintf(stderr, "\nError: unsupported data type (only 32bit counter is supported in normal mode)\n");
snmp_close(ses);
SOCK_CLEANUP;
exit(1);
}
tmp=resp->variables->val.counter64->high;
if(resp)
snmp_free_pdu(resp);
return tmp;
}
开发者ID:xiongshaogang,项目名称:NetAndSysMonitor,代码行数:29,代码来源:ttg-snmp.cpp
示例6: snmp_get_bulk
int snmp_get_bulk( struct snmp_session *ss,
const char *bulk_objid,
struct snmp_pdu *bulk_pdu,
struct snmp_pdu **bulk_response )
{
size_t anOID_len = MAX_OID_LEN;
oid anOID[MAX_OID_LEN];
int status;
/* Create the PDU for theenrty_count data for our request. */
read_objid(bulk_objid, anOID, &anOID_len);
bulk_pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
bulk_pdu->non_repeaters = 0;
bulk_pdu->max_repetitions = NUM_REPITIONS;
snmp_add_null_var(bulk_pdu, anOID, anOID_len);
/* Send the Request out.*/
status = snmp_synch_response(ss, bulk_pdu, bulk_response);
return(status);
}
开发者ID:openhpi1,项目名称:testrepo,代码行数:27,代码来源:snmp_client_discover.c
示例7: snmp_get_ifcount
/* report the value interfaces.ifNumber.0, actually the number of interfaces */
static int snmp_get_ifcount(struct snmp_session *ss) {
int nifaces = -1;
oid ifcount[] = { 1, 3, 6, 1, 2, 1, 2, 1, 0 };
struct snmp_pdu *pdu;
struct snmp_pdu *response = NULL;
int status;
if ((pdu = snmp_pdu_create(SNMP_MSG_GET)) == NULL) {
ifstat_error("snmp_pdu_create: %s", snmp_api_errstring(snmp_errno));
return -1;
}
snmp_add_null_var(pdu, ifcount, sizeof(ifcount) / sizeof(oid));
if ((status = snmp_synch_response(ss, pdu, &response)) != STAT_SUCCESS ||
response->errstat != SNMP_ERR_NOERROR ||
response->variables == NULL ||
response->variables->type != ASN_INTEGER) {
if (status == STAT_SUCCESS)
ifstat_error("snmp: Error: %s", snmp_errstring(response->errstat));
else
ifstat_error("snmpget(interfaces.ifNumber.0): %s", snmp_sess_errstring(ss));
if (response)
snmp_free_pdu(response);
return -1;
}
nifaces = *(response->variables->val.integer);
snmp_free_pdu(response);
if (nifaces < 0)
return -1;
return nifaces;
}
开发者ID:RaonControl,项目名称:siteApps,代码行数:34,代码来源:snmp.c
示例8: processSnmpGet
void processSnmpGet(char * oid){
read_objid(oid, id_oid, &id_len);
snmp_add_null_var(pdu, id_oid, id_len);
int status = snmp_synch_response(session_handle, pdu, &response);
for(vars = response->variables; vars; vars = vars->next_variable){
snprint_variable(outbuff, 256, vars->name, vars->name_length, vars);
resultString = strrchr(outbuff, ':');
}
}
开发者ID:und3ath,项目名称:centreon_plugins,代码行数:9,代码来源:check_netapp_native.c
示例9: ups_mib_mgr_get_upsBypassEntry
int ups_mib_mgr_get_upsBypassEntry(struct snmp_session *s, upsBypassEntry_t **upsBypassEntry)
{
struct snmp_session *peer;
struct snmp_pdu *request, *response;
struct variable_list *vars;
int status;
request = snmp_pdu_create(SNMP_MSG_GETNEXT);
snmp_add_null_var(request, upsBypassVoltage, sizeof(upsBypassVoltage)/sizeof(oid));
snmp_add_null_var(request, upsBypassCurrent, sizeof(upsBypassCurrent)/sizeof(oid));
snmp_add_null_var(request, upsBypassPower, sizeof(upsBypassPower)/sizeof(oid));
peer = snmp_open(s);
if (!peer) {
return -1;
}
status = snmp_synch_response(peer, request, &response);
if (status != STAT_SUCCESS) {
if (response) snmp_free_pdu(response);
snmp_close(peer);
return -2;
}
*upsBypassEntry = (upsBypassEntry_t *) malloc(sizeof(upsBypassEntry_t));
if (! *upsBypassEntry) {
if (response) snmp_free_pdu(response);
snmp_close(peer);
return -4;
}
for (vars = response->variables; vars; vars = vars->next_variable) {
if (vars->name_length > sizeof(upsBypassVoltage)/sizeof(oid)
&& memcmp(vars->name, upsBypassVoltage, sizeof(upsBypassVoltage)) == 0) {
(*upsBypassEntry)->__upsBypassVoltage = *vars->val.integer;
(*upsBypassEntry)->upsBypassVoltage = &((*upsBypassEntry)->__upsBypassVoltage);
}
if (vars->name_length > sizeof(upsBypassCurrent)/sizeof(oid)
&& memcmp(vars->name, upsBypassCurrent, sizeof(upsBypassCurrent)) == 0) {
(*upsBypassEntry)->__upsBypassCurrent = *vars->val.integer;
(*upsBypassEntry)->upsBypassCurrent = &((*upsBypassEntry)->__upsBypassCurrent);
}
if (vars->name_length > sizeof(upsBypassPower)/sizeof(oid)
&& memcmp(vars->name, upsBypassPower, sizeof(upsBypassPower)) == 0) {
(*upsBypassEntry)->__upsBypassPower = *vars->val.integer;
(*upsBypassEntry)->upsBypassPower = &((*upsBypassEntry)->__upsBypassPower);
}
}
if (response) snmp_free_pdu(response);
if (snmp_close(peer) == 0) {
return -5;
}
return 0;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:57,代码来源:rfc1628-mib-mgr.c
示例10: ups_mib_mgr_get_upsOutput
int ups_mib_mgr_get_upsOutput(struct snmp_session *s, upsOutput_t **upsOutput)
{
struct snmp_session *peer;
struct snmp_pdu *request, *response;
struct variable_list *vars;
int status;
request = snmp_pdu_create(SNMP_MSG_GETNEXT);
snmp_add_null_var(request, upsOutputSource, sizeof(upsOutputSource)/sizeof(oid));
snmp_add_null_var(request, upsOutputFrequency, sizeof(upsOutputFrequency)/sizeof(oid));
snmp_add_null_var(request, upsOutputNumLines, sizeof(upsOutputNumLines)/sizeof(oid));
peer = snmp_open(s);
if (!peer) {
return -1;
}
status = snmp_synch_response(peer, request, &response);
if (status != STAT_SUCCESS) {
if (response) snmp_free_pdu(response);
snmp_close(peer);
return -2;
}
*upsOutput = (upsOutput_t *) malloc(sizeof(upsOutput_t));
if (! *upsOutput) {
if (response) snmp_free_pdu(response);
snmp_close(peer);
return -4;
}
for (vars = response->variables; vars; vars = vars->next_variable) {
if (vars->name_length > sizeof(upsOutputSource)/sizeof(oid)
&& memcmp(vars->name, upsOutputSource, sizeof(upsOutputSource)) == 0) {
(*upsOutput)->__upsOutputSource = *vars->val.integer;
(*upsOutput)->upsOutputSource = &((*upsOutput)->__upsOutputSource);
}
if (vars->name_length > sizeof(upsOutputFrequency)/sizeof(oid)
&& memcmp(vars->name, upsOutputFrequency, sizeof(upsOutputFrequency)) == 0) {
(*upsOutput)->__upsOutputFrequency = *vars->val.integer;
(*upsOutput)->upsOutputFrequency = &((*upsOutput)->__upsOutputFrequency);
}
if (vars->name_length > sizeof(upsOutputNumLines)/sizeof(oid)
&& memcmp(vars->name, upsOutputNumLines, sizeof(upsOutputNumLines)) == 0) {
(*upsOutput)->__upsOutputNumLines = *vars->val.integer;
(*upsOutput)->upsOutputNumLines = &((*upsOutput)->__upsOutputNumLines);
}
}
if (response) snmp_free_pdu(response);
if (snmp_close(peer) == 0) {
return -5;
}
return 0;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:57,代码来源:rfc1628-mib-mgr.c
示例11: powernet_snmp_kill_ups_power
int powernet_snmp_kill_ups_power(UPSINFO *ups)
{
/* Was 1} change submitted by Kastus Shchuka ([email protected]) 10Dec03 */
oid upsBasicControlConserveBattery[] =
{ 1, 3, 6, 1, 4, 1, 318, 1, 1, 1, 6, 1, 1, 0 };
struct snmp_ups_internal_data *Sid =
(struct snmp_ups_internal_data *)ups->driver_internal_data;
struct snmp_session *s = &Sid->session;
struct snmp_session *peer;
struct snmp_pdu *request, *response;
int status;
/*
* Set up the SET request.
*/
request = snmp_pdu_create(SNMP_MSG_SET);
/*
* Set upsBasicControlConserveBattery variable (INTEGER) to
* turnOffUpsToConserveBattery(2) value. Will turn on the UPS only
* when power returns.
*/
if (snmp_add_var(request, upsBasicControlConserveBattery,
sizeof(upsBasicControlConserveBattery) / sizeof(oid), 'i', "2")) {
return 0;
}
peer = snmp_open(s);
if (!peer) {
Dmsg0(0, "Can not open the SNMP connection.\n");
return 0;
}
status = snmp_synch_response(peer, request, &response);
if (status != STAT_SUCCESS) {
Dmsg0(0, "Unable to communicate with UPS.\n");
return 0;
}
if (response->errstat != SNMP_ERR_NOERROR) {
Dmsg1(0, "Unable to kill UPS power: can not set SNMP variable (%d).\n", response->errstat);
return 0;
}
if (response)
snmp_free_pdu(response);
snmp_close(peer);
return 1;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:53,代码来源:drv_powernet.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: collect_mem
int collect_mem(netsnmp_session *ss, struct memStats *mem)
{
netsnmp_pdu *pdu;
netsnmp_pdu *response;
int status;
int ret = 0;
pdu = snmp_pdu_create(SNMP_MSG_GET);
add(pdu, "UCD-SNMP-MIB:memTotalSwap.0", NULL, 0);
add(pdu, "UCD-SNMP-MIB:memAvailSwap.0", NULL, 0);
add(pdu, "UCD-SNMP-MIB:memTotalReal.0", NULL, 0);
add(pdu, "UCD-SNMP-MIB:memAvailReal.0", NULL, 0);
add(pdu, "UCD-SNMP-MIB:memShared.0", NULL, 0);
add(pdu, "UCD-SNMP-MIB:memBuffer.0", NULL, 0);
add(pdu, "UCD-SNMP-MIB:memCached.0", NULL, 0);
status = snmp_synch_response(ss, pdu, &response);
memset(mem, 0, sizeof(*mem));
if (status != STAT_SUCCESS || !response ||
response->errstat != SNMP_ERR_NOERROR) {
goto out;
}
else {
netsnmp_variable_list *vlp = response->variables;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->totalSwap = *vlp->val.integer;
vlp = vlp->next_variable;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->availSwap = *vlp->val.integer;
vlp = vlp->next_variable;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->totalReal = *vlp->val.integer;
vlp = vlp->next_variable;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->availReal = *vlp->val.integer;
vlp = vlp->next_variable;
ret = 1;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->shared = *vlp->val.integer;
vlp = vlp->next_variable;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->buffer = *vlp->val.integer;
vlp = vlp->next_variable;
if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
mem->cached = *vlp->val.integer;
}
out:
if (response) snmp_free_pdu(response);
return ret;
}
开发者ID:michalklempa,项目名称:net-snmp,代码行数:52,代码来源:snmpps.c
示例15: perform_request
static std::unique_ptr<::snmp_pdu, pdu_deleter> perform_request(::snmp_session * session,
::snmp_pdu * request)
{
struct snmp_pdu * unsafe_response;
auto status = snmp_synch_response(session, request, &unsafe_response);
std::unique_ptr<::snmp_pdu, pdu_deleter> response(unsafe_response);
if (status != STAT_SUCCESS) throw snmp::session_error(session);
if (response->errstat != SNMP_ERR_NOERROR) throw snmp::protocol_error(response->errstat);
return response;
}
开发者ID:solatis,项目名称:qdb-benchmark,代码行数:13,代码来源:session.cpp
示例16: 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
示例17: MPC_write
/*
* write value of given oid
*/
static int
MPC_write(struct snmp_session *sptr, const char *objname, char type,
char *value)
{
oid name[MAX_OID_LEN];
size_t namelen = MAX_OID_LEN;
struct snmp_pdu *pdu;
struct snmp_pdu *resp;
DEBUGCALL;
/* convert objname into oid; return FALSE if invalid */
if (!read_objid(objname, name, &namelen)) {
LOG(PIL_CRIT, "%s: cannot convert %s to oid.", __FUNCTION__, objname);
return (FALSE);
}
/* create pdu */
if ((pdu = snmp_pdu_create(SNMP_MSG_SET)) != NULL) {
/* add to be written value to pdu */
snmp_add_var(pdu, name, namelen, type, value);
/* send pdu and get response; return NULL if error */
if (snmp_synch_response(sptr, pdu, &resp) == STAT_SUCCESS) {
/* go through the returned vars */
if (resp->errstat == SNMP_ERR_NOERROR) {
/* request successful done */
snmp_free_pdu(resp);
return (TRUE);
} else {
LOG(PIL_CRIT, "%s: error in response packet, reason %ld [%s]."
, __FUNCTION__, resp->errstat, snmp_errstring(resp->errstat));
}
} else {
MPC_error(sptr, __FUNCTION__, "error sending/receiving pdu");
}
/* free pdu (again: necessary?) */
snmp_free_pdu(resp);
} else {
MPC_error(sptr, __FUNCTION__, "cannot create pdu");
}
/* error */
return (FALSE);
}
开发者ID:ingted,项目名称:cluster-glue,代码行数:51,代码来源:wti_mpc.c
示例18: 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
示例19: throw
QtNetSNMP::SNMPPDU *QtNetSNMP::QSNMPCore::sendPDU(SNMPSession *session, SNMPPDU *pdu) throw(QSNMPException)
{
SNMPPDU *response;
int status;
status = snmp_synch_response(session, pdu, &response);
if(status == STAT_SUCCESS)
if(response -> errstat == SNMP_ERR_NOERROR)
return response;
else
throw QSNMPException("QSNMPCore :: Send PDU :: Responde PDU has errors");
else if(status == STAT_TIMEOUT)
throw QSNMPException("QSNMPCore :: Send PDU :: Timeout. No response from agent");
else
throw QSNMPException("QSNMPCore :: Send PDU :: SNMP Session error");
}
开发者ID:dsilvan,项目名称:qt-net-snmp,代码行数:17,代码来源:qsnmpcore.cpp
示例20: mau_mib_mgr_get_ifJackEntry
int mau_mib_mgr_get_ifJackEntry(struct snmp_session *s, ifJackEntry_t **ifJackEntry)
{
struct snmp_session *peer;
struct snmp_pdu *request, *response;
struct variable_list *vars;
int status;
request = snmp_pdu_create(SNMP_MSG_GETNEXT);
snmp_add_null_var(request, ifJackType, sizeof(ifJackType)/sizeof(oid));
peer = snmp_open(s);
if (!peer) {
snmp_free_pdu(request);
return -1;
}
status = snmp_synch_response(peer, request, &response);
if (status != STAT_SUCCESS) {
if (response) snmp_free_pdu(response);
snmp_close(peer);
return -2;
}
*ifJackEntry = (ifJackEntry_t *) malloc(sizeof(ifJackEntry_t));
if (! *ifJackEntry) {
if (response) snmp_free_pdu(response);
snmp_close(peer);
return -4;
}
for (vars = response->variables; vars; vars = vars->next_variable) {
if (vars->name_length > sizeof(ifJackType)/sizeof(oid)
&& memcmp(vars->name, ifJackType, sizeof(ifJackType)) == 0) {
(*ifJackEntry)->__ifJackType = *vars->val.integer;
(*ifJackEntry)->ifJackType = &((*ifJackEntry)->__ifJackType);
}
}
if (response) snmp_free_pdu(response);
if (snmp_close(peer) == 0) {
return -5;
}
return 0;
}
开发者ID:pan0007,项目名称:libsmi,代码行数:46,代码来源:mau-mib-mgr-stub.c
注:本文中的snmp_synch_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论