WINSNMP Response schlägt fehl bei SnmpRecvMsg



  • Liebes Community-Forum,

    ich versuche mich gerade in der WINSNMP-API einen SNMP-Manager zu erstellen.
    Das Senden der Get-Nachricht funktioniert. Der SNMP-Agent erhält die Nachricht und gibt auch eine Response-Nachricht zurück. Jedoch bricht schlägt mein SnmpRecvMsg mit dem Fehler 8 (NOOP) fehl.

    So sieht mein Code in Visual Studio 2013 Express aus:

    [code]
    #include <Windows.h>
    #include <WinInet.h>
    #include <WinSnmp.h>
    #include <iostream>

    using namespace std;

    SNMPAPI_STATUS CALLBACK snmpProc(HSNMP_SESSION hSession, HWND hWnd, UINT wMSG, WPARAM wParam, LPARAM lParam, LPVOID lpClientData)
    {
    return 0;
    }

    int main()
    {
    HSNMP_SESSION hSession;
    unsigned long lMajor;
    unsigned long lMinor;
    unsigned long lLevel;
    unsigned long lVersion;
    unsigned long lTranslation;
    unsigned long lOn;
    HSNMP_ENTITY dst, src;
    HSNMP_CONTEXT context;
    smiBYTE pByteData[] = "public";
    smiOCTETS smiOct = { 6, (smiLPBYTE)pByteData };
    smiOID smiOid;
    smiVALUE dValue;

    if (SnmpStartupEx(&lMajor, &lMinor, &lLevel, &lTranslation, &lOn) != SNMPAPI_SUCCESS)
    cout << "Startup fehlgeschlagen" << endl;

    SnmpSetRetransmitMode(SNMPAPI_ON);

    if (!(hSession = SnmpCreateSession(GetConsoleWindow(), 0, snmpProc, NULL)))
    cout << "Session fehlgeschlagen" << endl;

    dst = SnmpStrToEntity(hSession, "....");
    src = SnmpStrToEntity(hSession, "....");

    // OCTET of interests
    context = SnmpStrToContext(hSession, &smiOct);
    smiUINT32 OID[] = { 1, 3, 6, 1, 2, 1, 1, 1, 0 };
    smiOid.ptr = (smiLPUINT32)OID;
    smiOid.len = 9;
    dValue.syntax = SNMP_SYNTAX_OCTETS;
    dValue.value.uNumber = 0;

    // Senden der Nachricht
    HSNMP_VBL vblData = SnmpCreateVbl(hSession, &smiOid, &dValue);
    HSNMP_PDU pduData = SnmpCreatePdu(hSession, SNMP_PDU_GET, NULL, NULL, NULL, vblData);

    if (SnmpSendMsg(hSession, src, dst, context, pduData) == SNMPAPI_FAILURE)
    cout << "Senden fehlgeschlagen" << endl;

    // Empfangen der Nachricht

    HSNMP_ENTITY dstZiel, srcZiel;
    HSNMP_CONTEXT hContextZiel ;
    HSNMP_PDU pduDataZiel;
    HSNMP_VBL vblDataZiel;

    if (SnmpRecvMsg(hSession, &srcZiel, &dstZiel, &hContextZiel, &pduDataZiel) != SNMPAPI_FAILURE)
    {
    //if (SnmpSendMsg(hSession, dst, src, context, pduDataZiel) == SNMPAPI_FAILURE)
    cout << "Empfangen.." << endl;

    SNMPAPI_STATUS st = SnmpGetLastError(hSession);

    smiOID nSmiOID;
    smiVALUE nSmiValue;
    smiINT pduType;
    smiINT32 iReqID;
    if (SnmpGetPduData(pduDataZiel, &pduType, &iReqID, NULL, NULL, &vblDataZiel) != SNMPAPI_SUCCESS)
    cout << "PDUUmwandeln fehlgeschlagen" << endl;

    if (SnmpGetVb(vblDataZiel, iReqID, &nSmiOID, &nSmiValue) != SNMPAPI_SUCCESS)
    cout << "Umwandeln fehlgeschlagen" << endl;

    SNMPAPI_STATUS st2 = SnmpGetLastError(hSession);
    }

    SnmpClose(hSession);

    SnmpCleanup();

    system("Pause");
    }

    Ich hoffe Ihr könnt mir hierzu ein paar Tipps geben, da ich schon lange an diesem Problem mich vergnüge. Vielen Dank vorab...


Anmelden zum Antworten