--===============1549720588==
Content-Type: Multipart/Alternative;
boundary="Boundary-=_ZsAImxMvFWCEpdYjLDXyXDpFELVM"


--Boundary-=_ZsAImxMvFWCEpdYjLDXyXDpFELVM
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hi :
=20
I want to write a client/manager . I read the Simple Application cod=
e at the page : http://www.net-snmp.org/wiki/index.p...imple_Applica=
tion . when I write codes follow this page ,and run it . my monitor displ=
ay is :
=20
[root@localhost app]#
[root@localhost app]#
[root@localhost app]# ./snmpdemoapp
snmp open =3D 157139280
read objid 1 3 6 ... =3D 1
send pdu =3D 1
111111111111111
errstat =3D 00000000
No log handling enabled - turning on stderr logging
snmpget: Timeout
[root@localhost app]#

And I can see that master-agent(process snmpd ) receive nothing messa=
ge . So I think that if my pdu packet is wrong ? Have someone can help me=
?Thank you !=20
=20
=
best wishs for you !
=20
=20
My code is in the below:
=20
=20

#include
#include

/* change the word "define" to "undef" to try the (insecure) SNMPv1 vers=
ion */
#define DEMO_USE_SNMP_VERSION_3
=20
#ifdef DEMO_USE_SNMP_VERSION_3
//#include "net-snmp/transform_oids.h"
const char *our_v3_passphrase =3D "The Net-SNMP Demo Password";
#endif
=20
main()
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu;
struct snmp_pdu *response;
=20
oid anOID[MAX_OID_LEN];
size_t anOID_len =3D MAX_OID_LEN;
=20
struct variable_list *vars;
int status =3D 0;
/*
* Initialize the SNMP library
*/
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 =3D %d\n",status); =20
=20
session.peername =3D "test.net-snmp.org";
=20
/* set up the authentication parameters for talking to the server */
=20
#ifdef DEMO_USE_SNMP_VERSION_3
=20
/* Use SNMPv3 to talk to the experimental server */
=20
/* set the SNMP version number */
session.version=3DSNMP_VERSION_3;
=20
/* set the SNMPv3 user name */
session.securityName =3D strdup("MD5User");
session.securityNameLen =3D strlen(session.securityName);
=20
/* set the security level to authenticated, but not encrypted */
session.securityLevel =3D SNMP_SEC_LEVEL_AUTHNOPRIV;
=20
/* set the authentication method to MD5 */
session.securityAuthProto =3D usmHMACMD5AuthProtocol;
session.securityAuthProtoLen =3D sizeof(usmHMACMD5AuthProtocol)/size=
of(oid);
session.securityAuthKeyLen =3D USM_AUTH_KU_LEN;
=20
/* 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) !=3D SNMPERR_SUCCESS) {
// snmp_perror(argv[0]);
snmp_log(LOG_ERR,
"Error generating Ku from authentication pass phrase. \n"=
);
exit(1);
}
=20
#else /* we'll use the insecure (but simplier) SNMPv1 */
=20
/* set the SNMP version number */
session.version =3D SNMP_VERSION_1;
=20
/* set the SNMPv1 community name used for authentication */
session.community =3D "demopublic";
session.community_len =3D strlen(session.community);
=20
#endif /* SNMPv1 */

/* windows32 specific initialization (is a noop on unix) */
SOCK_STARTUP;
=20
/*
* Open the session
*/
ss =3D snmp_open(&session); /* establish the ses=
sion */
printf("snmp open =3D %d\n",ss);
=20
if (!ss) {
snmp_perror("ack");
snmp_log(LOG_ERR, "something horrible happened!!!\n");
exit(2);
}
=20
/*
* Create the PDU for the data for our request.
* 1) We're going to GET the system.sysDescr.0 node.
*/
pdu =3D snmp_pdu_create(SNMP_MSG_GET);
=20

status =3D read_objid(".1.3.6.1.2.1.1.1.0", anOID, &anOID_len);
printf("read objid 1 3 6 ... =3D %d\n",status);=20
=20
// #if OTHER_METHODS
// get_node("sysDescr.0", anOID, &anOID_len);
// read_objid("system.sysDescr.0", anOID, &anOID_len);
// #endif
=20
snmp_add_null_var(pdu, anOID, anOID_len);

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

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

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

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

}

=20
=20
=20
=20
=20


=B0=D9 =CD=F2 =CD=AC =CA=B1 =D4=DA =CF=DF=A3=AC=C8=CB =C9=BD =C8=CB =BA=A3=
=CD=AC =CD=E6 =C3=CE =BB=C3 =CE=F7 =D3=CE =20
--Boundary-=_ZsAImxMvFWCEpdYjLDXyXDpFELVM
Content-Type: text/html; charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Hi :

 

     I want to write a client/manager . I read t=
