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


C++ snmp_perror函数代码示例

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


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

示例1: snmp_set

/**
 * The 'raw' SNMP set function. It should not be used directly in external
 * files. Rather, a non-static wrapper function should be created here that
 * makes the appropriate call in order to preserve source code readability.
 *
 * @return 1 if successful, 0 if not
 */
static int snmp_set(netsnmp_session *s, char *oid_str, char type, const char *val)
{
	netsnmp_pdu *pdu;
	oid the_oid[MAX_OID_LEN];
	size_t oid_len;

	pdu = snmp_pdu_create(SNMP_MSG_SET);
	oid_len = MAX_OID_LEN;

	// Parse the OID
	if (snmp_parse_oid(oid_str, the_oid, &oid_len) == 0) {
		snmp_perror(oid_str);
		return 0;
	}

	// Build the packet to be sent
	if (snmp_add_var(pdu, the_oid, oid_len, type, val) != 0) {
		printf("type: %c, val: %s, oid_str: %s\n", type, val, oid_str);
		snmp_perror("SNMP: Could not add var!");
		return 0;
	}

	// Send the request
	if (snmp_send(s, pdu) == 0) {
		snmp_perror("SNMP: Error while sending!");
		snmp_free_pdu(pdu);
		return 0;
	}

	return 1;
}
开发者ID:limasierra,项目名称:SatelliteConnectionMonitor,代码行数:38,代码来源:snmplib.c

示例2: set_snmp

int set_snmp(void *precord, const char *sval)
{
  snmpRecord *psnmp = (snmpRecord *)precord;
  SNMP_INFO *snmpinfo = (SNMP_INFO*)psnmp->dpvt;

  char type = 'i';

  if (!(snmpinfo->sess = snmp_open(&snmpinfo->ss))) {
    snmp_perror("snmp_open");
    return -1;
  };

  snmpinfo->setreq = snmp_pdu_create(SNMP_MSG_SET);	/* send the first GET */
  if (! snmpinfo->setreq) {
    snmp_close(snmpinfo->sess);                 /* cleanup */
    return -1;
  }

  snmp_add_var(snmpinfo->setreq, snmpinfo->oid_info.Oid, snmpinfo->oid_info.OidLen, type, sval);       //snmp_add_var(netsnmp_pdu *, const oid *, size_t, char, const char *)

  if (snmp_send(snmpinfo->sess, snmpinfo->setreq))
    hosts++;
  else {
    snmp_perror("snmp_getsend");
    snmp_free_pdu(snmpinfo->setreq);
    return -1;
  }

  active_hosts();
  snmp_close(snmpinfo->sess);                 /* cleanup */
  return 0;
}
开发者ID:RaonControl,项目名称:siteLibs,代码行数:32,代码来源:snmpDevAsync_onlyint.c

示例3: get_snmp

void get_snmp(void *precord)
{
  snmpRecord *psnmp = (snmpRecord *)precord;
  SNMP_INFO *snmpinfo = (SNMP_INFO*)psnmp->dpvt;

  if (!(snmpinfo->sess = snmp_open(&snmpinfo->ss))) {
    snmp_perror("snmp_open");
  };

  snmpinfo->getreq = snmp_pdu_create(SNMP_MSG_GET);	/* send the first GET */
  if (! snmpinfo->getreq) {
    snmp_close(snmpinfo->sess);                 /* cleanup */
  }

  snmp_add_null_var(snmpinfo->getreq, snmpinfo->oid_info.Oid, snmpinfo->oid_info.OidLen);

  if (snmp_send(snmpinfo->sess, snmpinfo->getreq))
    hosts++;
  else {
    snmp_perror("snmp_setsend");
    snmp_free_pdu(snmpinfo->getreq);
  }

  active_hosts();
  snmp_close(snmpinfo->sess);                 /* cleanup */
}
开发者ID:RaonControl,项目名称:siteLibs,代码行数:26,代码来源:snmpDevAsync_onlyint.c

示例4: setupmib

/* 
 * This routine loads MIB files, and computes the key-OID values.
 * We defer this until the mib-definition is actually being referred to 
 * in snmphosts.cfg, because lots of MIB's are not being used
 * (and probably do not exist on the host where we're running) and
 * to avoid spending a lot of time to load MIB's that are not used.
 */
