Hi,
I am using VC++6.0 in windows  to extend the netsnmp agent.  I am
getting a link error. I understand that I have not included the
appropriate header files. Code is attached. What header files should be
included for the agent to work properly.

Thanks and Regards,
S.Jega


snmp.lib - 0 error(s), 0 warning(s)
--------------------Configuration: libsnmp - Win32
Debug--------------------

--------------------Configuration: encode_keychange - Win32
Release--------------------
Compiling...
panduitAppsLED.c
Linking...
panduitAppsLED.obj : error LNK2001: unresolved external symbol
_netsnmp_register_scalar
panduitCommon.obj : error LNK2001: unresolved external symbol
_netsnmp_register_scalar
panduitAppsLED.obj : error LNK2001: unresolved external symbol
_netsnmp_create_handler_registration
panduitCommon.obj : error LNK2001: unresolved external symbol
_netsnmp_create_handler_registration
panduitAppsLED.obj : error LNK2001: unresolved external symbol
_netsnmp_request_get_list_data
panduitAppsLED.obj : error LNK2001: unresolved external symbol
_netsnmp_request_add_list_data
panduitAppsLED.obj : error LNK2001: unresolved external symbol
_netsnmp_set_request_error

--------------------Configuration: snmpd - Win32
Release--------------------
Linking...
netsnmpmibs.lib(mib_modules.obj) : error LNK2001: unresolved external
symbol _init_panduitAppsLED
../bin/release/snmpd.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

snmpd.exe - 2 error(s), 0 warning(s)


Sample Code is attached

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "C:\usr\include\net-snmp\agent\instance.h"
#include "panduitAppsLED.h"
//#include <unistd.h>

struct panduitApps
{
   int portled;
   int systemled;
}struct_obj;

FILE *fp;

char
led_fname[110]="D:\\Jegan\\downloads\\jegan\\AJack\\panduitAppsLED\\file.properties";

/** Purpose of the function create_panduitApps() is to check for the
**property file existence and to initialize the OIDs which
**have READ_WRITE Permissions
**/

void create_panduitApps()
{
 //Check for property file existence


fp  = fopen(led_fname,"w");

   struct_obj.portled=1;
   struct_obj.systemled=1;
   fwrite(&struct_obj,sizeof(struct panduitApps),1,fp);
fclose(fp);

}  // End of Function create_panduitApps()


/** Initializes the panduitAppsLED module */
void
init_panduitAppsLED(void)
{
    static oid      panduitLEDPortLedPeriod_oid[] =
        { 1, 3, 6, 1, 4, 1, 19536, 7, 4, 2 };
    static oid      panduitLEDSystemLedPeriod_oid[] =
        { 1, 3, 6, 1, 4, 1, 19536, 7, 4, 4 };

    DEBUGMSGTL(("panduitAppsLED", "Initializing\n"));

    netsnmp_register_scalar(

netsnmp_create_handler_registration("panduitLEDPortLedPeriod",handle_panduitLEDPortLedPeriod,panduitLEDPortLedPeriod_oid,OID_LENGTH(panduitLEDPortLedPeriod_oid),HANDLER_CAN_RWRITE));


netsnmp_register_scalar(netsnmp_create_handler_registration("panduitLEDSystemLedPeriod",handle_panduitLEDSystemLedPeriod,panduitLEDSystemLedPeriod_oid,OID_LENGTH(panduitLEDSystemLedPeriod_oid),HANDLER_CAN_RWRITE));

}

int
handle_panduitLEDPortLedPeriod(netsnmp_mib_handler *handler,
                               netsnmp_handler_registration *reginfo,
                               netsnmp_agent_request_info *reqinfo,
                               netsnmp_request_info *requests)
{
//     create_panduitApps();
     static int *cache=NULL;
     #define LED "led"
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get
one.
     */

    switch (reqinfo->mode) {

    case MODE_GET:
       fp=fopen(led_fname,"r");
 if(!fp)
 printf ("File cannot be opened in
handle_panduitLEDPortLedPeriod:MODE_GET\n");
 fseek(fp,sizeof(struct panduitApps),SEEK_SET);
 fread(&struct_obj,sizeof(struct panduitApps),1,fp);

        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *)&struct_obj.portled
                                 /* XXX: a pointer to the scalar's data
*/
                                 ,sizeof(struct_obj.portled)
                                 /*
                                  * XXX: the length of the data in bytes

                                  */ );
 fclose(fp);
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         *
http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        if ( requests->requestvb->type != ASN_INTEGER /* XXX: check
incoming data in requests->requestvb->val.XXX for failures, like an
incorrect type or an illegal value or ... */ ) {
            netsnmp_set_request_error(reqinfo,
requests,SNMP_ERR_WRONGTYPE
                                      /* XXX: set error code depending
on problem (like SNMP_ERR_WRONGTYPE or SNMP_ERR_WRONGVALUE or ... */
                                      );
        }
        break;

    case MODE_SET_RESERVE2:

 fp=fopen(led_fname,"r");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDPortLedPeriod:MODE_SET_RESERVE2\n");
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fread(&struct_obj,sizeof(struct panduitApps),1,fp);

 /*
         * XXX malloc "undo" storage buffer
         */
 memdup((u_char **) &cache,(u_char *)
&struct_obj.portled,sizeof(struct_obj.portled));

        if (cache == NULL /* XXX if malloc, or whatever, failed: */ ) {
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_RESOURCEUNAVAILABLE);
        }
 