he Simple Application code at the page : rg/wiki/index.php/TUT:Simple_Application">http://www.net-snmp.org/wiki/in=
dex.php/TUT:Simple_Application . when I write codes follow this =
page ,and run it . my monitor display is :

 

[root@localhost app]#
[root@localhost app]#
[root@localhost ap=
p]# ./snmpdemoapp
snmp open =3D 157139280
read objid 1  3&nbsp=
; 6 ...  =3D 1
send pdu   =3D 1
111111111111111
e=
rrstat =3D 00000000
No log handling enabled - turning on stderr loggin=
g
snmpget: Timeout
[root@localhost app]#

    And I can see that master-agent(process snmpd ) r=
eceive nothing message . So I think that if my pdu packet is wrong ? Have=
someone can help me ?Thank you !

 

           &n=
bsp;           &nb=
sp;           &nbs=
p;           &nbsp=
;            =
            &=
nbsp;  best wishs for you !

 

 

My code is in the below:

 

 


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


 /* change the word "define" to "undef" to try the (insecur=
e) SNMPv1 version */
 #define DEMO_USE_SNMP_VERSION_3
  R> #ifdef DEMO_USE_SNMP_VERSION_3
 //#include "net-snmp/tran=
sform_oids.h"
 const char *our_v3_passphrase =3D "The Net-SNMP De=
mo Password";
 #endif

 

 main()
{

       struct snmp_session session, *s=
s;
       struct snmp_pdu *pdu;
&nbsp=
;      struct snmp_pdu *response;
 &nbsp=
;        
   &=
nbsp;   oid anOID[MAX_OID_LEN];
    &nbs=
p;  size_t anOID_len =3D MAX_OID_LEN;
  
 &nbs=
p;    struct variable_list *vars;
   &nb=
sp;  int status =3D 0;

     /*
      * Init=
ialize the SNMP library
     */

      init_snmp("snmpapp");


      /*
    &nb=
sp; * Initialize a "session" that defines who we're going to talk to
&=
nbsp;     */
      snmp_s=
ess_init( &session );        =
           /* set up de=
faults */
 //    printf("session initial =3D %d\n"=
,status);  
 
     session.peer=
name =3D "test.net-snmp.org";
  
   &nbsp=
; /* set up the authentication parameters for talking to the server */
>  
     #ifdef DEMO_USE_SNMP_VERSION_3=

  
     /* Use SNMPv3 to talk to th=
e experimental server */
    
  &nbs=
p;  /* set the SNMP version number */
     se=
ssion.version=3DSNMP_VERSION_3;
      &n=
bsp;
     /* set the SNMPv3 user name */
&nbsp=
;    session.securityName =3D strdup("MD5User");
 =
    session.securityNameLen =3D strlen(session.securityNam=
e);
  
     /* set the security leve=
l to authenticated, but not encrypted */
     sess=
ion.securityLevel =3D SNMP_SEC_LEVEL_AUTHNOPRIV;
  
&nbs=
p;    /* set the authentication method to MD5 */
 =
    session.securityAuthProto =3D usmHMACMD5AuthProtocol;<=
BR>     session.securityAuthProtoLen =3D sizeof(usmHM=
ACMD5AuthProtocol)/sizeof(oid);
     session.secur=
ityAuthKeyLen =3D USM_AUTH_KU_LEN;
   
  =
   /* set the authentication key to a MD5 hashed version of our=

        passphrase "The Net-SNMP D=
emo Password" (which must be at least 8
     =
   characters long) */
     if (generate=
_Ku(session.securityAuthProto,
      &nb=
sp;            ses=
sion.securityAuthProtoLen,
       &=
nbsp;           (u_char=
*) our_v3_passphrase, strlen(our_v3_passphrase),
   &n=
bsp;           &nb=
sp;   session.securityAuthKey,
    &nbsp=
;            =
  &session.securityAuthKeyLen) !=3D SNMPERR_SUCCESS) {
 =
       // snmp_perror(argv[0]);
 &n=
bsp;       snmp_log(LOG_ERR,
 &nbsp=
;            =
  "Error generating Ku from authentication pass phrase. \n");
&nb=
sp;        exit(1);
  &nb=
sp;  }
  
     #else /* we'll u=
se the insecure (but simplier) SNMPv1 */
  
  =
   /* set the SNMP version number */
   &nbsp=
; session.version =3D SNMP_VERSION_1;
  
  &nb=
sp;  /* set the SNMPv1 community name used for authentication */
=
     session.community =3D "demopublic";
 &nb=
