本文整理汇总了C++中snmp_perror函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_perror函数的具体用法?C++ snmp_perror怎么用?C++ snmp_perror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmp_perror函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: netbsd_read_icmp_stat
int
netbsd_read_icmp_stat(struct icmp_mib *mib)
{
uint64_t icmpstat[ICMP_NSTATS];
size_t size = sizeof(icmpstat);
int i;
(void)memset(mib, 0, sizeof(*mib));
if (-1 == sysctlbyname("net.inet.icmp.stats", icmpstat, &size, NULL, 0)) {
snmp_perror("netbsd_read_icmp_stat: net.inet.icmp.stats");
return -1;
}
mib->icmpInMsgs = icmpstat[ICMP_STAT_BADCODE]
+ icmpstat[ICMP_STAT_TOOSHORT]
+ icmpstat[ICMP_STAT_CHECKSUM]
+ icmpstat[ICMP_STAT_BADLEN];
for (i = 0; i <= ICMP_MAXTYPE; i++)
mib->icmpInMsgs += icmpstat[ICMP_STAT_INHIST + i];
mib->icmpInErrors = icmpstat[ICMP_STAT_BADCODE]
+ icmpstat[ICMP_STAT_TOOSHORT]
+ icmpstat[ICMP_STAT_CHECKSUM]
+ icmpstat[ICMP_STAT_BADLEN];
mib->icmpInDestUnreachs = icmpstat[ICMP_STAT_INHIST + ICMP_UNREACH];
mib->icmpInTimeExcds = icmpstat[ICMP_STAT_INHIST + ICMP_TIMXCEED];
mib->icmpInParmProbs = icmpstat[ICMP_STAT_INHIST + ICMP_PARAMPROB];
mib->icmpInSrcQuenchs = icmpstat[ICMP_STAT_INHIST + ICMP_SOURCEQUENCH];
mib->icmpInRedirects = icmpstat[ICMP_STAT_INHIST + ICMP_REDIRECT];
mib->icmpInEchos = icmpstat[ICMP_STAT_INHIST + ICMP_ECHO];
mib->icmpInEchoReps = icmpstat[ICMP_STAT_INHIST + ICMP_ECHOREPLY];
mib->icmpInTimestamps = icmpstat[ICMP_STAT_INHIST + ICMP_TSTAMP];
mib->icmpInTimestampReps
= icmpstat[ICMP_STAT_INHIST + ICMP_TSTAMPREPLY];
mib->icmpInAddrMasks = icmpstat[ICMP_STAT_INHIST + ICMP_MASKREQ];
mib->icmpInAddrMaskReps = icmpstat[ICMP_STAT_INHIST + ICMP_MASKREPLY];
mib->icmpOutMsgs = icmpstat[ICMP_STAT_OLDSHORT]
+ icmpstat[ICMP_STAT_OLDICMP];
for (i = 0; i <= ICMP_MAXTYPE; i++)
mib->icmpOutMsgs += icmpstat[ICMP_STAT_OUTHIST + i];
mib->icmpOutErrors = icmpstat[ICMP_STAT_OLDSHORT]
+ icmpstat[ICMP_STAT_OLDICMP];
mib->icmpOutDestUnreachs = icmpstat[ICMP_STAT_OUTHIST + ICMP_UNREACH];
mib->icmpOutTimeExcds = icmpstat[ICMP_STAT_OUTHIST + ICMP_TIMXCEED];
mib->icmpOutParmProbs = icmpstat[ICMP_STAT_OUTHIST + ICMP_PARAMPROB];
mib->icmpOutSrcQuenchs
= icmpstat[ICMP_STAT_OUTHIST + ICMP_SOURCEQUENCH];
mib->icmpOutRedirects = icmpstat[ICMP_STAT_OUTHIST + ICMP_REDIRECT];
mib->icmpOutEchos = icmpstat[ICMP_STAT_OUTHIST + ICMP_ECHO];
mib->icmpOutEchoReps = icmpstat[ICMP_STAT_OUTHIST + ICMP_ECHOREPLY];
mib->icmpOutTimestamps = icmpstat[ICMP_STAT_OUTHIST + ICMP_TSTAMP];
mib->icmpOutTimestampReps
= icmpstat[ICMP_STAT_OUTHIST + ICMP_TSTAMPREPLY];
mib->icmpOutAddrMasks = icmpstat[ICMP_STAT_OUTHIST + ICMP_MASKREQ];
mib->icmpOutAddrMaskReps = icmpstat[ICMP_STAT_OUTHIST + ICMP_MASKREPLY];
return 0;
}
开发者ID:ClausKlein,项目名称:net-snmp,代码行数:58,代码来源:kernel_netbsd.c
示例17: sysctl_read_icmp6_stat
int
sysctl_read_icmp6_stat(struct icmp6_mib *mib)
{
struct icmp6stat icmpstat;
size_t size = sizeof(icmpstat);
int i;
static int sname[4] =
{ CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_STATS };
(void)memset(mib, 0, sizeof(*mib));
if (-1 == sysctl(sname, 4, &icmpstat, &size, NULL, 0)) {
snmp_perror("sysctl_read_icmp6_stat: net.inet6.icmp6.stats");
return -1;
}
mib->icmp6InMsgs = icmpstat.icp6s_badcode
+ icmpstat.icp6s_tooshort
+ icmpstat.icp6s_checksum
+ icmpstat.icp6s_badlen;
mib->icmp6InErrors = mib->icmp6InMsgs;
for (i = 0; i <= ICMP6_MAXTYPE; i++)
mib->icmp6InMsgs += icmpstat.icp6s_inhist[i];
mib->icmp6InDestUnreachs = icmpstat.icp6s_inhist[ICMP6_DST_UNREACH];
mib->icmp6InPktTooBigs = icmpstat.icp6s_inhist[ICMP6_PACKET_TOO_BIG];
mib->icmp6InTimeExcds = icmpstat.icp6s_inhist[ICMP6_TIME_EXCEEDED];
mib->icmp6InParmProblems = icmpstat.icp6s_inhist[ICMP6_PARAM_PROB];
mib->icmp6InEchos = icmpstat.icp6s_inhist[ICMP6_ECHO_REQUEST];
mib->icmp6InEchoReplies = icmpstat.icp6s_inhist[ICMP6_ECHO_REPLY];
mib->icmp6InGroupMembQueries = icmpstat.icp6s_inhist[MLD_LISTENER_QUERY];
mib->icmp6InGroupMembResponses = icmpstat.icp6s_inhist[MLD_LISTENER_REPORT];
mib->icmp6InRouterSolicits = icmpstat.icp6s_inhist[ND_ROUTER_SOLICIT];
mib->icmp6InRouterAdvertisements = icmpstat.icp6s_inhist[ND_ROUTER_ADVERT];
mib->icmp6InNeighborSolicits = icmpstat.icp6s_inhist[ND_NEIGHBOR_SOLICIT];
mib->icmp6InNeighborAdvertisements = icmpstat.icp6s_inhist[ND_NEIGHBOR_ADVERT];
mib->icmp6InRedirects = icmpstat.icp6s_inhist[ND_REDIRECT];
mib->icmp6OutMsgs = icmpstat.icp6s_canterror
+ icmpstat.icp6s_toofreq;
for (i = 0; i <= ICMP6_MAXTYPE; i++)
mib->icmp6OutMsgs += icmpstat.icp6s_outhist[i];
mib->icmp6OutDestUnreachs = icmpstat.icp6s_outhist[ICMP6_DST_UNREACH];
mib->icmp6OutPktTooBigs = icmpstat.icp6s_outhist[ICMP6_PACKET_TOO_BIG];
mib->icmp6OutTimeExcds = icmpstat.icp6s_outhist[ICMP6_TIME_EXCEEDED];
mib->icmp6OutParmProblems = icmpstat.icp6s_outhist[ICMP6_PARAM_PROB];
mib->icmp6OutEchos = icmpstat.icp6s_outhist[ICMP6_ECHO_REQUEST];
mib->icmp6OutEchoReplies = icmpstat.icp6s_outhist[ICMP6_ECHO_REPLY];
mib->icmp6OutRouterSolicits = icmpstat.icp6s_outhist[ND_ROUTER_SOLICIT];
mib->icmp6OutNeighborSolicits = icmpstat.icp6s_outhist[ND_NEIGHBOR_SOLICIT];
mib->icmp6OutNeighborAdvertisements = icmpstat.icp6s_outhist[ND_NEIGHBOR_ADVERT];
mib->icmp6OutRedirects = icmpstat.icp6s_outhist[ND_REDIRECT];
mib->icmp6OutGroupMembResponses = icmpstat.icp6s_outhist[MLD_LISTENER_REPORT];
mib->icmp6OutGroupMembReductions = icmpstat.icp6s_outhist[MLD_LISTENER_DONE];
return 0;
}
开发者ID:ClausKlein,项目名称:net-snmp,代码行数:56,代码来源:kernel_sysctl.c
示例18: 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
示例19: add_pdu_var
static void add_pdu_var(netsnmp_pdu *pdu, const char *mib_name, int id, const char *value)
{
oid oid_name[MAX_OID_LEN];
size_t name_length;
char buf[4096];
buf[4095] = '\0';
snprintf(buf, sizeof(buf)-1, "%s.%d", mib_name, id);
name_length = MAX_OID_LEN;
if (snmp_parse_oid(buf, oid_name, &name_length) == NULL) {
snmp_perror(buf);
return;
}
if (snmp_add_var(pdu, oid_name, name_length, '=', value)) {
snmp_perror(buf);
return;
}
}
开发者ID:FreeRADIUS,项目名称:freeradius-server,代码行数:20,代码来源:snmp_mtp.c
示例20: netbsd_read_ip_stat
int
netbsd_read_ip_stat(struct ip_mib *mib)
{
uint64_t ipstat[IP_NSTATS];
size_t size = sizeof(ipstat);
int i;
static int sname[4] = { 4, 2, 0, 0 }; /* CTL_NET, PF_INET, IPPROTO_IP, 0 */
size_t len;
(void)memset(mib, 0, sizeof(*mib));
if (-1 == sysctlbyname("net.inet.ip.stats", ipstat, &size, NULL, 0)) {
snmp_perror("netbsd_read_ip_stat: net.inet.ip.stats");
return -1;
}
mib->ipForwarding = 0;
len = sizeof i;
sname[3] = IPCTL_FORWARDING;
if (0 == sysctl(sname, 4, &i, &len, 0, 0)) {
mib->ipForwarding = (long)i;
}
mib->ipDefaultTTL = 0;
sname[3] = IPCTL_DEFTTL;
if (0 == sysctl(sname, 4, &i, &len, 0, 0)) {
mib->ipDefaultTTL = (long)i;
}
mib->ipInReceives = ipstat[IP_STAT_TOTAL];
mib->ipInHdrErrors = ipstat[IP_STAT_BADSUM]
+ ipstat[IP_STAT_TOOSHORT] + ipstat[IP_STAT_TOOSMALL]
+ ipstat[IP_STAT_BADHLEN] + ipstat[IP_STAT_BADLEN];
mib->ipInAddrErrors = ipstat[IP_STAT_CANTFORWARD];
mib->ipForwDatagrams = ipstat[IP_STAT_FORWARD];
mib->ipInUnknownProtos = ipstat[IP_STAT_NOPROTO];
mib->ipInDiscards = ipstat[IP_STAT_FRAGDROPPED]; /* FIXME */
mib->ipInDelivers = ipstat[IP_STAT_DELIVERED];
mib->ipOutRequests = ipstat[IP_STAT_LOCALOUT];
mib->ipOutDiscards = ipstat[IP_STAT_ODROPPED];
mib->ipOutNoRoutes = 0; /* FIXME */
mib->ipReasmTimeout = 0; /* IPFRAGTTL; */
mib->ipReasmReqds = ipstat[IP_STAT_FRAGMENTS];
mib->ipReasmOKs = ipstat[IP_STAT_REASSEMBLED];
mib->ipReasmFails = ipstat[IP_STAT_FRAGDROPPED]
+ ipstat[IP_STAT_FRAGTIMEOUT];
mib->ipFragOKs = ipstat[IP_STAT_FRAGMENTS];
mib->ipFragFails = ipstat[IP_STAT_CANTFRAG];
mib->ipFragCreates = ipstat[IP_STAT_OFRAGMENTS];
mib->ipRoutingDiscards = ipstat[IP_STAT_NOROUTE];
return 0;
}
开发者ID:ClausKlein,项目名称:net-snmp,代码行数:53,代码来源:kernel_netbsd.c
注:本文中的snmp_perror函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论