void setupmib(mibdef_t *mib, int verbose)
{
	mibidx_t *iwalk;
	size_t sz, len;

	if (mib->loadstatus != MIB_STATUS_NOTLOADED) return;

	if (mib->mibfn && (read_mib(mib->mibfn) == NULL)) {
		mib->loadstatus = MIB_STATUS_LOADFAILED;
		if (verbose) {
			errprintf("Failed to read MIB file %s\n", mib->mibfn);
			snmp_perror("read_objid");
		}
	}

	for (iwalk = mib->idxlist; (iwalk); iwalk = iwalk->next) {
		iwalk->rootoid = calloc(MAX_OID_LEN, sizeof(oid));
		iwalk->rootoidlen = MAX_OID_LEN;
		if (read_objid(iwalk->keyoid, iwalk->rootoid, &iwalk->rootoidlen)) {
			/* Re-use the iwalk->keyoid buffer */
			sz = strlen(iwalk->keyoid) + 1; len = 0;
			sprint_realloc_objid((unsigned char **)&iwalk->keyoid, &sz, &len, 1, iwalk->rootoid, iwalk->rootoidlen);
		}
		else {
			mib->loadstatus = MIB_STATUS_LOADFAILED;
			if (verbose) {
				errprintf("Cannot determine OID for %s\n", iwalk->keyoid);
				snmp_perror("read_objid");
			}
		}
	}

	mib->loadstatus = MIB_STATUS_LOADED;
}
开发者ID:gvsurenderreddy,项目名称:xymon-2,代码行数:41,代码来源:xymon-snmpcollect.c

示例5: asynchronous

void asynchronous(void)
{
  struct session *hs;
  struct host *hp;

  /* startup all hosts */

  for (hs = sessions, hp = hosts; hp->name; hs++, hp++) {
    struct snmp_pdu *req;
    struct snmp_session sess;
    snmp_sess_init(&sess);			/* initialize session */
    sess.version = SNMP_VERSION_2c;
    sess.peername = strdup(hp->name);
    sess.community = strdup(hp->community);
    sess.community_len = strlen(sess.community);
    sess.callback = asynch_response;		/* default callback */
    sess.callback_magic = hs;
    if (!(hs->sess = snmp_open(&sess))) {
      snmp_perror("snmp_open");
      continue;
    }
    hs->current_oid = oids;
    req = snmp_pdu_create(SNMP_MSG_GET);	/* send the first GET */
    snmp_add_null_var(req, hs->current_oid->Oid, hs->current_oid->OidLen);
    if (snmp_send(hs->sess, req))
      active_hosts++;
    else {
      snmp_perror("snmp_send");
      snmp_free_pdu(req);
    }
  }

  /* loop while any active hosts */

  while (active_hosts) {
    int fds = 0, block = 1;
    fd_set fdset;
    struct timeval timeout;

    FD_ZERO(&fdset);
    snmp_select_info(&fds, &fdset, &timeout, &block);
    fds = select(fds, &fdset, NULL, NULL, block ? NULL : &timeout);
    if (fds < 0) {
        perror("select failed");
        exit(1);
    }
    if (fds)
        snmp_read(&fdset);
    else
        snmp_timeout();
  }

  /* cleanup */

  for (hp = hosts, hs = sessions; hp->name; hs++, hp++) {
    if (hs->sess) snmp_close(hs->sess);
  }
}
开发者ID:dear531,项目名称:snmp_source,代码行数:58,代码来源:asyncapp.c

示例6: sh_count_regexp_procs

