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
55
56
57
58
59
60
61
62
63
64
| int InitSNMP(int iOIDnum, char *strValue, LPSNMP_MGR_SESSION m_lpMgrSession)
{
char asciiStr[255] = " ";
char *pBuff=NULL;
AsnObjectIdentifier asnOid;
SnmpVarBindList snmpVarList;
AsnInteger errorStatus=0; // Error type that is returned if encountered
AsnInteger errorIndex=0; // Works with variable above
snmpVarList.list = NULL;
snmpVarList.len = 0;
snmpVarList.len++;
snmpVarList.list = (SnmpVarBind *)SNMP_realloc(snmpVarList.list, sizeof(SnmpVarBind) *snmpVarList.len);
SnmpMgrStrToOid(".1.3.6.1.2.1.2.2.1.5.5", &asnOid);
SnmpUtilOidCpy(&snmpVarList.list[0].name,&asnOid);
snmpVarList.list[0].value.asnType = ASN_OCTETSTRING;
sprintf(asciiStr,strValue);
snmpVarList.list[0].value.asnValue.string.dynamic = TRUE;
snmpVarList.list[0].value.asnValue.string.length = strlen(asciiStr)+1;
snmpVarList.list[0].value.asnValue.string.stream = (unsigned char*)
SnmpUtilMemAlloc(snmpVarList.list[0].value.asnValue.string.length*sizeof(char));
strcpy((char*)snmpVarList.list[0].value.asnValue.string.stream,asciiStr);
if(!SnmpMgrRequest(m_lpMgrSession,SNMP_PDU_SET,&snmpVarList,&errorStatus,&errorIndex))
{
SnmpUtilVarBindListFree(&snmpVarList);
SnmpUtilOidFree(&asnOid);
return 1;
}
if(errorStatus > 0)
{
sprintf(asciiStr,"Snmp Request Failed\nErrorStatus: %s ErrorIndex: %d",pBuff,errorIndex);
free(pBuff);
SnmpUtilVarBindListFree(&snmpVarList);
SnmpUtilOidFree(&asnOid);
return 1;
}
SnmpUtilOidFree(&asnOid);
SnmpUtilVarBindListFree(&snmpVarList);
return 0;
}
int main()
{
LPSNMP_MGR_SESSION session;
char resultat[MAX_PATH];
int iOIDnum=10;
char strValue[]="7";
session = SnmpMgrOpen("10.90.90.100","public",1000,3);
InitSNMP(iOIDnum, strValue, session);
SnmpMgrClose(session);
}else printf("Erreur SnmpMgrOpen\n");
system("PAUSE");
return 0;
} |