コード例 #1
0
int snmp_sess_synch_response(void * sessp,
			struct snmp_pdu *PDU,
			struct snmp_pdu **ResponsePDUP)
{
  struct snmp_session *Session;
  struct synch_state *state;
//  int numfds, count;
//  fd_set fdset;
//  struct timeval timeout, *tvp;
//  int block;
  DWORD dwStart;

  Session = snmp_sess_session(sessp);
  state = Session->snmp_synch_state;

  state->reqid = snmp_sess_send(sessp, PDU);
  if (state->reqid == 0) {
    *ResponsePDUP = NULL;
    snmp_free_pdu(PDU);
    return STAT_ERROR;
  }
  state->waiting = 1;

   dwStart = GetTickCount();
  while(state->waiting) {
     // this does the timeout...
     if( ( GetTickCount() - dwStart ) > 5000 ) break; // and fail...
     Sleep( 10 ); // let the rest of the box run for a while...
  }

  *ResponsePDUP = state->pdu;
  return state->status;
}
コード例 #2
0
ファイル: agentxtrap.c プロジェクト: nnathan/net-snmp
static void
NotifyingEntry(UNUSED tState self)
{
    netsnmp_pdu* act = snmp_clone_pdu(pdu);
    if(act) {
        act->sessid = session;
        act->transid = 0;
        act->reqid = ++packetid;
        if(snmp_sess_send(sessp, act) == 0)
            snmp_free_pdu(act);
    }
}
コード例 #3
0
ファイル: agentxtrap.c プロジェクト: nnathan/net-snmp
static void
ClosingEntry(UNUSED tState self)
{
    /* CLOSE pdu->errstat */
    netsnmp_pdu* act =
        pdu_create_opt_context(AGENTX_MSG_CLOSE, context, contextLen);
    if(act) {
        act->sessid = session;
        act->transid = 0;
        act->reqid = ++packetid;
        act->errstat = AGENTX_CLOSE_SHUTDOWN;
        if(snmp_sess_send(sessp, act) == 0)
            snmp_free_pdu(act);
    }
}
コード例 #4
0
ファイル: agentxtrap.c プロジェクト: nnathan/net-snmp
static void
OpeningEntry(UNUSED tState self)
{
    netsnmp_pdu* act =
        pdu_create_opt_context(AGENTX_MSG_OPEN, context, contextLen);
    if(act) {
        act->sessid = 0;
        act->transid = 0;
        act->reqid = ++packetid;
        act->time = 0;
        snmp_pdu_add_variable(act, NULL, 0, ASN_OCTET_STR, NULL, 0);
        if(snmp_sess_send(sessp, act) == 0)
            snmp_free_pdu(act);
    }
}
コード例 #5
0
void snmpDeliverTrap_netsnmp::deliverTrap(
    const String& trapOid,
    const String& securityName,
    const String& targetHost,
    const Uint16& targetHostFormat,
    const String& otherTargetHostFormat,
    const Uint32& portNumber,
    const Uint16& snmpVersion,
    const String& engineID,
    const Array<String>& vbOids,
    const Array<String>& vbTypes,
    const Array<String>& vbValues)
{

    PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpDeliverTrap_netsnmp::deliverTrap");

    void* sessionHandle;
    struct snmp_session* sessionPtr;

    struct snmp_pdu* snmpPdu;

    // Creates a SNMP session
    _createSession(targetHost, targetHostFormat, portNumber, securityName,
                   sessionHandle, sessionPtr);

    try
    {
        _createPdu(snmpVersion, trapOid, sessionPtr, snmpPdu);
    }
    catch (...)
    {
        _destroySession(sessionHandle);

        PEG_METHOD_EXIT();
        throw;
    }

    // Pack OIDs into the PDU
    try
    {
        _packOidsIntoPdu(vbOids, vbTypes, vbValues, snmpPdu);
    }
    catch (Exception& e)
    {
        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
            MessageLoaderParms(
                _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY,
                _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED,
                e.getMessage()));
    }
    catch (...)
    {
        PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
            "Snmp Indication Handler failed to pack a CIM "
                "Property into the SNMP PDU: Unknown exception.");
    }

    // Send the trap to the destination
    if (snmp_sess_send(sessionHandle, snmpPdu) == 0)
    {
        Sint32 libErr, sysErr;
        char* errStr;

        // snmp_sess_send failed
        // get library, system errno
        snmp_sess_error(sessionHandle, &libErr, &sysErr, &errStr);

        String exceptionStr = _MSG_SESSION_SEND_FAILED;
        exceptionStr.append(errStr);

        free(errStr);

        snmp_free_pdu(snmpPdu);

        _destroySession(sessionHandle);

        PEG_METHOD_EXIT();

        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
            MessageLoaderParms(_MSG_SESSION_SEND_FAILED_KEY, exceptionStr));
    }

    _destroySession(sessionHandle);

    PEG_METHOD_EXIT();
}
コード例 #6
0
ファイル: snmp_client.c プロジェクト: AllardJ/Tomato
int
snmp_sess_synch_response(void *sessp,
                         netsnmp_pdu *pdu, netsnmp_pdu **response)
{
    netsnmp_session *ss;
    struct synch_state lstate, *state;
    snmp_callback   cbsav;
    void           *cbmagsav;
    int             numfds, count;
    fd_set          fdset;
    struct timeval  timeout, *tvp;
    int             block;

    ss = snmp_sess_session(sessp);
    memset((void *) &lstate, 0, sizeof(lstate));
    state = &lstate;
    cbsav = ss->callback;
    cbmagsav = ss->callback_magic;
    ss->callback = snmp_synch_input;
    ss->callback_magic = (void *) state;

    if ((state->reqid = snmp_sess_send(sessp, pdu)) == 0) {
        snmp_free_pdu(pdu);
        state->status = STAT_ERROR;
    } else
        state->waiting = 1;

    while (state->waiting) {
        numfds = 0;
        FD_ZERO(&fdset);
        block = SNMPBLOCK;
        tvp = &timeout;
        timerclear(tvp);
        snmp_sess_select_info(sessp, &numfds, &fdset, tvp, &block);
        if (block == 1)
            tvp = NULL;         /* block without timeout */
        count = select(numfds, &fdset, 0, 0, tvp);
        if (count > 0) {
            snmp_sess_read(sessp, &fdset);
        } else
            switch (count) {
            case 0:
                snmp_sess_timeout(sessp);
                break;
            case -1:
                if (errno == EINTR) {
                    continue;
                } else {
                    snmp_errno = SNMPERR_GENERR;
                    /*
                     * CAUTION! if another thread closed the socket(s)
                     * waited on here, the session structure was freed.
                     * It would be nice, but we can't rely on the pointer.
                     * ss->s_snmp_errno = SNMPERR_GENERR;
                     * ss->s_errno = errno;
                     */
                    snmp_set_detail(strerror(errno));
                }
                /*
                 * FALLTHRU 
                 */
            default:
                state->status = STAT_ERROR;
                state->waiting = 0;
            }
    }
    *response = state->pdu;
    ss->callback = cbsav;
    ss->callback_magic = cbmagsav;
    return state->status;
}