Hi Robert,
The snmpget with v 3 works perfectly. I have checked the tutorial and based on it I modifyied to support both authentication and encryption. See code above. I don't know what it is. the weird thing is that it works on linux.
thanks Mauricio.
From: Robert Story (Users) <[EMAIL PROTECTED]> Reply-To: [EMAIL PROTECTED] To: "Mauricio Reyes" <[EMAIL PROTECTED]> CC: [EMAIL PROTECTED] Subject: Re: weird tutorial Date: Thu, 18 Nov 2004 17:06:54 -0500
On Thu, 18 Nov 2004 19:16:07 +0000 Mauricio wrote:
MR> The client has also openssl, I included the libeay32.lib in it. Besides, I
MR> run the normal snmpget and it works fine. what else could be the problem?
You run the normal snmpget with -v3 and encryption options, and it works? If
that's the case, then the libraries should work with a properly coded
application.
Have you checked out the tutorial's use of v3?
http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demoapp/snmpdemoapp.c
--
Robert Story; NET-SNMP Junkie
Support: <http://www.net-snmp.org/> <irc://irc.freenode.net/#net-snmp>
Archive: <http://sourceforge.net/mailarchive/forum.php?forum=net-snmp-users>
You are lost in a twisty maze of little standards, all different.
------------CODE---------------
#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.click-url.com/go/onm00200415ave/direct/01/
------------------------------------------------------- This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8 _______________________________________________ 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