netsnmp_request_add_list_data(requests,netsnmp_create_data_list(LED,cache,free));

 fclose(fp);
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called.
         */
        break;

    case MODE_SET_ACTION:
 fp=fopen(led_fname,"r+");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDPortLedPeriod:MODE_SET_ACTION\n");
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fread(&struct_obj,sizeof(struct panduitApps),1,fp);


        /*
         * XXX: perform the value change here
         */
 struct_obj.portled=*(requests->requestvb->val.integer);
 DEBUGMSGTL(("LED", "updated portled_period value ->
%d\n",struct_obj.portled));
 fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fwrite(&struct_obj,sizeof(struct panduitApps),1,fp);

        /*if (  XXX: error?  ) {
            netsnmp_set_request_error(reqinfo, requests,  some error
                                      );
        }*/
 fclose(fp);
        break;

    case MODE_SET_COMMIT:
    break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object
         */
 fp=fopen(led_fname,"r+");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDPortLedPeriod:MODE_SET_UNDO\n");
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fread(&struct_obj,sizeof(struct panduitApps),1,fp);
 struct_obj.portled=*((u_long
*)netsnmp_request_get_list_data(requests,LED));
 fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fwrite(&struct_obj,sizeof(struct panduitApps),1,fp);
 fclose(fp);

        break;

    default:
        /*
         * we should never get here, so this is a really bad error
         */
        snmp_log(LOG_ERR,
                 "unknown mode (%d) in
handle_panduitLEDPortLedPeriod\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}

int
handle_panduitLEDSystemLedPeriod(netsnmp_mib_handler *handler,
                                 netsnmp_handler_registration *reginfo,
                                 netsnmp_agent_request_info *reqinfo,
                                 netsnmp_request_info *requests)
{
//    create_panduitApps();
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get
one.
     */

    static int *cache = NULL;
    #define SYSTEM "SYSTEM"

    switch (reqinfo->mode) {

    case MODE_GET:
 fp=fopen(led_fname,"r");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDSystemLedPeriod:MODE_GET\n");
 fseek(fp,sizeof(struct panduitApps),SEEK_SET);
 fread(&struct_obj,sizeof(struct panduitApps),1,fp);
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *) &struct_obj.systemled
                                 /* XXX: a pointer to the scalar's data
*/
                                 ,sizeof(struct_obj.systemled)
                                 /*
                                  * XXX: the length of the data in bytes

                                  */ );
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         *
http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        if ( requests->requestvb->type != ASN_INTEGER /* XXX: check
incoming data in requests->requestvb->val.XXX for failures, like an
incorrect type or an illegal value or ... */ ) {
            netsnmp_set_request_error(reqinfo,
requests,SNMP_ERR_WRONGTYPE
                                      /* XXX: set error code depending
on problem (like SNMP_ERR_WRONGTYPE or SNMP_ERR_WRONGVALUE or ... */
                                      );
        }
        break;

    case MODE_SET_RESERVE2:
 fp=fopen(led_fname,"r");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDSystemLedPeriod:MODE_SET_RESERVE2\n");
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fread(&struct_obj,sizeof(struct panduitApps),1,fp);

        /*
         * XXX malloc "undo" storage buffer
         */
 memdup( (u_char **) &cache, (u_char *) &struct_obj.systemled,
sizeof(struct_obj.systemled) );
        if ( cache == NULL /* XXX if malloc, or whatever, failed: */ ) {

            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_RESOURCEUNAVAILABLE);
        }
 netsnmp_request_add_list_data(requests,
netsnmp_create_data_list(SYSTEM,cache,free));
 fclose(fp);
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called.
         */
        break;

    case MODE_SET_ACTION:
 fp=fopen(led_fname,"r+");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDSystemLedPeriod:MODE_SET_ACTION\n");
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fread(&struct_obj,sizeof(struct panduitApps),1,fp);

        /*
         * XXX: perform the value change here
         */
 struct_obj.systemled= *(requests->requestvb->val.integer);
        DEBUGMSGTL(("LED", "updated systemled_period value ->
%d\n",struct_obj.systemled));
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fwrite(&struct_obj,sizeof(struct panduitApps),1,fp);
 fclose(fp);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object
         */
 fp=fopen(led_fname,"r+");
        if(!fp)
        printf ("File cannot be opened in
handle_panduitLEDSystemLedPeriod:MODE_SET_UNDO\n");
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fread(&struct_obj,sizeof(struct panduitApps),1,fp);
        struct_obj.systemled=*((u_long
*)netsnmp_request_get_list_data(requests,SYSTEM));
        fseek(fp,sizeof(struct panduitApps),SEEK_SET);
        fwrite(&struct_obj,sizeof(struct panduitApps),1,fp);
        fclose(fp);
        break;

    default:
        /*
         * we should never get here, so this is a really bad error
         */
        snmp_log(LOG_ERR,
                 "unknown mode (%d) in
handle_panduitLEDSystemLedPeriod\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to