int
sh_count_regexp_procs(char *procname, pcre *regexp)
{
    int             fd, total = 0;
    struct psinfo   info;
    char            fbuf[32];
    struct dirent  *ent;
    DIR            *dir;

    if (!(dir = opendir("/proc"))) {
        snmp_perror("/proc");
        return -1;
    }

    while ((ent = readdir(dir))) {
        if (!strcmp(ent->d_name, "..") || !strcmp(ent->d_name, "."))
            continue;

        snprintf(fbuf, sizeof fbuf, "/proc/%s/psinfo", ent->d_name);
        if ((fd = open(fbuf, O_RDONLY)) < 0) {  /* Continue or return error? */
            snmp_perror(fbuf);
	    continue;
        }

        if (read(fd, (char *) &info, sizeof(struct psinfo)) !=
            sizeof(struct psinfo)) {
            snmp_perror(fbuf);
            close(fd);
            closedir(dir);
            return -1;
        }

        if (!info.pr_nlwp && !info.pr_lwp.pr_lwpid) {
            /*
             * Zombie process 
             */
        } else {
            DEBUGMSGTL(("proc","Comparing wanted %s against %s\n",
                        procname, info.pr_fname));
            if (!strcmp(procname, info.pr_fname)) {
                total++;
                DEBUGMSGTL(("proc", " Matched.  total count now=%d\n", total));
            }
        }

        close(fd);
    }
    closedir(dir);
    return total;
}
开发者ID:ClydeFroq,项目名称:sipxecs,代码行数:50,代码来源:regexp_proc.c

示例7: send_trap_pdu

void
send_trap_pdu(struct snmp_pdu *pdu)
{
  struct snmp_pdu *mypdu;
  
  struct trap_sink *sink = sinks;

  if ((snmp_enableauthentraps == 1) && sink != NULL) {
    DEBUGMSGTL(("snmpd", "sending v2 trap pdu...\n"));
    while (sink) {
      if (sink->ses.version == SNMP_VERSION_2c) {
        DEBUGMSGTL(("snmpd", " found v2 session...\n"));
        mypdu = snmp_clone_pdu(pdu);
        if (snmp_send(sink->sesp, mypdu) == 0) {
          snmp_perror ("snmpd: send_trap_pdu");
        }
#ifdef USING_MIBII_SNMP_MIB_MODULE       
        snmp_outtraps++;
#endif
      }
      sink = sink->next;
    }
    DEBUGMSGTL(("snmpd", "  done\n"));
  }
}
开发者ID:Einheri,项目名称:wl500g,代码行数:25,代码来源:snmpd.c

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

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

示例10: sysctl_read_icmp6_msg_stat

int
sysctl_read_icmp6_msg_stat(struct icmp6_mib *mib,
                           struct icmp6_msg_mib *msgmib,
			   int *support)
{
    struct icmp6stat icmpstat;
    size_t   size = sizeof(icmpstat);
    int      i;
    static int      sname[4] =
        { CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_STATS };

    sysctl_read_icmp6_stat(mib);

    if (-1 == sysctl(sname, 4, &icmpstat, &size, NULL, 0)) {
	snmp_perror("sysctl_read_icmp6_stat: net.inet6.icmp6.stats");
        return -1;
    }

    for (i = 0; i < 256; i++) {
	msgmib->vals[i].InType = icmpstat.icp6s_inhist[i];
	msgmib->vals[i].OutType = icmpstat.icp6s_outhist[i];
    }
    *support = 1;
    return 0;
}
开发者ID:ClausKlein,项目名称:net-snmp,代码行数:25,代码来源:kernel_sysctl.c

示例11: asynch_response

/*
 * response handler
 */
int asynch_response(int operation, struct snmp_session *sp, int reqid,
		    struct snmp_pdu *pdu, void *magic)
{
  struct session *host = (struct session *)magic;
  struct snmp_pdu *req;

  if (operation == NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) {
    if (print_result(STAT_SUCCESS, host->sess, pdu)) {
      host->current_oid++;			/* send next GET (if any) */
      if (host->current_oid->Name) {
	req = snmp_pdu_create(SNMP_MSG_GET);
	snmp_add_null_var(req, host->current_oid->Oid, host->current_oid->OidLen);
	if (snmp_send(host->sess, req))
	  return 1;
	else {
	  snmp_perror("snmp_send");
	  snmp_free_pdu(req);
	}
      }
    }
  }
  else
    print_result(STAT_TIMEOUT, host->sess, pdu);

  /* something went wrong (or end of variables) 
   * this host not active any more
   */
  active_hosts--;
  return 1;
}
开发者ID:dear531,项目名称:snmp_source,代码行数:33,代码来源:asyncapp.c

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

示例13: add

