How to run netsnmp client/manager at a ma chine with Linux AS4?

"bahamute" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
 

Hi:
 
       I have wrote a client/manager ,and It can run well at the computer which install the Linux :2.6.18-8 and 2.6.21 。But when I run it at the Linux :Red Hat Enterprise Linux AS 4 (2.6.9-22) 。 the application could not run well. It display like this :
 
[root@localhost app6]#
[root@localhost app6]#
[root@localhost app6]# ./snmpdemoapp
snmp open = 154150000
read objid 1  3  6 ...  = 1
send pdu   = 1
111111111111111
errstat = 00000000
No log handling enabled - turning on stderr logging
snmpget: Too long
[root@localhost app6]#
 

 
      Look at this display and I think if my pdu packet is run ?but this process could run well at other operation system.
Dose not this client/manager run at the Linux : 2.6.9-22 ?
     Someone can help me ??
 
            Thank you very much!
 
                                                                Best wishs for you!
 
     And my code is in below :
 
 

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>

 /* change the word "define" to "undef" to try the (insecure) SNMPv1 version */
 #define DEMO_USE_SNMP_VERSION_1
 
 #ifdef DEMO_USE_SNMP_VERSION_3
 //#include "net-snmp/transform_oids.h"
 const char *our_v3_passphrase = "The Net-SNMP Demo Password";
 #endif
 
 main()
{
       struct snmp_session session, *ss;
       struct snmp_pdu *pdu;
       struct snmp_pdu *response;
           
       oid anOID[MAX_OID_LEN];
       size_t anOID_len = MAX_OID_LEN;
   
      struct variable_list *vars;
      int status = 0;
     /*
      * Initialize the SNMP library
     */
      while(1)
       {
      init_snmp("snmpapp");

      /*
      * Initialize a "session" that defines who we're going to talk to
      */
      snmp_sess_init( &session );                   /* set up defaults */
 //    printf("session initial = %d\n",status);   
 
     session.peername = "192.168.202.143";
   
     /* set up the authentication parameters for talking to the server */
   
     #ifdef DEMO_USE_SNMP_VERSION_3
   
     /* Use SNMPv3 to talk to the experimental server */
     
     /* set the SNMP version number */
     session.version=SNMP_VERSION_3;
        
     /* set the SNMPv3 user name */
     session.securityName = strdup("MD5User");
     session.securityNameLen = strlen(session.securityName);
   
     /* set the security level to authenticated, but not encrypted */
   //  session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
   
     /* set the authentication method to MD5 */
     session.securityAuthProto = usmHMACMD5AuthProtocol;
     session.securityAuthProtoLen = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
     session.securityAuthKeyLen = USM_AUTH_KU_LEN;
    
     /* set the authentication key to a MD5 hashed version of our
        passphrase "The Net-SNMP Demo Password" (which must be at least 8
        characters long) */
     if (generate_Ku(session.securityAuthProto,
                   session.securityAuthProtoLen,
                   (u_char *) our_v3_passphrase, strlen(our_v3_passphrase),
                   session.securityAuthKey,
                   &session.securityAuthKeyLen) != SNMPERR_SUCCESS) {
         //snmp_perror(argv[0]);
         snmp_log(LOG_ERR,
                "Error generating Ku from authentication pass phrase. \n");
         exit(1);
     }
   
     #else /* we'll use the insecure (but simplier) SNMPv1 */
   
     /* set the SNMP version number */
     session.version = SNMP_VERSION_1;
   
     /* set the SNMPv1 community name used for authentication */
     session.community = "public";
     session.community_len = strlen(session.community);
   
     #endif /* SNMPv1 */

     /* windows32 specific initialization (is a noop on unix) */
     SOCK_STARTUP;
   
     /*
      * Open the session
      */
     ss = snmp_open(&session);                     /* establish the session */
     printf("snmp open = %d\n",ss);
 
       if (!ss) {
         snmp_perror("ack");
         snmp_log(LOG_ERR, "something horrible happened!!!\n");
         exit(2);
       }
    
     /*
      * Create the PDU for the data for our request.
      *   1) We're going to GET the system.sysDescr.0 node.
      */
     pdu = snmp_pdu_create(SNMP_MSG_GET);
 
      //status = read_objid("ngntmonitor.1.1.2.1.0", anOID, &anOID_len);
      status = read_objid("1.3.6.1.4.1.343.2.7.2.1.1.4.135.0", anOID, &anOID_len);
      printf("read objid 1  3  6 ...  = %d\n",status); 
   
//      #if OTHER_METHODS
  //    get_node("sysDescr.0", anOID, &anOID_len);
    //  read_objid("system.sysDescr.0", anOID, &anOID_len);
   //   #endif
 
      snmp_add_null_var(pdu, anOID, anOID_len);

      /*
       * Send the Request out.
       */
      status = snmp_synch_response(ss, pdu, &response);
      printf("send pdu   = %d\n",status); 
      if(response == NULL)
    printf("111111111111111\n");
 
      printf("errstat = %08x\n",response);
      /*
      * Process the response.
      */
      if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
       /*
        * SUCCESS: Print the result variables
        */

       for(vars = response->variables; vars; vars = vars->next_variable)
       print_variable(vars->name, vars->name_length, vars);
 
        /* manipuate the information ourselves */
        for(vars = response->variables; vars; vars = vars->next_variable) {
          int count=1;
          if (vars->type == ASN_OCTET_STR) {
            char *sp = (char *)malloc(1 + vars->val_len);
            memcpy(sp, vars->val.string, vars->val_len);
            sp[vars->val_len] = '\0';
            printf("value #%d is a string: %s\n", count++, sp);
            free(sp);
          }
           else
            printf("value #%d is NOT a string! Ack!\n", count++);
     }
     

      } else {
        /*
          * FAILURE: print what went wrong!
         */
    
        if (status == STAT_SUCCESS)
          fprintf(stderr, "Error in packet\nReason: %s\n",
               snmp_errstring(response->errstat));
        else
          snmp_sess_perror("snmpget", ss);
    
   }

      /*
       * Clean up:
       *  1) free the response.
       *  2) close the session.
       */
      if (response)
        snmp_free_pdu(response);
        snmp_close(ss);
    
       /* windows32 specific cleanup (is a noop on unix) */
      SOCK_CLEANUP;
      sleep(1);
   
       }
}
 
 


劲 爆 150 万 同 时 在 线,众 人 追 捧 梦 幻 西 游

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

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