/* * 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); } }
static void csnmp_host_open_session (host_definition_t *host) { struct snmp_session sess; if (host->sess_handle != NULL) csnmp_host_close_session (host); snmp_sess_init (&sess); sess.peername = host->address; sess.community = (u_char *) host->community; sess.community_len = strlen (host->community); sess.version = (host->version == 1) ? SNMP_VERSION_1 : SNMP_VERSION_2c; /* snmp_sess_open will copy the `struct snmp_session *'. */ host->sess_handle = snmp_sess_open (&sess); if (host->sess_handle == NULL) { char *errstr = NULL; snmp_error (&sess, NULL, NULL, &errstr); ERROR ("snmp plugin: host %s: snmp_sess_open failed: %s", host->name, (errstr == NULL) ? "Unknown problem" : errstr); sfree (errstr); } } /* void csnmp_host_open_session */
int init_master_agent(int dest_port, int (*pre_parse) (struct snmp_session *, snmp_ipaddr), int (*post_parse) (struct snmp_session *, struct snmp_pdu *,int)) { struct snmp_session sess, *session; if ( ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) != MASTER_AGENT ) return 0; /* no error if ! MASTER_AGENT */ DEBUGMSGTL(("snmpd","installing master agent on port %d\n", dest_port)); snmp_sess_init( &sess ); sess.version = SNMP_DEFAULT_VERSION; sess.peername = SNMP_DEFAULT_PEERNAME; sess.community_len = SNMP_DEFAULT_COMMUNITY_LEN; sess.local_port = dest_port; sess.callback = handle_snmp_packet; sess.authenticator = NULL; sess.flags = ds_get_int(DS_APPLICATION_ID, DS_AGENT_FLAGS); session = snmp_open_ex( &sess, pre_parse, 0, post_parse, 0, 0 ); if ( session == NULL ) { /* diagnose snmp_open errors with the input struct snmp_session pointer */ snmp_sess_perror("init_master_agent", &sess); return 1; } main_session = session; return 0; }
void snmp_start_read_rssi(char *host) { struct snmp_pdu *pdu; struct snmp_session session; const char *community = "public"; if (oid_rssi_ts1_length == 0 || oid_rssi_ts2_length == 0) return; snmp_rssi_received = 0; if (snmp_session_rssi != NULL) { snmp_close(snmp_session_rssi); snmp_session_rssi = NULL; } snmp_sess_init(&session); session.version = SNMP_VERSION_1; session.peername = strdup(host); session.community = (unsigned char *)strdup(community); session.community_len = strlen(community); session.callback = snmp_get_rssi_cb; if (!(snmp_session_rssi = snmp_open(&session))) { console_log("snmp error: error opening session to host %s\n", host); return; } pdu = snmp_pdu_create(SNMP_MSG_GET); snmp_add_null_var(pdu, oid_rssi_ts1, oid_rssi_ts1_length); snmp_add_null_var(pdu, oid_rssi_ts2, oid_rssi_ts2_length); if (!snmp_send(snmp_session_rssi, pdu)) console_log("snmp error: error sending rssi request to host %s\n", host); free(session.peername); free(session.community); }
/* Init SNMP Session * alorbach, 2008-02-12 */ static rsRetVal omsnmp_initSession(instanceData *pData) { DEFiRet; netsnmp_session session; /* should not happen, but if session is not cleared yet - we do it now! */ if (pData->snmpsession != NULL) omsnmp_exitSession(pData); dbgprintf( "omsnmp_initSession: ENTER - Target = '%s' on Port = '%d'\n", pData->szTarget, pData->iPort); putenv(strdup("POSIXLY_CORRECT=1")); snmp_sess_init(&session); session.version = pData->iSNMPVersion; session.callback = NULL; /* NOT NEEDED */ session.callback_magic = NULL; session.peername = (char*) pData->szTargetAndPort; /* Set SNMP Community */ if (session.version == SNMP_VERSION_1 || session.version == SNMP_VERSION_2c) { session.community = (unsigned char *) pData->szCommunity; session.community_len = strlen((char*) pData->szCommunity); } pData->snmpsession = snmp_open(&session); if (pData->snmpsession == NULL) { errmsg.LogError(0, RS_RET_SUSPENDED, "omsnmp_initSession: snmp_open to host '%s' on Port '%d' failed\n", pData->szTarget, pData->iPort); /* Stay suspended */ iRet = RS_RET_SUSPENDED; } RETiRet; }
int init_ilo_snmp_session(struct ilo_snmp_priv * priv_ptr) { int ret = NAGIOS_ILO_SUCCESS_STATUS; netsnmp_session session; init_snmp("Nagios_hpilo_snmp"); snmp_sess_init(&session); session.peername = strdup(priv_ptr->options.host); session.community = strdup(priv_ptr->options.community); session.community_len = strlen((char *) session.community); session.version = priv_ptr->options.version; session.timeout = priv_ptr->options.timeout; session.retries = priv_ptr->options.retries; priv_ptr->session = snmp_open(&session); if (priv_ptr->session == NULL) { snmp_error(&session, &session.s_errno, &session.s_snmp_errno, &priv_ptr->err_str); ret = NAGIOS_ILO_FAIL_STATUS; } return ret; }
QtNetSNMP::SNMPSession *QtNetSNMP::QSNMPCore::createSession(SNMPVersion version, const QString& community, const QString& agent) throw(QSNMPException) { SNMPSession session; SNMPSession *openedSession; std::string stdCommunity = community.toStdString(); std::string stdAgent = agent.toStdString(); if(version != SNMPv1 && version != SNMPv2) throw QSNMPException("QSNMPCore :: Create Session :: Version not supported"); snmp_sess_init(&session); session.remote_port = _port; session.retries = _retries; session.timeout = _timeout; session.version = version; session.community = reinterpret_cast<u_char *>(const_cast<char *>(stdCommunity.c_str())); session.community_len = stdCommunity.length(); session.peername = const_cast<char *>(stdAgent.c_str()); SOCK_STARTUP; if(!(openedSession = snmp_open(&session))) { SOCK_CLEANUP; throw QSNMPException("QSNMPCore :: Create Session :: Open Session"); } return openedSession; }
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); }
HSNMP SnmpOpen(const char* ipAddress) { HSNMP m_sessp; struct snmp_session session; snmp_sess_init(&session); // structure defaults session.version = SNMP_VERSION_2c; session.peername = strdup(ipAddress); session.community = (u_char*)strdup(readCommunity); session.community_len = strlen((char*)session.community); session.timeout = 100000; // timeout (us) session.retries = 3; // retries if(!(m_sessp = snmp_sess_open(&session))) { int liberr, syserr; char *errstr; snmp_error(&session, &liberr, &syserr, &errstr); syslog(LOG_ERR,"Open SNMP session for host \"%s\": %s",ipAddress,errstr); free(errstr); return 0; } // m_session = snmp_sess_session(m_sessp); // get the session pointer syslog(LOG_INFO,"SNMP session for host \"%s\" opened",ipAddress); return m_sessp; }
void * snmp_poll ( void * request_details ) { snmp_request_t* req = (snmp_request_t*)request_details; struct snmp_session ss, *sp; struct oid *op; snmp_sess_init(&ss); /* initialize session */ ss.version = SNMP_VERSION_2c; ss.peername = req->target_host; ss.community = req->community; ss.community_len = strlen(ss.community); snmp_synch_setup(&ss); if (!(sp = snmp_open(&ss))) snmp_perror("snmp_open"); struct snmp_pdu *req2, *resp; int status; req = snmp_pdu_create(SNMP_MSG_GET); snmp_add_null_var(req2, req->oid, strlen(req->oid)); status = snmp_synch_response(sp, req2, &resp); snmp_free_pdu(resp); snmp_close(sp); // Push the results back to the result queue.. pthread_mutex_lock ( &result_lock ) ; // TODO: create linked array for a result buffer pthread_mutex_unlock ( &result_lock ) ; }
static void ConnectingEntry(UNUSED tState self) { netsnmp_session init; netsnmp_transport* t; void* sess; if(sessp) { snmp_sess_close(sessp); sessp = NULL; } snmp_sess_init(&init); init.version = AGENTX_VERSION_1; init.retries = 0; /* Retries are handled by the state machine */ init.timeout = SNMP_DEFAULT_TIMEOUT; init.flags |= SNMP_FLAGS_STREAM_SOCKET; init.callback = handle_agentx_response; init.authenticator = NULL; if(!(t = netsnmp_transport_open_client( "agentx", netsnmp_ds_get_string( NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET)))) { snmp_log(LOG_ERR, "Failed to connect to AgentX server\n"); change_state(&Exit); } else if(!(sess = snmp_sess_add_ex( &init, t, NULL, agentx_parse, NULL, NULL, agentx_realloc_build, agentx_check_packet, NULL))) { snmp_log(LOG_ERR, "Failed to create session\n"); change_state(&Exit); } else { sessp = sess; change_state(&Opening); } }
/* * creates a snmp session */ static struct snmp_session * MPC_open(char *hostname, int port, char *community) { static struct snmp_session session; struct snmp_session *sptr; DEBUGCALL; /* create session */ snmp_sess_init(&session); /* fill session */ session.peername = hostname; session.version = SNMP_VERSION_1; session.remote_port = port; session.community = (u_char *)community; session.community_len = strlen(community); session.retries = 5; session.timeout = 1000000; /* open session */ sptr = snmp_open(&session); if (sptr == NULL) { MPC_error(&session, __FUNCTION__, "cannot open snmp session"); } /* return pointer to opened session */ return (sptr); }
static netsnmp_session *snmp_init (const char *target) { static netsnmp_session *session = NULL; #ifndef NETSNMPV54 char default_port[128]; snprintf (default_port, sizeof (default_port), "%s:162", target); #endif if (session) { return (session); } if (target == NULL) { return NULL; } session = malloc (sizeof (netsnmp_session)); snmp_sess_init (session); session->version = SNMP_VERSION_2c; session->callback = NULL; session->callback_magic = NULL; session = snmp_add(session, #ifdef NETSNMPV54 netsnmp_transport_open_client ("snmptrap", target), #else netsnmp_tdomain_transport (default_port, 0, "udp"), #endif NULL, NULL); if (session == NULL) { qb_log(LOG_ERR, 0, "Could not create snmp transport"); } return (session); }
static void test_exec_sensor_cb(const char *cjson_sensor, void (*msg_cb)(void *opaque, rb_message_list *msgs, size_t i), void *opaque, size_t n) { const size_t aux_mem_wrap_fail_in = mem_wrap_fail_in; // Exclude this // code mem_wrap_fail_in = 0; struct _worker_info worker_info; memset(&worker_info, 0, sizeof(worker_info)); snmp_sess_init(&worker_info.default_session); struct json_object *json_sensor = json_tokener_parse(cjson_sensor); rb_sensor_t *sensor = parse_rb_sensor(json_sensor, &worker_info); json_object_put(json_sensor); mem_wrap_fail_in = aux_mem_wrap_fail_in; for (size_t i = 0; i < n; ++i) { rb_message_list messages; rb_message_list_init(&messages); process_rb_sensor(&worker_info, sensor, &messages); msg_cb(opaque, &messages, i); } rb_sensor_put(sensor); }
/** * Helper for snmp_init */ static void init_session_helper(netsnmp_session *s, char *community) { snmp_sess_init(s); s->peername = strdup(TC1_IP_ADDR); s->version = SNMP_VERSION_2c; s->community = (unsigned char *)strdup(community); s->community_len = strlen(community); }
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); } }
void Session::initSession(snmp_session &sess) { snmp_sess_init(&sess); // Setup defaults sess.peername = new char[m_peerName.length()+1]; strncpy(sess.peername, m_peerName.latin1(), m_peerName.length()+1); // Casts are to move the variables to the original type. sess.retries = (int)m_retries; sess.timeout = (long)m_timeout; }
void init_master(void) { struct snmp_session sess, *session; if ( ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) != MASTER_AGENT ) return; DEBUGMSGTL(("agentx/master","initializing...\n")); snmp_sess_init( &sess ); sess.version = AGENTX_VERSION_1; sess.flags |= SNMP_FLAGS_STREAM_SOCKET; if ( ds_get_string(DS_APPLICATION_ID, DS_AGENT_X_SOCKET) ) sess.peername = strdup(ds_get_string(DS_APPLICATION_ID, DS_AGENT_X_SOCKET)); else sess.peername = strdup(AGENTX_SOCKET); if ( sess.peername[0] == '/' ) { /* * If this is a Unix pathname, * try and create the directory first. */ if (mkdirhier(sess.peername, AGENT_DIRECTORY_MODE, 1)) { snmp_log(LOG_ERR, "Failed to create the directory for the agentX socket: %s\n", sess.peername); } } /* * Otherwise, let 'snmp_open' interpret the string. */ sess.local_port = AGENTX_PORT; /* Indicate server & set default port */ sess.remote_port = 0; sess.callback = handle_master_agentx_packet; session = snmp_open_ex( &sess, 0, agentx_parse, 0, agentx_build, agentx_check_packet ); if ( session == NULL && sess.s_errno == EADDRINUSE ) { /* * Could be a left-over socket (now deleted) * Try again */ session = snmp_open_ex( &sess, 0, agentx_parse, 0, agentx_build, agentx_check_packet ); } if ( session == NULL ) { /* diagnose snmp_open errors with the input struct snmp_session pointer */ snmp_sess_perror("init_master", &sess); if (!ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS)) exit(1); } DEBUGMSGTL(("agentx/master","initializing... DONE\n")); }
/* Main program Queries various SNMP values on cisco devices. */ int main(int argc, char *argv[]) { char* output; struct snmp_session session; char arg; // int i; // long snmpVer; /* Initialize and build snmp session, add version, community, host, etc */ init_snmp("Linux_checks"); snmp_sess_init( &session ); switch (arg = snmp_parse_args(argc, argv, &session, "C:", optProc)) { case -3: exit(1); case -2: exit(0); case -1: usage(); exit(1); default: break; } /* Check warning/critical test values to verify they are within the appropriate ranges */ if ((crit > 100) && (strcmp(mode, "sessions"))) { printf("Critical threshold should be less than 100!\n"); usage(); exit(RESULT_UNKNOWN); } else if (crit < 0) { printf("Critical threshould must be greater than 0!\n"); usage(); exit(RESULT_UNKNOWN); } else if ((warn < 0) && (strcmp(mode, "sessions"))) { printf("Warning threshold must be greater than or equal to 0!\n"); usage(); exit(RESULT_UNKNOWN); } else if (warn > crit) { printf("Warning threshold must not be greater than critical threshold!\n"); usage(); exit(RESULT_UNKNOWN); } output = checkCPU(&session); printf("%s", output); return exitVal; }
// initialize connection to snmp agent void init(char* ip , char* community) { init_snmp("cs158b"); /* * Initialize a "session" that defines who we're going to talk to */ snmp_sess_init( &session ); /* set up defaults */ session.peername = strdup(ip); // ip session.version = SNMP_VERSION_2c; session.community = community; // community session.community_len = strlen(session.community); }
u_char * cmu_snmp_parse(netsnmp_session * session, netsnmp_pdu *pdu, u_char * data, size_t length) { u_char *bufp = NULL; snmp_sess_init(session); /* gimme a break! */ switch (pdu->version) { case SNMP_VERSION_1: case SNMP_VERSION_2c: case SNMP_DEFAULT_VERSION: break; default: return NULL; } #ifndef NO_INTERNAL_VARLIST if (snmp_parse(0, session, pdu, data, length) != SNMP_ERR_NOERROR) { return NULL; } #else /* * while there are two versions of variable_list: * use an internal variable list for snmp_parse; * clone the result. */ if (1) { netsnmp_pdu *snmp_clone_pdu(netsnmp_pdu *); netsnmp_pdu *snmp_2clone_pdu(netsnmp_pdu *from_pdu, netsnmp_pdu *to_pdu); netsnmp_pdu *ipdu; ipdu = snmp_clone_pdu(pdu); if (snmp_parse(0, session, ipdu, data, length) != SNMP_ERR_NOERROR) { snmp_free_internal_pdu(ipdu); return NULL; } pdu = snmp_2clone_pdu(ipdu, pdu); snmp_free_internal_pdu(ipdu); } #endif /* NO_INTERNAL_VAR_LIST */ /* * Add a null to meet the caller's expectations. */ bufp = (u_char *) malloc(1 + pdu->community_len); if (bufp && pdu->community_len) { memcpy(bufp, pdu->community, pdu->community_len); bufp[pdu->community_len] = '\0'; } return (bufp); }
int snmp_init(selector_t *sel) { struct snmp_session session; #ifdef HAVE_NETSNMP netsnmp_transport *transport = NULL; static char *snmp_default_port = "udp:162"; netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_ERRORS, 0); init_snmp("ipmi_ui"); transport = netsnmp_tdomain_transport(snmp_default_port, 1, "udp"); if (!transport) { snmp_sess_perror("ipmi_ui", &session); return -1; } #else void *transport = NULL; #endif snmp_sess_init(&session); session.peername = SNMP_DEFAULT_PEERNAME; session.version = SNMP_DEFAULT_VERSION; session.community_len = SNMP_DEFAULT_COMMUNITY_LEN; session.retries = SNMP_DEFAULT_RETRIES; session.timeout = SNMP_DEFAULT_TIMEOUT; session.local_port = SNMP_TRAP_PORT; session.callback = snmp_input; session.callback_magic = transport; session.authenticator = NULL; session.isAuthoritative = SNMP_SESS_UNKNOWNAUTH; #ifdef HAVE_NETSNMP snmp_session = snmp_add(&session, transport, snmp_pre_parse, NULL); #else snmp_session = snmp_open_ex(&session, snmp_pre_parse, NULL, NULL, NULL, NULL); #endif if (snmp_session == NULL) { snmp_sess_perror("ipmi_ui", &session); return -1; } ipmi_sel_set_read_fds_handler(sel, snmp_add_read_fds, snmp_check_read_fds, snmp_check_timeout, NULL); return 0; }
static int Snmp_init(SnmpObject *self, PyObject *args, PyObject *kwds) { PyObject *host=NULL, *community=NULL; char *chost=NULL, *ccommunity=NULL; int version = 2; struct snmp_session session; static char *kwlist[] = {"ip", "community", "version", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|i", kwlist, &host, &community, &version)) return -1; snmp_sess_init(&session); if ((chost = PyString_AsString(host)) == NULL) return -1; switch (version) { case 1: session.version = SNMP_VERSION_1; break; case 2: session.version = SNMP_VERSION_2c; break; default: PyErr_Format(PyExc_ValueError, "invalid SNMP version: %d", version); return -1; } if ((ccommunity = PyString_AsString(community)) == NULL) return -1; session.community_len = strlen(ccommunity); if ((session.community = (u_char*)strdup(ccommunity)) == NULL) { PyErr_NoMemory(); return -1; } if ((session.peername = strdup(chost)) == NULL) { PyErr_NoMemory(); return -1; } if ((self->ss = snmp_open(&session)) == NULL) { Snmp_raise_error(&session); free(session.community); free(session.peername); return -1; } if ((self->defers = PyDict_New()) == NULL) return -1; if (Snmp_updatereactor() == -1) return -1; return 0; }
struct snmp_mtp_session *snmp_mtp_session_create() { struct snmp_mtp_session *session = talloc_zero(NULL, struct snmp_mtp_session); if (!session) return NULL; init_snmp("cellmgr_ng"); snmp_sess_init(&session->session); session->session.version = SNMP_VERSION_1; session->session.community = (unsigned char *) "private"; session->session.community_len = strlen((const char *) session->session.community); session->session.myvoid = session; return session; }
/* Init SNMP Session * alorbach, 2008-02-12 */ static rsRetVal omsnmp_initSession(wrkrInstanceData_t *pWrkrData) { netsnmp_session session; instanceData *pData; char szTargetAndPort[MAXHOSTNAMELEN+128]; /* work buffer for specifying a full target and port string */ DEFiRet; /* should not happen, but if session is not cleared yet - we do it now! */ if (pWrkrData->snmpsession != NULL) omsnmp_exitSession(pWrkrData); pData = pWrkrData->pData; snprintf((char*)szTargetAndPort, sizeof(szTargetAndPort), "%s:%s:%d", (pData->szTransport == NULL) ? "udp" : (char*)pData->szTransport, pData->szTarget, pData->iPort == 0 ? 162 : pData->iPort); dbgprintf( "omsnmp_initSession: ENTER - Target = '%s' on Port = '%d'\n", pData->szTarget, pData->iPort); if (setenv("POSIXLY_CORRECT", "1", 1) == -1) ABORT_FINALIZE(RS_RET_ERR); snmp_sess_init(&session); session.version = pData->iSNMPVersion; session.callback = NULL; /* NOT NEEDED */ session.callback_magic = NULL; session.peername = (char*) szTargetAndPort; /* Set SNMP Community */ if (session.version == SNMP_VERSION_1 || session.version == SNMP_VERSION_2c) { session.community = (unsigned char *) pData->szCommunity == NULL ? (uchar*)"public" : pData->szCommunity; session.community_len = strlen((char*) session.community); } pWrkrData->snmpsession = snmp_open(&session); if (pWrkrData->snmpsession == NULL) { errmsg.LogError(0, RS_RET_SUSPENDED, "omsnmp_initSession: snmp_open to host '%s' on Port '%d' " "failed\n", pData->szTarget, pData->iPort); /* Stay suspended */ iRet = RS_RET_SUSPENDED; } finalize_it: RETiRet; }
QSnmp::QSnmp(const QString &peername, const QByteArray &community) { init_snmp("door_control"); snmp_sess_init(&session); session.peername = strdup(peername.toUtf8().constData()); //"192.168.0.100"; session.version = SNMP_VERSION_1; session.community = (unsigned char*)strdup(community.constData()); //(unsigned char*)"private"; session.community_len = strlen((char*)session.community); ss = snmp_open(&session); if (!ss) { snmp_perror("ack"); snmp_log(LOG_ERR, "something horrible happened!!!\n"); return; } qDebug("QSnmp: session established"); }
void snmp::session::open(const std::string & peername, const std::string & community) { if (!_initialized) { init_snmp("snmpapp"); _initialized = true; } ::snmp_session session; snmp_sess_init(&session); session.peername = const_cast<char *>(peername.c_str()); session.version = SNMP_VERSION_1; session.community = reinterpret_cast<u_char *>(const_cast<char *>(community.c_str())); session.community_len = community.size(); _ss = snmp_open(&session); if (!_ss) throw std::runtime_error("Failed to open SNMP session"); }
static netsnmp_session *snmptrapd_add_session(netsnmp_transport *t) { netsnmp_session sess, *session = &sess, *rc = NULL; snmp_sess_init(session); session->peername = SNMP_DEFAULT_PEERNAME; /* Original code had NULL here */ session->version = SNMP_DEFAULT_VERSION; session->community_len = SNMP_DEFAULT_COMMUNITY_LEN; session->retries = SNMP_DEFAULT_RETRIES; session->timeout = SNMP_DEFAULT_TIMEOUT; session->callback = snmp_input; session->callback_magic = (void *) t; session->authenticator = NULL; sess.isAuthoritative = SNMP_SESS_UNKNOWNAUTH; rc = snmp_add(session, t, pre_parse, NULL); if (rc == NULL) { snmp_sess_perror("snmptrapd", session); } return rc; }
struct snmp_session * simpleSNMPopen(gchar *peername, gint port, gchar *community, void *data) { struct snmp_session session, *ss; /* * initialize session to default values */ snmp_sess_init( &session ); session.version = SNMP_VERSION_1; session.community = community; session.community_len = strlen(community); session.peername = peername; session.remote_port = port; session.retries = SNMP_DEFAULT_RETRIES; session.timeout = SNMP_DEFAULT_TIMEOUT; session.callback = snmp_input; session.callback_magic = data; /* most likely a Reader */ session.authenticator = NULL; #ifdef STREAM session.flags |= SNMP_FLAGS_STREAM_SOCKET; #endif /* * Open an SNMP session. */ ss = snmp_open(&session); if (ss == NULL){ snmp_sess_perror("snmp_open", &session); // exit(1); } return ss; }
struct snmp_session *session_open(const char *chost, const char *ccommunity) { struct snmp_session *ss, session; char *host, *community; host=calloc(strlen(chost)+1, sizeof(char)); strcpy(host, chost); community=calloc(strlen(ccommunity)+1, sizeof(char)); strcpy(community, ccommunity); /* Initialize the SNMP library */ init_snmp("snmpapp"); /* Initialize the session */ snmp_sess_init( &session ); session.version = SNMP_VERSION_2c; session.peername = host; session.community = (u_char*)community; session.community_len = strlen(community); netsnmp_ds_set_int( NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, NETSNMP_OID_OUTPUT_UCD ); // NETSNMP_OID_OUTPUT_NONE); SOCK_STARTUP /* open the SNMP session */ ss = snmp_open(&session); if (ss == NULL) { perror("Cant snmp_open"); exit(-1); } netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, NETSNMP_OID_OUTPUT_NUMERIC); return ss; }