int
add(netsnmp_pdu *pdu, const char *mibnodename,
    oid * index, size_t indexlen)
{
    oid             base[MAX_OID_LEN];
    size_t          base_length = MAX_OID_LEN;

    memset(base, 0, MAX_OID_LEN * sizeof(oid));

    if (!snmp_parse_oid(mibnodename, base, &base_length)) {
        snmp_perror(mibnodename);
        fprintf(stderr, "couldn't find mib node %s, giving up\n",
                mibnodename);
#if HAVE_CURSES_H
        endwin();
#endif
        exit(1);
    }

    if (index && indexlen) {
        memcpy(&(base[base_length]), index, indexlen * sizeof(oid));
        base_length += indexlen;
    }
    DEBUGMSGTL(("add", "created: "));
    DEBUGMSGOID(("add", base, base_length));
    DEBUGMSG(("add", "\n"));
    snmp_add_null_var(pdu, base, base_length);

    return base_length;
}
开发者ID:michalklempa,项目名称:net-snmp,代码行数:30,代码来源:snmpps.c

示例14: netbsd_read_icmp6_stat

int
netbsd_read_icmp6_stat(struct icmp6_mib *mib)
{
    uint64_t icmpstat[ICMP6_NSTATS];
    size_t   size = sizeof(icmpstat);
    int      i;

    (void)memset(mib, 0, sizeof(*mib));

    if (-1 == sysctlbyname("net.inet6.icmp6.stats", icmpstat, &size, NULL, 0)) {
	snmp_perror("netbsd_read_icmp6_stat: net.inet6.icmp6.stats");
        return -1;
    }

    mib->icmp6InMsgs = icmpstat[ICMP6_STAT_BADCODE]
            + icmpstat[ICMP_STAT_TOOSHORT]
	    + icmpstat[ICMP_STAT_CHECKSUM]
            + icmpstat[ICMP_STAT_BADLEN];
    for (i = 0; i <= ICMP6_MAXTYPE; i++)
        mib->icmp6InMsgs  += icmpstat[ICMP6_STAT_INHIST + i];
    mib->icmp6InErrors = icmpstat[ICMP6_STAT_BADCODE]
        + icmpstat[ICMP6_STAT_TOOSHORT]
        + icmpstat[ICMP6_STAT_CHECKSUM]
        + icmpstat[ICMP6_STAT_BADLEN];
    mib->icmp6InDestUnreachs = icmpstat[ICMP6_STAT_INHIST + ICMP6_DST_UNREACH];
    mib->icmp6InPktTooBigs = icmpstat[ICMP6_STAT_INHIST + ICMP6_PACKET_TOO_BIG];
    mib->icmp6InTimeExcds = icmpstat[ICMP6_STAT_INHIST + ICMP6_TIME_EXCEEDED];
    mib->icmp6InParmProblems = icmpstat[ICMP6_STAT_INHIST + ICMP6_PARAM_PROB];
    mib->icmp6InEchos = icmpstat[ICMP6_STAT_INHIST + ICMP6_ECHO_REQUEST];
    mib->icmp6InEchoReplies = icmpstat[ICMP6_STAT_INHIST + ICMP6_ECHO_REPLY];
    mib->icmp6InGroupMembQueries = icmpstat[ICMP6_STAT_INHIST + MLD_LISTENER_QUERY];
    mib->icmp6InGroupMembResponses = icmpstat[ICMP6_STAT_INHIST + MLD_LISTENER_REPORT];
    mib->icmp6InRouterSolicits = icmpstat[ICMP6_STAT_INHIST + ND_ROUTER_SOLICIT];
    mib->icmp6InRouterAdvertisements = icmpstat[ICMP6_STAT_INHIST + ND_ROUTER_ADVERT];
    mib->icmp6InNeighborSolicits = icmpstat[ICMP6_STAT_INHIST + ND_NEIGHBOR_SOLICIT];
    mib->icmp6InNeighborAdvertisements = icmpstat[ICMP6_STAT_INHIST + ND_NEIGHBOR_ADVERT];
    mib->icmp6InRedirects = icmpstat[ICMP6_STAT_INHIST + ND_REDIRECT];

    mib->icmp6OutMsgs = icmpstat[ICMP6_STAT_BADCODE]
        + icmpstat[ICMP6_STAT_TOOSHORT]
        + icmpstat[ICMP6_STAT_CHECKSUM]
        + icmpstat[ICMP6_STAT_BADLEN];
    for (i = 0; i <= ICMP6_MAXTYPE; i++)
        mib->icmp6OutMsgs += icmpstat[ICMP6_STAT_OUTHIST + i];
    mib->icmp6OutDestUnreachs = icmpstat[ICMP6_STAT_OUTHIST + ICMP6_DST_UNREACH];
    mib->icmp6OutPktTooBigs =  icmpstat[ICMP6_STAT_OUTHIST + ICMP6_PACKET_TOO_BIG];
    mib->icmp6OutTimeExcds = icmpstat[ICMP6_STAT_OUTHIST + ICMP6_TIME_EXCEEDED];
    mib->icmp6OutParmProblems = icmpstat[ICMP6_STAT_OUTHIST + ICMP6_PARAM_PROB];
    mib->icmp6OutEchos = icmpstat[ICMP6_STAT_OUTHIST + ICMP6_ECHO_REQUEST];
    mib->icmp6OutEchoReplies = icmpstat[ICMP6_STAT_OUTHIST + ICMP6_ECHO_REPLY];
    mib->icmp6OutRouterSolicits =  icmpstat[ICMP6_STAT_OUTHIST + ND_ROUTER_SOLICIT];
    mib->icmp6OutNeighborSolicits =  icmpstat[ICMP6_STAT_OUTHIST + ND_NEIGHBOR_SOLICIT];
    mib->icmp6OutNeighborAdvertisements =  icmpstat[ICMP6_STAT_OUTHIST + ND_NEIGHBOR_ADVERT];
    mib->icmp6OutRedirects = icmpstat[ICMP6_STAT_OUTHIST + ND_REDIRECT];
    mib->icmp6OutGroupMembResponses =  icmpstat[ICMP6_STAT_OUTHIST + MLD_LISTENER_REPORT];
    mib->icmp6OutGroupMembReductions =  icmpstat[ICMP6_STAT_OUTHIST + MLD_LISTENER_DONE];

    return 0;
}
开发者ID:ClausKlein,项目名称:net-snmp,代码行数:59,代码来源:kernel_netbsd.c

