Simple application

"gilles B" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
hi,

I'am trying to use example to learn net-snmp library use.
So, i just code the following (see below), but it exits with error:

ack:  (apptest.net-snmp.org)
something horrible happened!!!


What could be the error ?

Thks
gilles


------------------------------------------------------
#include <windows.h>
#include <iostream>
#include <fstream>

#ifdef _VCPP_
#include "consredirect.h"
#endif

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/session_api.h>
#include <net-snmp/library/snmp_logging.h>


using namespace std;

///////////////////////////////////////////////////////////////////////////////
// WINSOCK
// WINSOCK
// WINSOCK
void winsock_cleanup(void)
{
    WSACleanup();
}

///////////////////////////////////////////////////////////////////////////////
// WINSOCK
// WINSOCK
// WINSOCK
char *winsock_startup(void)
{
    WORD            VersionRequested;
    WSADATA         stWSAData;
    int             i;
    static char     errmsg[100];

	/* winsock 1: use MAKEWORD(1,1) */
	/* winsock 2: use MAKEWORD(2,2) */

    VersionRequested = MAKEWORD(2,2);
    i = WSAStartup(VersionRequested, &stWSAData);
    if (i != 0) {
        if (i == WSAVERNOTSUPPORTED)
            sprintf(errmsg,
                    "Unable to init. socket lib, does not support 1.1");
        else {
            sprintf(errmsg, "Socket Startup error %d", i);
        }
        return (errmsg);
    }
    return (NULL);
}


///////////////////////////////////////////////////////////////////////////////
// MAIN
// MAIN
// MAIN
#define SOCK_STARTUP winsock_startup()
#define SOCK_CLEANUP winsock_cleanup()

//int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR 
lpCmdLine,int nCmdShow)
int main(int argc, char *argv[])
{
	//----
	struct snmp_session snmpsession, *ss;

	#ifdef _VCPP_
	RedirectIOToConsole();
	#endif

	//----
	cout<<"Essai d'un serveur de reception de traps"<<endl;

	init_snmp("snmpapp");
	snmp_enable_stderrlog();
	snmp_sess_init(&snmpsession);
	snmpsession.peername = "apptest.net-snmp.org";


    /* set the SNMP version number */
    snmpsession.version = SNMP_VERSION_1;

    /* set the SNMPv1 community name used for authentication */
    snmpsession.community = (unsigned char *)"public";
    snmpsession.community_len = strlen((char *)snmpsession.community);

	SOCK_STARTUP;

	/*
     * Open the session
     */
    ss = snmp_open(&snmpsession);                     /* establish the 
session */
	if(!ss) {
		snmp_perror("ack");
        snmp_log(LOG_ERR, "something horrible happened!!!\n");
		SOCK_CLEANUP;
		Sleep(2000);
        exit(2);
	} else {
		cout<<"Ok SNMP open"<<endl;
	} // end if


	cout<<"Version:"<<snmpsession.version<<endl;


	Sleep(2000);

	SOCK_CLEANUP;

	return 0;
}
------------------------------------------------------




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.