1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| LireMultOid(char* id, char *resultat , LPSNMP_MGR_SESSION session)
{
SnmpVarBindList snmpVarList; //Structure variable Snmp
AsnInteger errorStatus,errorIndex;
int j = 1;
char* test;
char testbis[256];
snmpVarList.list = NULL;
snmpVarList.len = 1;
snmpVarList.list = (SnmpVarBind *)realloc(snmpVarList.list, sizeof(SnmpVarBind) *snmpVarList.len);
SnmpMgrStrToOid(id,&snmpVarList.list[0].name);
do
{
if (SnmpMgrRequest(session,SNMP_PDU_GETNEXT,&snmpVarList,&errorStatus,&errorIndex)!=0)
{
if (errorStatus==SNMP_ERRORSTATUS_NOERROR)
{
//printf("Lecture OK\n");
//printf("[%s]\n",id); // AFFICHE L'OID CHERCHER
// SnmpUtilPrintAsnAny(&snmpVarList.list[0].value); //AFFICHE LA VALEUR DE L'OID
//char* szValue = (char*)(snmpVarList.list[0].value.asnValue.string.stream);
char* szValue = (char*)(snmpVarList.list[0].value);
}
}
j=j++;
}
while(j!=125);
return 0;
}
int main(int argc, char* argv[])
{
LPSNMP_MGR_SESSION session;
char resultat[MAX_PATH];
char* oid;
oid = ".1.3.6.1.2.1.17.4.3.1.1"; // PORTNAME
session = SnmpMgrOpen("192.168.2.82","public",1000,3); //ouverture de session
if (session!=0)
{
printf("Connexion OK\n");
LireMultOid(oid ,resultat,session); //id racine
}
else printf("Erreur SnmpMgrOpen\n");
SnmpMgrClose(session); //fermeture
system("PAUSE");
return 0;
} |
Partager