示例15: snmp_get

void snmp_get(void *precord)
{
  snmpRecord *psnmp = (snmpRecord *)precord;
  /* SNMP_INFO *gsnmpInfo = (SNMP_INFO*)psnmp->dpvt;       */

  printf("snmpget()****** Message:%s, version: %s, ip: %s, name: %s, securityname: %s, authpass: %s, privpass: %s, secuauth: %s, secupriv: %s\n", snmpinfo->msg, snmpinfo->ss.version, snmpinfo->ss.peername, snmpinfo->username, snmpinfo->ss.securityName, snmpinfo->authpass, snmpinfo->privpass, snmpinfo->ss.securityAuthKey, snmpinfo->ss.securityPrivKey);

  printf("oids: %s\n", psnmp->oids);

  if (!(snmpinfo->sess = snmp_open(&snmpinfo->ss))) {
    snmp_perror("snmp_open");
  };

  snmpinfo->getreq = snmp_pdu_create(SNMP_MSG_GET);	/* send the first GET */
  if (! snmpinfo->getreq) {
    snmp_close(snmpinfo->sess);                 /* cleanup */
  }

  snmp_add_null_var(snmpinfo->getreq, snmpinfo->oid_info.Oid, snmpinfo->oid_info.OidLen);

/* int snmp_async_send(netsnmp_session *, netsnmp_pdu *, netsnmp_callback, void *) */
/* int snmp_send(netsnmp_session *, netsnmp_pdu *) */


  /* if (snmp_async_send(snmpinfo->sess, snmpinfo->getreq, asynch_response, NULL))   */
  /*   { */
  /*     hosts++; */
  /*   } else { */
  /*   snmp_perror("snmp_get->async_Send Error "); */
  /*   snmp_free_pdu(snmpinfo->getreq); */
  /* } */


  if (snmp_send(snmpinfo->sess, snmpinfo->getreq))
    {
      hosts++;
    } else {
    snmp_perror("snmp_get->Send Error ");
    snmp_free_pdu(snmpinfo->getreq);
  }



  active_hosts();
  snmp_close(snmpinfo->sess);                 /* cleanup */
}
开发者ID:RaonControl,项目名称:siteLibs,代码行数:46,代码来源:snmpAsync_v3_problem.c


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