I send V3 broadcast packet to discover snmp devices in LAN and I can't get
respondents's IP address. I can get MIB values from only one device at one time
when using SNMPv3. All the devices in LAN have same AUTH.,privacy,username and
password.
Codes:
BOOL snmp_broadcast(HOST_IP *host_ip)
{
//struct session *hs = sessions;
struct snmp_pdu *req;
struct snmp_session sess,*Session;
struct oid1 *current_oid;
// struct sockaddr_in *psa;
struct timeval timeout;
fd_set fdset;
// int fd;
int fds = 0, block = 0;
DWORD lasttime;
BOOL bsnmpok = FALSE;
/* startup open host */
snmp_sess_init(&sess); /* initialize session */
CString csIP ;//= inet_ntoa(addr_in);
csIP.Format("192.168.5.109:%d",setinfo.uPort);
sess.peername = csIP.GetBuffer(0);
if(setinfo.SnmpVer==0){
sess.version = SNMP_VERSION_1;
}else{
/////////////////////
EnterCriticalSection(&g_ResetLib);
snmp_shutdown("libsnmp");
initializesnmp();
LeaveCriticalSection(&g_ResetLib);
TCHAR our_v3_passphrase[32] = {0};
TCHAR AuthName[32] = {0};
_tcscpy(AuthName,setinfo.szAuthName);
_tcscpy(our_v3_passphrase,setinfo.szAuthPass);
sess.version=SNMP_VERSION_3;
/* set the SNMPv3 user name */
sess.securityName = AuthName;
sess.securityNameLen = strlen(sess.securityName);
/* set the security level to authenticated, but not encrypted */
sess.securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
if(setinfo.AuthProto==0)
{
sess.securityAuthProto =
snmp_duplicate_objid(usmHMACMD5AuthProtocol,USM_AUTH_PROTO_MD5_LEN);
sess.securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
}else
{
sess.securityAuthProto =
snmp_duplicate_objid(usmHMACSHA1AuthProtocol,
USM_AUTH_PROTO_SHA_LEN);
sess.securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
}
sess.securityAuthKeyLen = USM_AUTH_KU_LEN;
if(SNMPERR_SUCCESS != generate_Ku(sess.securityAuthProto,
sess.securityAuthProtoLen,
(u_char *)our_v3_passphrase,
strlen(our_v3_passphrase),
sess.securityAuthKey,
&sess.securityAuthKeyLen)
)
{
return FALSE;
}
/* set the privacy method to DES */
if(setinfo.PrivProto==0)
{
sess.securityPrivProto =
snmp_duplicate_objid(usmDESPrivProtocol,USM_PRIV_PROTO_DES_LEN);
sess.securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
}else
{
sess.securityPrivProto =
snmp_duplicate_objid(usmAESPrivProtocol,
USM_PRIV_PROTO_AES_LEN);
sess.securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
}
sess.securityPrivKeyLen = USM_PRIV_KU_LEN;
if (SNMPERR_SUCCESS != generate_Ku(sess.securityAuthProto,
sess.securityAuthProtoLen,
(u_char *)our_v3_passphrase,
strlen(our_v3_passphrase),
sess.securityPrivKey,
&sess.securityPrivKeyLen))
{
return FALSE;
}
}
///////////////////////////////////
sess.community =(unsigned char*)setinfo.szCommunity;
sess.community_len = strlen((const char*)sess.community);
sess.flags |= 0x800;
sess.callback = snmp_broadcast_response; /* callback does not run */
sess.callback_magic = (void*)host_ip;
if (!(Session = snmp_open(&sess)))
{
//snmp_perror("snmp_open");
return FALSE;
}
/* Do send request to hosts */
/* poocess_type = (0 for search device, 1 for look Battery status, 2 for look
AC status) */
current_oid = &oids[0];
req = snmp_pdu_create(SNMP_MSG_GET);
/* send the first GET */
snmp_add_null_var(req, current_oid->Oid, current_oid->OidLen);
/* int status = 0;
netsnmp_pdu *response;
status = snmp_synch_response(Session, req, &response);
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
snmp_ipaddr *pipaddress = (snmp_ipaddr*)response->transport_data;
long u_tmp = pipaddress->sa_align;
char tmp[20]={0};
sprintf(tmp, "%d.%d.%d.%d\n" , (u_tmp&0xFF),
(u_tmp>>8)&0xFF,(u_tmp>>16)&0xFF,(u_tmp>>24)&0xFF);
TRACE0(tmp);
}*/
if (!(snmp_send(Session, req)))
{
//snmp_perror("snmp_send");
snmp_free_pdu(req);
snmp_close(Session);
return FALSE;
}
/* struct timeval *tvp;
int numfds, count;*/
//Read response
lasttime = GetTickCount();
int fff = 0;
do {
FD_ZERO(&fdset);
snmp_select_info(&fds, &fdset, &timeout, &block);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if(select(0, &fdset, NULL, NULL, &timeout) > 0)
{TRACE0("nnnnnn\n");
snmp_read(&fdset);
char *err=0;
snmp_error(Session, NULL, NULL, &err);
// TRACE0(err);
bsnmpok = TRUE;
}
} while(/*(GetTickCount() - lasttime) < 6000*/fff++<5);
// cleanup
snmp_close(Session);
return bsnmpok;
}
Please tell me why.
Thanks.------------------------------------------------------------------------------
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