Hi All,

I haven't had an answer so I don't know if the mail was received. Just in case below is what i wrote.

thanks
Mauricio.

---------------------------------------------

Hi all,

I'm new to net snmp. i work with microsoft windows. I am trying to use the snmpdemoapp.c in the tutorial. but can't make it work. the snmpd.conf file is ok.
i am trying to use authentication and enryption using snmp v3. the user i created like this:


snmpusm  -v 3  -u initial -n "" -l authPriv -a MD5 -A setup_passphrase -x
DES -X setup_passphrase -l authPriv localhost create testusr initial
User successfully created.

snmpusm -v 3 -u testusr -n "" -l authPriv -a MD5 -A setup_passphrase -x D
ES -X setup_passphrase localhost passwd setup_passphrase testthispass
SNMPv3 Key(s) successfully changed.

a snmpget works well:

snmpget -v 3 -u testusr -n "" -l authPriv -a MD5 -A testthispass -x DES -X testthispass localhost system.sysContact.0

but when i use the code below i get: Why it says it doesn't support encryption, if it works above? the agent was compiled with openssl

No log handling enabled - turning on stderr logging
Encryption support not enabled.
snmpget: USM encryption error

thanks,
mauricio

i have done this:

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

const char *pass="testthispass";

int main(int argc, char ** argv)
{
  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;
  int count=1;

  init_snmp("snmpapp");

  snmp_sess_init( &session );
session.peername = strdup("127.0.0.1");

session.version=SNMP_VERSION_3;
session.securityName = strdup("testusr");
session.securityNameLen = strlen(session.securityName);
session.securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
session.securityAuthProto = usmHMACMD5AuthProtocol;
session.securityAuthProtoLen = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
session.securityAuthKeyLen = USM_AUTH_KU_LEN;
session.securityPrivProto = usmDESPrivProtocol;
session.securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
session.securityPrivKeyLen = USM_PRIV_KU_LEN;


if (generate_Ku(session.securityAuthProto,
                  session.securityAuthProtoLen,
                  (u_char *) pass, strlen(pass),
                  session.securityAuthKey,
                  &session.securityAuthKeyLen) != SNMPERR_SUCCESS) {
      snmp_perror(argv[0]);
      snmp_log(LOG_ERR,
               "Error generating Ku from authentication pass phrase. \n");
      exit(1);
  }

if (generate_Ku(session.securityAuthProto,
                  session.securityAuthProtoLen,
                  (u_char *) pass, strlen(pass),
                  session.securityPrivKey,
                  &session.securityPrivKeyLen) != SNMPERR_SUCCESS) {
      snmp_perror(argv[0]);
      snmp_log(LOG_ERR,
               "Error generating Ku from authentication pass phrase. \n");
      exit(1);
  }

  SOCK_STARTUP;
  ss = snmp_open(&session);

  if (!ss)
{
      snmp_perror("ack");
      snmp_log(LOG_ERR, "something horrible happened!!!\n");
      exit(2);
  }

  pdu = snmp_pdu_create(SNMP_MSG_GET);
  read_objid(".1.3.6.1.2.1.1.4.0", anOID, &anOID_len);

  snmp_add_null_var(pdu, anOID, anOID_len);

  status = snmp_synch_response(ss, pdu, &response);

  if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)
{

    for(vars = response->variables; vars; vars = vars->next_variable)
      print_variable(vars->name, vars->name_length, vars);

for(vars = response->variables; vars; vars = vars->next_variable)
{
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
{
if (status == STAT_SUCCESS)
fprintf(stderr, "Error in packet\nReason: %s\n",snmp_errstring(response->errstat));
else
snmp_sess_perror("snmpget", ss);
}


  if (response)
    snmp_free_pdu(response);
  snmp_close(ss);

  SOCK_CLEANUP;
  return (0);
}

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.com/




-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
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

Reply via email to