sp;   session.community_len =3D strlen(session.community);
&=
nbsp; 
     #endif /* SNMPv1 */


     /* windows32 specific initialization (i=
s a noop on unix) */
     SOCK_STARTUP;
 &=
nbsp;
     /*
      *=
Open the session
      */
  &nb=
sp;  ss =3D snmp_open(&session);     &n=
bsp;           &nb=
sp;   /* establish the session */
     p=
rintf("snmp open =3D %d\n",ss);

 

       if (!ss) {
  &nbsp=
;      snmp_perror("ack");
   =
      snmp_log(LOG_ERR, "something horrible happ=
ened!!!\n");
         exit(2);=

       }

   

     /*
      * Crea=
te the PDU for the data for our request.
    &nbsp=
; *   1) We're going to GET the system.sysDescr.0 node.
&nbs=
p;     */
     pdu =3D snmp_pd=
u_create(SNMP_MSG_GET);

 


      status =3D read_objid(".1.3.6.1.2=
=2E1.1.1.0", anOID, &anOID_len);
      pr=
intf("read objid 1  3  6 ...  =3D %d\n",status);
&nbsp=

//      #if OTHER_METHODS
  =
//    get_node("sysDescr.0", anOID, &anOID_len);
&n=
bsp;   //  read_objid("system.sysDescr.0", anOID, &anO=
ID_len);
   //   #endif

 

      snmp_add_null_var(pdu, anOID, anOID_l=
en);


      /*
    &nb=
sp;  * Send the Request out.
      =
*/
      status =3D snmp_synch_response(ss, =
pdu, &response);
      printf("send pdu&n=
bsp;  =3D %d\n",status);
      if(respo=
nse =3D=3D NULL)
    printf("111111111111111\n");
&n=
bsp;
      printf("errstat =3D %08x\n",respon=
se);

      /*
      =
* Process the response.
      */
 &nb=
sp;    if (status =3D=3D STAT_SUCCESS && response-=
>errstat =3D=3D SNMP_ERR_NOERROR) {
     &=
nbsp; /*
        * SUCCESS: Print t=
he result variables
        */
>

       for(vars =3D response->v=
ariables; vars; vars =3D vars->next_variable)
   &nb=
sp;   print_variable(vars->name, vars->name_length, vars)=
;

 

        /* manipuate the informat=
ion ourselves */
        for(vars =3D=
response->variables; vars; vars =3D vars->next_variable) {
&nbs=
p;         int count=3D1;
&nbs=
p;         if (vars->type =3D=3D=
ASN_OCTET_STR) {
        &nbs=
p;   char *sp =3D (char *)malloc(1 + vars->val_len);
&nbs=
p;           memcpy(sp,=
vars->val.string, vars->val_len);
    &nbsp=
;       sp[vars->val_len] =3D '\0';
&=
nbsp;           printf(=
"value #%d is a string: %s\n", count++, sp);
    &=
nbsp;       free(sp);
   =
       }
     &=
nbsp;     else
     &nbsp=
;      printf("value #%d is NOT a string! Ack!\n=
", count++);
     }
     DIV>

      } else {
   &nb=
sp;    /*
       &nb=
sp;  * FAILURE: print what went wrong!
    &n=
bsp;    */
   
   &nb=
sp;    if (status =3D=3D STAT_SUCCESS)
  &nbs=
p;       fprintf(stderr, "Error in packet\n=
Reason: %s\n",
         &=
nbsp;     snmp_errstring(response->errstat));
&=
nbsp;       else
   &nbsp=
;      snmp_sess_perror("snmpget", ss);
&nbsp=
;  
   }


      /*
    &nb=
sp;  * Clean up:
       *  1) =
free the response.
       *  2) clo=
se the session.
       */
 &nbsp=
;    if (response)
      =
  snmp_free_pdu(response);
      &n=
bsp; snmp_close(ss);
   
    &n=
bsp;  /* windows32 specific cleanup (is a noop on unix) */
 =
     SOCK_CLEANUP;

  


}


 

 

 

 

 




none" href=3D"http://event.mail.163.com/chanel/xyq.htm?from=3D126_NO3" ta=
rget=3D"_blank">=B0=
=D9 =CD=F2 =CD=AC =CA=B1 =D4=DA =CF=DF=A3=AC=C8=CB =C9=BD =C8=CB =BA=A3 =CD=
=AC =CD=E6 =C3=CE =BB=C3 =CE=F7 =D3=CE

--Boundary-=_ZsAImxMvFWCEpdYjLDXyXDpFELVM--


--===============1549720588==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
--===============1549720588==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

--===============1549720588==--