NET-SNMP -> C program in localhost ?

Madi Aurélien <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hello,

I'm discovering SNMP C programmation and I've developped the following program, 
with the help of NET-SNMP tutorial. It's almost the same code as tuto's code, 
but which is running in localhost (or 127.0.0.1). It doesn't work, but the 
tuto's application works fine !

When I compile and run the application, but instead of having an object value 
(like a STRING or INTEGER), it displays : 

.1702326096.1952796274.1112100141.1886730810.1935753843.1968137065.1953853556.1952543827.841905013.0.990059265.36.3.4294966456


PowerNet-MIB::upsBasicOutputStatus.0 = Wrong Type (should be INTEGER): NULL
PowerNet-MIB::upsBasicOutputStatus.2 = Wrong Type (should be INTEGER): NULL

I tried so many solutions, but nothing I found can fix this "wrong type" error. 
I understand the whole code (each of its line), but I can't find the reason that 
make it doesn't work. I guess it comes from SNMP in general (or NET-SNMP), but 
I'm newbie with this protocol, so I really don't know.

My goal is just to display the value of an object from a personal MIB ("home 
made"), but for now I'm working with tools from tutorial ().

Have you any idea ?

thanks to everyone.

----------------------------------
C Code :: with "localhost" parameter


#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
int main(int argc, char ** argv)
{
      struct snmp_session session;
      struct snmp_session *sess_handle;
      struct snmp_pdu *pdu;
      struct snmp_pdu *response;
      struct variable_list *vars;
      oid id_oid[MAX_OID_LEN];
      oid serial_oid[MAX_OID_LEN];
      size_t id_len = MAX_OID_LEN;
      size_t serial_len = MAX_OID_LEN;
      int status;
      struct tree * mib_tree;
      
      /*********************/
      init_mib();
      if(argv[1] == NULL){
 printf("Please supply a hostname\n");
 exit(1);
      }
      
      init_snmp("test_PowerNet");
      
      snmp_sess_init( &session );
      session.version = SNMP_VERSION_1;
      session.community = "public";
      session.community_len = strlen(session.community);
      session.peername = argv[1];
      sess_handle = snmp_open(&session);
      
      add_mibdir(".");
      mib_tree = read_mib("NET-SNMP-TUTORIAL-MIB.txt");
      pdu = snmp_pdu_create(SNMP_MSG_GET);
      
      read_objid("NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0", id_oid, 
&id_len);
      snmp_add_null_var(pdu, id_oid, id_len);
      read_objid("NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0", serial_oid, 
&serial_len);
      snmp_add_null_var(pdu, serial_oid, serial_len);
      
      print_objid("NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0",id_len);
      /**
      *returns : 
     
 .1702326096.1952796274.1112100141.1886730810.1935753843.1968137065.1953853556.1952543827.841905013.0.990059265.36.3.4294966464

      **/
      status = snmp_synch_response(sess_handle, pdu, &response);
      for(vars = response->variables; vars; vars = vars->next_variable){
 print_variable(vars->name, vars->name_length, vars);
      }
      
      snmp_free_pdu(response);
      snmp_close(sess_handle);
      
      return (0);
}

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev

_______________________________________________
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.