Compilation error (MIB)

"Mitul Sen (misen)" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <3B6F5C9068D5864096EB291236C3386F03B354F1@xmb-sjc-21d.amer.cisco.com>
Hello,

I have defined a MIB and the generated the C code for the managed object using mib2c. Once I added the implementation (I am simply using popen() to issue a command and I am trying to get the output of this command and pass it to the snmp_set_var_typed_value(..) function). However, my code doesn't seem to compile. I can however compile the same code (the lines that give the compilation error) on my linux machine as a standalone program (without net-snmp)

I have attached the code I am using. The compilation error is as follows

make[2]: Entering directory `/home/misen/work/snmp/net-snmp-5.4.2.1/agent/mibgroup'
/bin/sh ../../libtool  --mode=compile gcc -I../../include -I. -I../../agent -I../../agent/mibgroup -I../../snmplib   -g -O2 -Ulinux -Dlinux=linux  -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib/perl/5.8/CORE   -c -o ciscoDmpMIBHdmi.lo ciscoDmpMIBHdmi.c
 gcc -I../../include -I. -I../../agent -I../../agent/mibgroup -I../../snmplib -g -O2 -Ulinux -Dlinux=linux -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.8/CORE -c ciscoDmpMIBHdmi.c  -fPIC -DPIC -o .libs/ciscoDmpMIBHdmi.o
ciscoDmpMIBHdmi.c:18: warning: data definition has no type or storage class
ciscoDmpMIBHdmi.c:18: error: conflicting types for ‘fp’
ciscoDmpMIBHdmi.c:16: error: previous declaration of ‘fp’ was here
ciscoDmpMIBHdmi.c:18: warning: initialization makes integer from pointer without a cast
ciscoDmpMIBHdmi.c:18: error: initializer element is not constant
ciscoDmpMIBHdmi.c:20: error: expected identifier or ‘(’ before ‘if’
make[2]: *** [ciscoDmpMIBHdmi.lo] Error 1
make[2]: Leaving directory `/home/misen/work/snmp/net-snmp-5.4.2.1/agent/mibgroup'
make[1]: *** [subdirs] Error 1
make[1]: Leaving directory `/home/misen/work/snmp/net-snmp-5.4.2.1/agent'
make: *** [subdirs] Error 1




Not sure what I am doing wrong. Any help will be much appreciated.

Thanks and regards,
Mitul

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword

_______________________________________________
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
ciscoDmpMIBHdmi.c (text/x-csrc, 2.4 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
 */

#include <stdio.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "ciscoDmpMIBHdmi.h"

#define MAX_VAL_LEN 100

char my_ret_val[MAX_VAL_LEN];

FILE* fp;

fp = popen("my_com list sigma.hdmifreq", "r");

if (fp != NULL)
{
    while (fgets(my_ret_val, MAX_VAL_LEN, fp) != NULL)
	// my_ret_val should now have the value

}

//int my_var = 12;

/** Initializes the ciscoDmpMIBHdmi module */
void
init_ciscoDmpMIBHdmi(void)
{
    static oid      ciscoDmpMIBHdmi_oid[] =
        { 1, 3, 6, 1, 4, 1, 9, 9, 9999, 1, 1 };

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

    netsnmp_register_scalar(netsnmp_create_handler_registration
                            ("ciscoDmpMIBHdmi", handle_ciscoDmpMIBHdmi,
                             ciscoDmpMIBHdmi_oid,
                             OID_LENGTH(ciscoDmpMIBHdmi_oid),
                             HANDLER_CAN_RONLY));
}

int
handle_ciscoDmpMIBHdmi(netsnmp_mib_handler *handler,
                       netsnmp_handler_registration *reginfo,
                       netsnmp_agent_request_info *reqinfo,
                       netsnmp_request_info *requests)
{
    /*
     * 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:
        snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                 (u_char *) (my_ret_val),
                                 /* XXX: a pointer to the scalar's data */
                                /*sizeof(my_var)*/
				strlen(my_ret_val)+1 
                                 /*
                                  * XXX: the length of the data in bytes 
                                  */ );
        break;


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

    snmp_log(LOG_ERR, "returning %d\n", SNMP_ERR_GENERR);

    return SNMP_ERR_NOERROR;
}
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.