当前位置: 首页>>代码示例>>C++>>正文


C++ snmp_errstring函数代码示例

本文整理汇总了C++中snmp_errstring函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_errstring函数的具体用法?C++ snmp_errstring怎么用?C++ snmp_errstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了snmp_errstring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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

示例2: perr

void perr(struct snmp_pdu *resp) {
    if(resp) fprintf(stderr, "error: %s\n", snmp_errstring(resp->errstat));
    snmp_perror("error");
    snmp_close(ses);
    SOCK_CLEANUP;
    exit(1);
}
开发者ID:xiongshaogang,项目名称:NetAndSysMonitor,代码行数:7,代码来源:ttg-snmp.cpp

示例3: 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

示例4: snmpStoreResult

/*
 * simple printing of returned data
 */
int snmpStoreResult (tSession *session, struct snmp_pdu *pdu, char **result)
{
	char buf[RESULTSIZE];
	struct variable_list *vp;
	struct snmp_session *sp = session->sess;
	unsigned int o = session->current_oid;
	unsigned int i,j;

	*result = (char*)calloc(RESULTSIZE+1, sizeof(char));

	vp = pdu->variables;
	if (pdu->errstat == SNMP_ERR_NOERROR) {
		while (vp) {
			snprint_value(*result, RESULTSIZE, vp->name, vp->name_length, vp);

			// tolower & remove spaces and linebreaks
			for (i=0, j=0; i<strlen(*result); i++) {
				if ((*result)[i] > 0x22) {
					if ((*result)[i] >= 0x41 && (*result)[i] <= 0x5A) {
						(*result)[j] = (*result)[i] + 0x20;
					} else {
						(*result)[j] = (*result)[i];
					}
					j++;
				}
			}
			(*result)[j] = 0;

			// fix lancom snr
			if (session->oidList.oid[o].id_oidtype == 12 &&
				( session->oidList.oid[o].id_type == 2 ||
  				session->oidList.oid[o].id_type == 5 ||
  				session->oidList.oid[o].id_type == 9 ||
  				session->oidList.oid[o].id_type == 24 )) {
				snprintf(*result, RESULTSIZE, "%.0f", atoi(*result) * 0.64);
			}

			snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp);
			syslog(LOG_DEBUG, "snmpStoreResult: %s: %s", sp->peername, buf);
			vp = vp->next_variable;
		}
		return 1;
	} else {
		if (vp) {
			snprint_objid(buf, sizeof(buf), vp->name, vp->name_length);
		} else {
			strcpy(buf, "(empty buf)");
		}

		syslog(LOG_ERR, "snmpStoreResult: %s: %s: (%s)", sp->peername, buf, snmp_errstring(pdu->errstat));

		if (pdu->errstat == SNMP_ERR_NOSUCHNAME) {
			snprintf(*result, RESULTSIZE, "U");
			return 1;
		}

		return 0;
	}
}
开发者ID:fbn-dd,项目名称:netplan,代码行数:62,代码来源:snmp.c

示例5: 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

示例6: 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

示例7: return_data

int return_data(int status, struct snmp_session *sp, struct snmp_pdu *pdu)
{
  char buf[1024];
  struct variable_list *vp;
  int ix;
  char *getdata = NULL;
 
  switch (status) {
  case STAT_SUCCESS:
    vp = pdu->variables;
    if (pdu->errstat == SNMP_ERR_NOERROR) {
      while (vp) {
	snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp);
	/*mjpark------------------------------------------*/
	getdata = (char *)malloc(1 + vp->val_len);
	memcpy(getdata, vp->val.string, vp->val_len);
	getdata[vp->val_len] = '\0';
#if 0
	//Data over flow...
	int nVal;
	memcpy((void *)&nVal, getdata, 4);
#else
	unsigned long int nVal;
	memcpy((void *)&nVal, getdata, sizeof(unsigned long int));
#endif
	gpSnmp->val = nVal;

	//debug print
	/* printf("data length(%d), unsigned long int size(%d), int(%d)\n",vp->val_len, sizeof(unsigned long int), sizeof(int)); */
	printf("snmpVal(%d), psnmp(%p)\n", nVal, gpSnmp);
	/*------------------------------------------------*/
	vp = vp->next_variable;
      }
      free(getdata);
    }
    else {
      for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++);
      if (vp)
	snprint_objid(buf, sizeof(buf), vp->name, vp->name_length);
      else
	strcpy(buf, "(none)");
      fprintf(stdout, "%s: %s: %s\n", sp->peername, buf, snmp_errstring(pdu->errstat));
    }
    return 1;
  case STAT_TIMEOUT:
    fprintf(stdout, "%s: Timeout\n", sp->peername);
    return 0;
  
  case STAT_ERROR:
    snmp_perror(sp->peername);
    return 0;
  }
  return 0;
}
开发者ID:RaonControl,项目名称:siteLibs,代码行数:54,代码来源:snmpAsync_v3_problem.c

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: snmp_get_nextif

static int snmp_get_nextif(struct snmp_session *ss, int index) {
  oid ifindex[] = { 1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 0 };
  int len = sizeof(ifindex) / sizeof(oid);
  struct snmp_pdu *pdu;
  struct snmp_pdu *response = NULL;
  struct variable_list *vars;
  int status;

  if (index >= 0)
    ifindex[len - 1] = index;

  if ((pdu = snmp_pdu_create(SNMP_MSG_GETNEXT)) == NULL) {
    ifstat_error("snmp_pdu_create: %s", snmp_api_errstring(snmp_errno));
    return -1;
  }

  snmp_add_null_var(pdu, ifindex, (index < 0) ? len - 1 : len);

  if ((status = snmp_synch_response(ss, pdu, &response)) != STAT_SUCCESS ||
      response->errstat != SNMP_ERR_NOERROR ||
      response->variables == NULL) {
    if (status == STAT_SUCCESS) 
      ifstat_error("snmp: Error: %s", snmp_errstring(response->errstat));
    else
      ifstat_error("snmpgetnext(interfaces.ifTable.ifEntry.ifIndex...): %s",
		   snmp_sess_errstring(ss));
    if (response != NULL)
      snmp_free_pdu(response);
    return -1;
  }

  for(vars = response->variables; vars; vars = vars->next_variable) {
    /* check that the variable is under the base oid */
    if (vars->name_length != len)
      continue;
    if (memcmp(ifindex, vars->name, sizeof(ifindex) - sizeof(oid)) != 0)
      continue;

    index = vars->name[vars->name_length - 1];
    snmp_free_pdu(response);
    return index;
  }
  snmp_free_pdu(response);
  return -1;
}
开发者ID:RaonControl,项目名称:siteApps,代码行数:45,代码来源:snmp.c


注:本文中的snmp_errstring函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。