void system_parse_config_sysObjectID(const char *token, char *cptr) { char tmpbuf[1024]; sysObjectIDLength = MAX_OID_LEN; if (!read_objid(cptr, sysObjectID, &sysObjectIDLength)) { snprintf(tmpbuf, sizeof(tmpbuf), "sysobjectid token not a parsable OID:\n\t%s", cptr); config_perror(tmpbuf); // Modified by Gavin Lin, 2008/10/30 //memcpy(sysObjectID, version_sysoid, version_sysoid_len * sizeof(oid)); //sysObjectIDLength = version_sysoid_len; #ifdef CONFIG_MODEL_LRTXXX /* purpose : 0012697 author : Gavin.Lin date : 2010-06-22 */ /* description : Customer requirements */ kd_doCommand("VERSION MODEL", CMD_PRINT, ASH_DO_NOTHING, tmpbuf); if (!strcmp("LRT214", tmpbuf)) { memcpy(sysObjectID, nk_sysobjectid_214, nk_sysobjectid_len * sizeof(oid)); } if (!strcmp("LRT224", tmpbuf)) { memcpy(sysObjectID, nk_sysobjectid_224, nk_sysobjectid_len * sizeof(oid)); } #else memcpy(sysObjectID, nk_sysobjectid, nk_sysobjectid_len * sizeof(oid)); #endif sysObjectIDLength = nk_sysobjectid_len; } }
void snmp_init(void) { console_log("snmp: init\n"); init_snmp(APPNAME); conv_utf16_utf8 = iconv_open("UTF-8","UTF-16LE"); oid_rssi_ts1_length = MAX_OID_LEN; if (!read_objid(OID_RSSI_TS1, oid_rssi_ts1, &oid_rssi_ts1_length)) console_log("snmp error: can't parse ts1 rssi oid (%s)\n", OID_RSSI_TS1); oid_rssi_ts2_length = MAX_OID_LEN; if (!read_objid(OID_RSSI_TS2, oid_rssi_ts2, &oid_rssi_ts2_length)) console_log("snmp error: can't parse ts2 rssi oid (%s)\n", OID_RSSI_TS2); oid_id_length = MAX_OID_LEN; if (!read_objid(OID_ID, oid_id, &oid_id_length)) console_log("snmp error: can't parse id oid (%s)\n", OID_ID); oid_repeatertype_length = MAX_OID_LEN; if (!read_objid(OID_REPEATERTYPE, oid_repeatertype, &oid_repeatertype_length)) console_log("snmp error: can't parse repeatertype oid (%s)\n", OID_REPEATERTYPE); oid_fwversion_length = MAX_OID_LEN; if (!read_objid(OID_FWVERSION, oid_fwversion, &oid_fwversion_length)) console_log("snmp error: can't parse fwversion oid (%s)\n", OID_FWVERSION); oid_callsign_length = MAX_OID_LEN; if (!read_objid(OID_CALLSIGN, oid_callsign, &oid_callsign_length)) console_log("snmp error: can't parse callsign oid (%s)\n", OID_CALLSIGN); oid_dlfreq_length = MAX_OID_LEN; if (!read_objid(OID_DLFREQ, oid_dlfreq, &oid_dlfreq_length)) console_log("snmp error: can't parse callsign oid (%s)\n", OID_DLFREQ); oid_ulfreq_length = MAX_OID_LEN; if (!read_objid(OID_ULFREQ, oid_ulfreq, &oid_ulfreq_length)) console_log("snmp error: can't parse callsign oid (%s)\n", OID_ULFREQ); }
/* * 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; }
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); }
static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t *ci) { char buffer[DATA_MAX_NAME_LEN]; int status; status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer)); if (status != 0) return status; if (dd->is_table) { /* Instance is an OID */ dd->instance.oid.oid_len = MAX_OID_LEN; if (!read_objid (buffer, dd->instance.oid.oid, &dd->instance.oid.oid_len)) { ERROR ("snmp plugin: read_objid (%s) failed.", buffer); return (-1); } } else { /* Instance is a simple string */ sstrncpy (dd->instance.string, buffer, sizeof (dd->instance.string)); } return (0); } /* int csnmp_config_add_data_instance */
/* * initialize */ void snmpInitialize(tInterfaceList *interfaceList) { tOidList *oidList; /* initialize library */ init_snmp("snmppoller"); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, TRUE); unsigned int i = 0; while (i < interfaceList->count) { syslog(LOG_DEBUG, "snmpInitialize: %s", interfaceList->interface[i].ip); oidList = &interfaceList->interface[i].oidList; unsigned int o = 0; while (o < oidList->count) { syslog(LOG_DEBUG, "snmpInitialize: * %s", oidList->oid[o].oidName); oidList->oid[o].OidLen = sizeof(oidList->oid[o].Oid)/sizeof(oidList->oid[o].Oid[0]); if (!read_objid(oidList->oid[o].oidName, oidList->oid[o].Oid, &oidList->oid[o].OidLen)) { syslog(LOG_ERR, "snmpInitialize: read_objid failed for: %d %s", interfaceList->interface[i].id_interface, oidList->oid[o].oidName); exit(1); } o++; } i++; } }
static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t *ci) { if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("snmp plugin: `Instance' needs exactly one string argument."); return (-1); } if (dd->is_table) { /* Instance is an OID */ dd->instance.oid.oid_len = MAX_OID_LEN; if (!read_objid (ci->values[0].value.string, dd->instance.oid.oid, &dd->instance.oid.oid_len)) { ERROR ("snmp plugin: read_objid (%s) failed.", ci->values[0].value.string); return (-1); } } else { /* Instance is a simple string */ sstrncpy (dd->instance.string, ci->values[0].value.string, sizeof (dd->instance.string)); } return (0); } /* int csnmp_config_add_data_instance */
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); }
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); }
int mp_snmp_values_fetch2(netsnmp_session *ss, const mp_snmp_value *values) { const mp_snmp_value *vp1; mp_snmp_query_cmd *vp2; size_t count; mp_snmp_query_cmd *oid_values = NULL; int rc = 0; for (count = 0, vp1 = values; vp1->oid; vp1++, count++) ; oid_values = (mp_snmp_query_cmd *) mp_malloc(count * sizeof(mp_snmp_query_cmd)); for (vp1 = values, vp2 = oid_values; vp1->oid; vp1++, vp2++) { vp2->oid_len = MAX_OID_LEN; if (!read_objid(vp1->oid, vp2->oid, &vp2->oid_len)) { if (mp_verbose > 3) printf("Invalid OID: %s\n", vp1->oid); goto done; } vp2->type = vp1->type; vp2->target = vp1->target; vp2->target_len = vp1->target_len; } rc = mp_snmp_values_fetch1(ss, oid_values); done: free(oid_values); return rc; }
int main( int argc, char **argv) { OPEN_LOG("check_signature", LOG_USER); if (argc != 3) FATAL(MSG_USAGE); struct Certificate locert, hicert; struct CertificateRevocationList crl; Certificate(&locert, (ushort) 0); Certificate(&hicert, (ushort) 0); CertificateRevocationList(&crl, (ushort) 0); struct Blob blob; Blob(&blob, (ushort) 0); struct casn *tbsp, *sigp; struct AlgorithmIdentifier *algp; char *sfx = strchr(argv[1], (int)'.'); int ansr; if (!strcmp(sfx, ".cer")) { tbsp = &locert.toBeSigned.self; algp = &locert.algorithm; sigp = &locert.signature; ansr = get_casn_file(&locert.self, argv[1], 0); } else if (!strcmp(sfx, ".crl")) { tbsp = &crl.toBeSigned.self; algp = &crl.algorithm; sigp = &crl.signature; ansr = get_casn_file(&crl.self, argv[1], 0); } else if (!strcmp(sfx, ".blb")) { tbsp = &blob.toBeSigned; algp = &blob.algorithm; sigp = &blob.signature; ansr = get_casn_file(&blob.self, argv[1], 0); } else FATAL(MSG_TYPE, argv[1]); if (ansr < 0) FATAL(MSG_GET, argv[1]); if (get_casn_file(&hicert.self, argv[2], 0) < 0) FATAL(MSG_GET, argv[2]); if (diff_objid(&algp->algorithm, id_sha_256WithRSAEncryption)) { char oidbuf[80]; read_objid(&algp->algorithm, oidbuf); FATAL(MSG_ALG, oidbuf); } if (!check_signature(tbsp, &hicert, sigp)) fprintf(stderr, "Signature failed\n"); fprintf(stderr, "Signature succeeded\n"); return 0; }
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, ':'); } }
static void system_parse_config_sysObjectID(const char *token, char *cptr) { size_t sysObjectIDLength = MAX_OID_LEN; if (!read_objid(cptr, sysObjectID, &sysObjectIDLength)) { netsnmp_config_error("sysobjectid token not a parsable OID:\n\t%s", cptr); sysObjectIDByteLength = version_sysoid_len * sizeof(oid); memcpy(sysObjectID, version_sysoid, sysObjectIDByteLength); } else sysObjectIDByteLength = sysObjectIDLength * sizeof(oid); }
int main(int argc, char ** argv) { struct snmp_session session; struct snmp_session *sess_handle; struct snmp_pdu *pdu; struct snmp_pdu *response; struct variable_list *vars; oid id_oid[MAX_OID_LEN]; oid serial_oid[MAX_OID_LEN]; size_t id_len = MAX_OID_LEN; size_t serial_len = MAX_OID_LEN; int status; struct tree * mib_tree; /*********************/ if(argv[1] == NULL){ printf("Please supply a hostname\n"); exit(1); } init_snmp("Main check"); snmp_sess_init( &session ); session.version = SNMP_VERSION_1; session.community = "public"; session.community_len = strlen(session.community); session.peername = argv[1]; sess_handle = snmp_open(&session); add_mibdir("."); mib_tree = read_mib("mibs/SNMPv2-MIB.txt"); pdu = snmp_pdu_create(SNMP_MSG_GET); read_objid("SNMPv2-MIB::sysDescr.0", id_oid, &id_len); snmp_add_null_var(pdu, id_oid, id_len); read_objid("SNMPv2-MIB::sysObjectID.0", serial_oid, &serial_len); snmp_add_null_var(pdu, serial_oid, serial_len); status = snmp_synch_response(sess_handle, pdu, &response); for(vars = response->variables; vars; vars = vars->next_variable) print_value(vars->name, vars->name_length, vars); snmp_free_pdu(response); snmp_close(sess_handle); return (0); }
/* read_config_read_objid(): reads an objid from a format saved by the above */ char *read_config_read_objid(char *readfrom, oid **objid, size_t *len) { if (objid == NULL || readfrom == NULL) return NULL; if (*objid != NULL) { char buf[SPRINT_MAX_LEN]; if (strncmp(readfrom,"NULL",4) == 0) { /* null length oid */ *len = 0; } else { /* read_objid is touchy with trailing stuff */ copy_word(readfrom, buf); /* read the oid into the buffer passed to us */ if (!read_objid(buf, *objid, len)) { DEBUGMSGTL(("read_config_read_objid","Invalid OID")); return NULL; } } readfrom = skip_token(readfrom); } else { if (strncmp(readfrom,"NULL",4) == 0) { /* null length oid */ *len = 0; readfrom = skip_token(readfrom); } else { /* space needs to be malloced. Call ourself recursively to figure out how long the oid actually is */ oid obuf[MAX_OID_LEN]; size_t obuflen = MAX_OID_LEN; oid *oidp = obuf; oid **oidpp = &oidp; /* done this way for odd, untrue, gcc warnings */ readfrom = read_config_read_objid(readfrom, oidpp, &obuflen); /* Then malloc and copy the results */ *len = obuflen; if (*len > 0 && (*objid = (oid*)malloc(*len * sizeof(oid))) == NULL) return NULL; if (obuflen > 0) memcpy(*objid, obuf, obuflen*sizeof(oid)); } } return readfrom; }
void process_stdin(void) { char buf[MAX_LINE_TEMP]; oid name[MAX_OID_LEN]; size_t name_length; while ( NULL != fgets( buf, sizeof( buf ), stdin ) ) { char delim = ' '; char *nl = strchr(buf, '\n'); char *rest = strchr(buf, delim); if (nl != NULL) { *nl = '\0'; } /* else too-long line: output will look weird. Too bad. */ if (rest == NULL) { delim = '\t'; rest = strchr(buf, delim); } if (rest != NULL) { *rest++ = '\0'; } name_length = MAX_OID_LEN; /* * If it's not the whole line, only try to process buffer * longer than 5 characters. * The idea is to avoid false positives including, e.g., * a hex dump. */ if ( !(rest && strlen( buf ) <= 5) && read_objid( buf, name, &name_length )) { char objbuf[MAX_LINE_TEMP]; snprint_objid( objbuf, MAX_LINE_TEMP, name, name_length ); fputs( objbuf, stdout ); } else { fputs( buf, stdout ); } /* * For future improvement: if delim == ' ' && rest && *rest == '=' * see if rest looks like snmpget/snmpwalk output * and handle it in the context of the given node */ if (rest) { fputc( delim, stdout ); fputs( rest, stdout ); } fputc( '\n', stdout ); } }
void system_parse_config_sysObjectID(const char *token, char *cptr) { char tmpbuf[1024]; sysObjectIDLength = MAX_OID_LEN; if (!read_objid(cptr, sysObjectID, &sysObjectIDLength)) { snprintf(tmpbuf, sizeof(tmpbuf), "sysobjectid token not a parsable OID:\n\t%s", cptr); config_perror(tmpbuf); memcpy(sysObjectID, version_sysoid, version_sysoid_len * sizeof(oid)); sysObjectIDLength = version_sysoid_len; } }
int mp_snmp_subtree_query_string(netsnmp_session *ss, const char *subtree_oid, mp_snmp_subtree *subtree) { oid subtree_oid_prefix[MAX_OID_LEN]; size_t subtree_oid_prefix_len = MAX_OID_LEN; if (!read_objid(subtree_oid, subtree_oid_prefix, &subtree_oid_prefix_len)) { if (mp_verbose > 3) printf("Invalid OID: %s\n", subtree_oid); return 0; } return mp_snmp_subtree_query(ss, subtree_oid_prefix, subtree_oid_prefix_len, subtree); }
/* * 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); }
oid *snmp_parse_oid(char *argv, oid *root, int *rootlen) { if (random_access) { if (get_node(argv,root,rootlen)) { return root; } } else { if (read_objid(argv,root,rootlen)) { return root; } } return NULL; }
/* * initialize */ void initialize (void) { struct oid *op = oids; /* Win32: init winsock */ SOCK_STARTUP; /* initialize library */ init_snmp("asynchapp"); /* parse the oids */ while (op->Name) { op->OidLen = sizeof(op->Oid)/sizeof(op->Oid[0]); if (!read_objid(op->Name, op->Oid, &op->OidLen)) { snmp_perror("read_objid"); exit(1); } op++; } }
QVariant QSnmp::get(const QString &oid) { struct snmp_pdu *pdu; struct snmp_pdu *response; // oid anOID[MAX_OID_LEN]; u_long anOID[MAX_OID_LEN]; size_t anOID_len = MAX_OID_LEN; int status; struct variable_list *vars; pdu = snmp_pdu_create(SNMP_MSG_GET); read_objid(oid.toUtf8().constData(), anOID, &anOID_len); snmp_add_null_var(pdu, anOID, anOID_len); status = snmp_synch_response(ss, pdu, &response); if (status != STAT_SUCCESS || response->errstat != SNMP_ERR_NOERROR) { qDebug("QSnmp: failed to get an oid"); if (response) snmp_free_pdu(response); return QVariant(); } for(vars = response->variables; vars; vars = vars->next_variable) { if (vars->type == ASN_OCTET_STR) { // string QByteArray res(vars->val_len, '\0'); memcpy(res.data(), vars->val.string, vars->val_len); snmp_free_pdu(response); return res; } if (vars->type == ASN_INTEGER) { int res = (int)*vars->val.integer; snmp_free_pdu(response); return res; } print_variable(vars->name, vars->name_length, vars); qDebug("QSnmp: unknown var type %d", vars->type); } snmp_free_pdu(response); return QVariant(); }
oid *snmp_parse_oid(const char *argv, oid *root, size_t *rootlen) { size_t savlen = *rootlen; /* printf("parse_oid: read_objid\n"); */ if (read_objid(argv,root,rootlen)) { return root; } *rootlen = savlen; /* printf("parse_oid: get_node\n"); */ if (get_node(argv,root,rootlen)) { return root; } *rootlen = savlen; /* printf("parse_oid: wildly parsing\n"); */ if (get_wild_node(argv,root,rootlen)) { return root; } return NULL; }
int mp_snmp_subtree_get_value_string(const mp_snmp_subtree *subtree, const char* value_oid, const size_t idx, const u_char type, void **target, const size_t target_len) { oid oid_prefix[MAX_OID_LEN]; size_t oid_prefix_len = MAX_OID_LEN; if (!subtree || (subtree->size < 1)) return 0; if (!read_objid(value_oid, oid_prefix, &oid_prefix_len)) { if (mp_verbose > 3) printf("Invalid OID: %s\n", value_oid); return 0; } return mp_snmp_subtree_get_value(subtree, oid_prefix, oid_prefix_len, idx, type, target, target_len); }
int mp_snmp_values_fetch3(netsnmp_session *ss, const mp_snmp_value *values, ...) { va_list ap; const mp_snmp_value *vp1; mp_snmp_query_cmd *vp2; size_t count; char formatted_oid[1024]; mp_snmp_query_cmd *oid_values = NULL; int rc = 0; for (count = 0, vp1 = values; vp1->oid; vp1++, count++) ; oid_values = (mp_snmp_query_cmd *) mp_malloc(count * sizeof(mp_snmp_query_cmd)); for (vp1 = values, vp2 = oid_values; vp1->oid; vp1++, vp2++) { va_start(ap, values); vsnprintf(formatted_oid, sizeof(formatted_oid), vp1->oid, ap); va_end(ap); vp2->oid_len = MAX_OID_LEN; if (!read_objid(formatted_oid, vp2->oid, &vp2->oid_len)) { if (mp_verbose > 3) printf("Invalid OID: %s\n", vp1->oid); goto done; } vp2->type = vp1->type; vp2->target = vp1->target; vp2->target_len = vp1->target_len; } rc = mp_snmp_values_fetch1(ss, oid_values); done: free(oid_values); return rc; }
/* * initialize */ void initialize (void) { struct oid *op; init_snmp("asynchapp"); load_oids(); /* parse the oids */ op = oids; while (op->hostname) { /* printf("[%s]\n",op->hostname); */ op->OidLen = sizeof(op->Oid)/sizeof(op->Oid[0]); if (!read_objid(op->Name, op->Oid, &op->OidLen)) { snmp_perror("read_objid"); exit(1); } op++; } printf("Press Enter to start polling"); getc(stdin); }
static oid_t *make_oitem(mibdef_t *mib, char *devname, oidds_t *oiddef, char *oidstr, struct req_t *reqitem) { oid_t *oitem = (oid_t *)calloc(1, sizeof(oid_t)); oitem->mib = mib; oitem->devname = strdup(devname); oitem->setnumber = reqitem->setnumber; oitem->oiddef = oiddef; oitem->OidLen = sizeof(oitem->Oid)/sizeof(oitem->Oid[0]); if (read_objid(oidstr, oitem->Oid, &oitem->OidLen)) { if (!reqitem->oidhead) reqitem->oidhead = oitem; else reqitem->oidtail->next = oitem; reqitem->oidtail = oitem; } else { /* Could not parse the OID definition */ errprintf("Cannot determine OID for %s\n", oidstr); snmp_perror("read_objid"); xfree(oitem->devname); xfree(oitem); } return oitem; }
int mp_snmp_subtree_get_values(const mp_snmp_subtree *subtree, const size_t idx, const mp_snmp_value *values) { const mp_snmp_value *vp; oid oid_prefix[MAX_OID_LEN]; size_t oid_prefix_len; int count = 0; if (!subtree || (subtree->size < 1)) return 0; for (vp = values; vp->oid; vp++) { oid_prefix_len = MAX_OID_LEN; read_objid(vp->oid, oid_prefix, &oid_prefix_len); if (mp_snmp_subtree_get_value(subtree, oid_prefix, oid_prefix_len, idx, vp->type, vp->target, vp->target_len) > 0) { count++; } } return count; }
bool QSnmp::set(const QString &oid, int val) { struct snmp_pdu *pdu; struct snmp_pdu *response = NULL; // oid anOID[MAX_OID_LEN]; u_long anOID[MAX_OID_LEN]; size_t anOID_len = MAX_OID_LEN; int status; pdu = snmp_pdu_create(SNMP_MSG_SET); read_objid(oid.toUtf8().constData(), anOID, &anOID_len); snmp_add_var(pdu, anOID, anOID_len, 'i', QByteArray::number(val).constData()); //snmp_add_var(pdu, anOID, anOID_len, ASN_INTEGER, QByteArray::number(val).constData()); status = snmp_synch_response(ss, pdu, &response); if (status != STAT_SUCCESS || response->errstat != SNMP_ERR_NOERROR) { qDebug("QSnmp: failed to set an oid"); if (response) snmp_free_pdu(response); return false; } if (response) snmp_free_pdu(response); return true; }
unsigned int encode_snmp_oid (char *oid_string, unsigned char *out_buffer, size_t out_size) { oid var_name[MAX_OID_LEN]; size_t name_len = MAX_OID_LEN; unsigned char *data_ptr; if (!read_objid (oid_string, var_name, &name_len)) { if (!get_node (oid_string, var_name, &name_len)) { fprintf(stderr, "Can't find oid %s at line %d\n", oid_string, line); return 0; } } data_ptr = asn_build_objid (out_buffer, &out_size, (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), var_name, name_len); return data_ptr - out_buffer; }