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


C++ snmp_sess_init函数代码示例

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


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

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

示例2: csnmp_host_open_session

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 */
开发者ID:haojunyu,项目名称:collectd,代码行数:27,代码来源:snmp.c

示例3: init_master_agent

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;
}
开发者ID:Palantir555,项目名称:ecos-mars-zx3,代码行数:32,代码来源:snmp_agent.c

示例4: snmp_start_read_rssi

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);
}
开发者ID:n8ohu,项目名称:dmrshark,代码行数:34,代码来源:snmp.c

示例5: omsnmp_initSession

/* 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;
}
开发者ID:fastly,项目名称:rsyslog,代码行数:38,代码来源:omsnmp.c

示例6: init_ilo_snmp_session

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;
}
开发者ID:HewlettPackard,项目名称:zabbix-plugins-hpeilo,代码行数:26,代码来源:hpilo_snmp.c

示例7: throw

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;
}
开发者ID:dsilvan,项目名称:qt-net-snmp,代码行数:27,代码来源:qsnmpcore.cpp

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

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;
}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:26,代码来源:WIENER_SNMP.cpp

示例10: ConnectingEntry

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);
    }
}
开发者ID:nnathan,项目名称:net-snmp,代码行数:35,代码来源:agentxtrap.c

示例11: MPC_open

/*
 *  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);
}
开发者ID:ingted,项目名称:cluster-glue,代码行数:33,代码来源:wti_mpc.c

示例12: snprintf

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);
}
开发者ID:ClusterLabs,项目名称:corosync,代码行数:34,代码来源:corosync-notifyd.c

示例13: test_exec_sensor_cb

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);
}
开发者ID:redBorder,项目名称:rb_monitor,代码行数:26,代码来源:sensor_test.c

示例14: init_session_helper

/**
 * 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);
}
开发者ID:limasierra,项目名称:SatelliteConnectionMonitor,代码行数:11,代码来源:snmplib.c

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


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