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ILE=CE=C4=BC=FE=A3=AC=D5=
=E2=C0=EF=BE=CD=B2=BB=C1=D0=B3=F6=C1=CB=A1=A3</P>
<P =
align=3Dleft>=D2=D4=CF=C2=CA=C7SNMPUTIL.C=CE=C4=BC=FE=A3=BA</P><PRE>/*++ =
BUILD Version: 0001 // Increment this if a change has global effects
Copyright (c) 1991-1995 Microsoft Corporation
=20
Module Name:
=20
snmputil.c
=20
Abstract:
=20
Sample SNMP Management API usage for Windows NT.
=20
This file is an example of how to code management =
applications using
the SNMP Management API for Windows NT. It is similar in =
operation to
the other commonly available SNMP command line utilities.
=20
Extensive comments have been included to describe its =
structure and
operation. See also "Microsoft Windows/NT SNMP =
Programmer's Reference".
=20
Created:
=20
28-Jun-1991
=20
Revision History:
=20
--*/
static char *vcsid =3D "@(#) $Logfile: =
N:/agent/mgmtapi/vcs/snmputil.c_v $ $Revision: 1.5 $";
// General notes:
// Microsoft's SNMP Management API for Windows NT is implemented as a =
DLL
// that is linked with the developer's code. These APIs (examples =
follow in
// this file) allow the developer's code to generate SNMP queries and =
receive
// SNMP traps. A simple MIB compiler and related APIs are also =
available to
// allow conversions between OBJECT IDENTIFIERS and OBJECT DESCRIPTORS.
// Necessary includes.
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <snmp.h>
#include <mgmtapi.h>
// Constants used in this example.
#define GET 1
#define GETNEXT 2
#define WALK 3
#define TRAP 4
#define TIMEOUT 6000 /* milliseconds */
#define RETRIES 3
// Main program.
INT _CRTAPI1 main(
IN int argumentCount,
IN char *argumentVector[])
=20
{
INT operation;
LPSTR agent;
LPSTR community;
RFC1157VarBindList variableBindings;
LPSNMP_MGR_SESSION session;
=20
INT timeout =3D TIMEOUT;
INT retries =3D RETRIES;
=20
BYTE requestType;
AsnInteger errorStatus;
AsnInteger errorIndex;
char *chkPtr =3D NULL;
=20
=20
// Parse command line arguments to determine requested operation.
=20
// Verify number of arguments...
if (argumentCount < 5 && argumentCount !=3D 2)
{
printf("Error: Incorrect number of arguments specified.\n");
printf(
"\nusage: snmputil [get|getnext|walk] agent community oid =
[oid ...]\n");
printf(
" snmputil trap\n");
=20
return 1;
}
=20
// Get/verify operation...
argumentVector++;
argumentCount--;
if (!strcmp(*argumentVector, "get"))
operation =3D GET;
else if (!strcmp(*argumentVector, "getnext"))
operation =3D GETNEXT;
else if (!strcmp(*argumentVector, "walk"))
operation =3D WALK;
else if (!strcmp(*argumentVector, "trap"))
operation =3D TRAP;
else
{
printf("Error: Invalid operation, '%s', specified.\n",
*argumentVector);
=20
return 1;
}
=20
if (operation !=3D TRAP)
{
if (argumentCount < 4)
{
printf("Error: Incorrect number of arguments =
specified.\n");
printf(
"\nusage: snmputil [get|getnext|walk] agent community =
oid [oid ...]\n");
printf(
" snmputil trap\n");
=20
return 1;
}
=20
// Get agent address...
argumentVector++;
argumentCount--;
agent =3D (LPSTR)SNMP_malloc(strlen(*argumentVector) + 1);
strcpy(agent, *argumentVector);
=20
// Get agent community...
argumentVector++;
argumentCount--;
community =3D (LPSTR)SNMP_malloc(strlen(*argumentVector) + 1);
strcpy(community, *argumentVector);
=20
// Get oid's...
variableBindings.list =3D NULL;
variableBindings.len =3D 0;
=20
while(--argumentCount)
{
AsnObjectIdentifier reqObject;
=20
argumentVector++;
=20
// Convert the string representation to an internal =
representation.
if (!SnmpMgrStrToOid(*argumentVector, &reqObject))
{
printf("Error: Invalid oid, %s, specified.\n", =
*argumentVector);
=20
return 1;
}
else
{
// Since sucessfull, add to the variable bindings list.
variableBindings.len++;
if ((variableBindings.list =3D (RFC1157VarBind =
*)SNMP_realloc(
variableBindings.list, sizeof(RFC1157VarBind) *
variableBindings.len)) =3D=3D NULL)
{
printf("Error: Error allocating oid, %s.\n",
*argumentVector);
=20
return 1;
}
=20
variableBindings.list[variableBindings.len - 1].name =3D
reqObject; // NOTE! structure copy
variableBindings.list[variableBindings.len - =
1].value.asnType =3D
ASN_NULL;
}
} // end while()
=20
// Make sure only one variable binding was specified if =
operation
// is WALK.
if (operation =3D=3D WALK && variableBindings.len !=3D =
1)
{
printf("Error: Multiple oids specified for WALK.\n");
=20
return 1;
}
=20
=20
// Establish a SNMP session to communicate with the remote =
agent. The
// community, communications timeout, and communications retry =
count
// for the session are also required.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -