snmp.pas

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
{***************************************************************************** Copyright 1992 - 1998 Microsoft Corporation
Translate:Kingron
Mail: Kingron@163.net
Web: http://kingron.myetang.com
Module Name:
snmp.h
Abstract:
Definitions for SNMP development.
*****************************************************************************}
unit SNMP;
interface
uses windows;
{$IFNDEF _INC_SNMP}
{$DEFINE _INC_SNMP}
{$ENDIF}
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Type Definitions //
// //
///////////////////////////////////////////////////////////////////////////////
const
Inetmib1 = 'Inetmib1.dll';
Igmpagnt = 'igmpagnt.dll';
snmpapidll = 'snmpapi.dll';
type
PByteAr=array[0..1000] of byte;
type
TAsnOctetString = packed record
stream: PByteAr;
length: UINT;
dynamic: BOOL;
end;
TAsnObjectIdentifier = packed record
idLength: UINT; /// Length of IDS
ids: pointer; /// Pointer to oid array
end;
PAsnObjectIdentifier = ^TAsnObjectIdentifier;
LONG = WORD;
TAsnInteger32 = LONG;
TAsnUnsigned32 = DWORD;
TAsnCounter64 = ULARGE_INTEGER;
TAsnCounter32 = TAsnUnsigned32;
TAsnGauge32 = TAsnUnsigned32;
TAsnTimeticks = TAsnUnsigned32;
TAsnBits = TAsnOctetString;
TAsnSequence = TAsnOctetString;
TAsnImplicitSequence = TAsnOctetString;
TAsnIPAddress = TAsnOctetString;
TAsnNetworkAddress = TAsnOctetString;
TAsnDisplayString = TAsnOctetString;
TAsnOpaque = TAsnOctetString;
TAsnValue = packed record
number: TAsnInteger32; // ASN_INTEGER
// ASN_INTEGER32
unsigned32: TAsnUnsigned32; // ASN_UNSIGNED32
counter64: TAsnCounter64; // ASN_COUNTER64
Astring: TAsnOctetString; // ASN_OCTETSTRING
bits: TAsnBits; // ASN_BITS
Aobject: TAsnObjectIdentifier; // ASN_OBJECTIDENTIFIER
sequence: TAsnSequence; // ASN_SEQUENCE
address: TAsnIPAddress; // ASN_IPADDRESS
counter: TAsnCounter32; // ASN_COUNTER32
gauge: TAsnGauge32; // ASN_GAUGE32
ticks: TAsnTimeticks; // ASN_TIMETICKS
arbitrary: TAsnOpaque; // ASN_OPAQUE
end;
TAsnAny = packed record
asnType: BYTE;
asnValue: TAsnValue;
end;
TAsnObjectName = TAsnObjectIdentifier;
TAsnObjectSyntax = TAsnAny;
TSnmpVarBind = packed record
name: TAsnObjectName;
value: TAsnObjectSyntax;
end;
TSnmpVarBindList = packed record
list: pointer;
len: UINT;
end;
{$IFNDEF _INC_WINSNMP}
///////////////////////////////////////////////////////////////////////////////
// //
// ASN/BER Base Types //
// //
///////////////////////////////////////////////////////////////////////////////
const
ASN_UNIVERSAL = $00;
ASN_APPLICATION = $40;
ASN_CONTEXT = $80;
ASN_PRIVATE = $C0;
ASN_PRIMITIVE = $00;
ASN_CONSTRUCTOR = $20;
///////////////////////////////////////////////////////////////////////////////
// //
// PDU Type Values //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_PDU_GET = ASN_CONTEXT or ASN_CONSTRUCTOR or $0;
SNMP_PDU_GETNEXT = ASN_CONTEXT or ASN_CONSTRUCTOR and $1;
SNMP_PDU_RESPONSE = ASN_CONTEXT or ASN_CONSTRUCTOR and $2;
SNMP_PDU_SET = ASN_CONTEXT or ASN_CONSTRUCTOR or $3;
SNMP_PDU_V1TRAP = ASN_CONTEXT or ASN_CONSTRUCTOR or $4;
SNMP_PDU_GETBULK = ASN_CONTEXT or ASN_CONSTRUCTOR or $5;
SNMP_PDU_INFORM = ASN_CONTEXT or ASN_CONSTRUCTOR or $6;
SNMP_PDU_TRAP = ASN_CONTEXT or ASN_CONSTRUCTOR or $7;
{$ENDIF} // _INC_WINSNMP
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Simple Syntax Values //
// //
///////////////////////////////////////////////////////////////////////////////
const
ASN_INTEGER = ASN_UNIVERSAL or ASN_PRIMITIVE or $02;
ASN_BITS = ASN_UNIVERSAL or ASN_PRIMITIVE or $03;
ASN_OCTETSTRING = ASN_UNIVERSAL or ASN_PRIMITIVE or $04;
ASN_NULL = ASN_UNIVERSAL or ASN_PRIMITIVE or $05;
ASN_OBJECTIDENTIFIER = ASN_UNIVERSAL or ASN_PRIMITIVE or $06;
ASN_INTEGER32 = ASN_INTEGER;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Constructor Syntax Values //
// //
///////////////////////////////////////////////////////////////////////////////
ASN_SEQUENCE = ASN_UNIVERSAL or ASN_CONSTRUCTOR or $10;
ASN_SEQUENCEOF = ASN_SEQUENCE;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Application Syntax Values //
// //
///////////////////////////////////////////////////////////////////////////////
ASN_IPADDRESS = ASN_APPLICATION or ASN_PRIMITIVE or $00;
ASN_COUNTER32 = ASN_APPLICATION or ASN_PRIMITIVE or $01;
ASN_GAUGE32 = ASN_APPLICATION or ASN_PRIMITIVE or $02;
ASN_TIMETICKS = ASN_APPLICATION or ASN_PRIMITIVE or $03;
ASN_OPAQUE = ASN_APPLICATION or ASN_PRIMITIVE or $04;
ASN_COUNTER64 = ASN_APPLICATION or ASN_PRIMITIVE or $06;
ASN_UNSIGNED32 = ASN_APPLICATION or ASN_PRIMITIVE or $07;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Exception Conditions //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_EXCEPTION_NOSUCHOBJECT = ASN_CONTEXT or ASN_PRIMITIVE or $00;
SNMP_EXCEPTION_NOSUCHINSTANCE = ASN_CONTEXT or ASN_PRIMITIVE or $01;
SNMP_EXCEPTION_ENDOFMIBVIEW = ASN_CONTEXT or ASN_PRIMITIVE or $02;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Request Types (used in SnmpExtensionQueryEx) //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_EXTENSION_GET = SNMP_PDU_GET;
SNMP_EXTENSION_GET_NEXT = SNMP_PDU_GETNEXT;
SNMP_EXTENSION_GET_BULK = SNMP_PDU_GETBULK;
SNMP_EXTENSION_SET_TEST = ASN_PRIVATE or ASN_CONSTRUCTOR or $0;
SNMP_EXTENSION_SET_COMMIT = SNMP_PDU_SET;
SNMP_EXTENSION_SET_UNDO = ASN_PRIVATE or ASN_CONSTRUCTOR or $1;
SNMP_EXTENSION_SET_CLEANUP = ASN_PRIVATE or ASN_CONSTRUCTOR or $2;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Error Codes //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_ERRORSTATUS_NOERROR = 0;
SNMP_ERRORSTATUS_TOOBIG = 1;
SNMP_ERRORSTATUS_NOSUCHNAME = 2;
SNMP_ERRORSTATUS_BADVALUE = 3;
SNMP_ERRORSTATUS_READONLY = 4;
SNMP_ERRORSTATUS_GENERR = 5;
SNMP_ERRORSTATUS_NOACCESS = 6;
SNMP_ERRORSTATUS_WRONGTYPE = 7;
SNMP_ERRORSTATUS_WRONGLENGTH = 8;
SNMP_ERRORSTATUS_WRONGENCODING = 9;
SNMP_ERRORSTATUS_WRONGVALUE = 10;
SNMP_ERRORSTATUS_NOCREATION = 11;
SNMP_ERRORSTATUS_INCONSISTENTVALUE = 12;
SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE = 13;
SNMP_ERRORSTATUS_COMMITFAILED = 14;
SNMP_ERRORSTATUS_UNDOFAILED = 15;
SNMP_ERRORSTATUS_AUTHORIZATIONERROR = 16;
SNMP_ERRORSTATUS_NOTWRITABLE = 17;
SNMP_ERRORSTATUS_INCONSISTENTNAME = 18;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMPv1 Trap Types //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_GENERICTRAP_COLDSTART = 0;
SNMP_GENERICTRAP_WARMSTART = 1;
SNMP_GENERICTRAP_LINKDOWN = 2;
SNMP_GENERICTRAP_LINKUP = 3;
SNMP_GENERICTRAP_AUTHFAILURE = 4;
SNMP_GENERICTRAP_EGPNEIGHLOSS = 5;
SNMP_GENERICTRAP_ENTERSPECIFIC = 6;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Access Types //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_ACCESS_NONE = 0;
SNMP_ACCESS_NOTIFY = 1;
SNMP_ACCESS_READ_ONLY = 2;
SNMP_ACCESS_READ_WRITE = 3;
SNMP_ACCESS_READ_CREATE = 4;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP API Return Code Definitions //
// //
///////////////////////////////////////////////////////////////////////////////
type
SNMPAPI = integer;
// SNMP_FUNC_TYPE = WINAPI;
const
SNMPAPI_NOERROR = TRUE;
SNMPAPI_ERROR = FALSE;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Extension API Prototypes //
// //
///////////////////////////////////////////////////////////////////////////////
function SnmpExtensionInit(dwTimeZeroReference: DWORD; hPollForTrapEvent: HWND;
pFirstSupportedRegion: TAsnObjectIdentifier): Boolean; stdcall; external
Inetmib1 name 'SnmpExtensionInit';
function SnmpExtensionInitEx(pNextSupportedRegion: PAsnObjectIdentifier):
boolean; stdcall; external Inetmib1 name 'SnmpExtensionInitEx';
function SnmpExtensionQuery(bPduType: BYTE; pVarBindList: TSnmpVarBindList;
pErrorStatus: TAsnInteger32; pErrorIndex: TAsnInteger32): boolean; stdcall;
external Inetmib1 name 'SnmpExtensionQuery';
{
//// Under Function Can't Import becouse the DLL File Unknwon
function SnmpExtensionQueryEx(nRequestType: UINT; nTransactionId: UINT;
pVarBindList: TSnmpVarBindList; pContextInfo: TAsnOctetString; pErrorStatus:
TAsnInteger32; pErrorIndex: TAsnInteger32): boolean; stdcall; external Inetmib1
name 'SnmpExtensionQueryEx';
}
function SnmpExtensionTrap(pEnterpriseOid: TAsnObjectIdentifier; pGenericTrapId:
TAsnInteger32; pSpecificTrapId: TAsnInteger32; pTimeStamp: TAsnTimeticks;
pVarBindList: TSnmpVarBindList): boolean; stdcall; external Inetmib1 name
'SnmpExtensionTrap';
procedure SnmpExtensionClose; stdcall; external Igmpagnt name 'SnmpExtensionClose';
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Extension API Type Definitions //
// //
///////////////////////////////////////////////////////////////////////////////
type
PFNSNMPEXTENSIONINIT = function(dwUpTimeReference: DWORD; phSubagentTrapEvent:
THANDLE; pFirstSupportedRegion: TAsnObjectIdentifier): boolean; stdcall;
PFNSNMPEXTENSIONINITEX = function(pNextSupportedRegion: TAsnObjectIdentifier):
boolean; stdcall;
PFNSNMPEXTENSIONQUERY = function(bPduType: BYTE; pVarBindList: TSnmpVarBindList;
pErrorStatus: TAsnInteger32; pErrorIndex: TAsnInteger32): boolean; stdcall;
PFNSNMPEXTENSIONQUERYEX = function(nRequestType: UINT; nTransactionId: UINT;
pVarBindList: TSnmpVarBindList; pContextInfo: TAsnOctetString; pErrorStatus:
TAsnInteger32; pErrorIndex: TAsnInteger32): boolean; stdcall;
PFNSNMPEXTENSIONTRAP = function(pEnterpriseOid: TAsnObjectIdentifier;
pGenericTrapId: TAsnInteger32; pSpecificTrapId: TAsnInteger32; pTimeStamp:
TAsnTimeticks; pVarBindList: TSnmpVarBindList): boolean; stdcall;
PFNSNMPEXTENSIONCLOSE = procedure; stdcall;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP API Prototypes //
// //
///////////////////////////////////////////////////////////////////////////////
function SnmpUtilOidCpy(pOidDst: TAsnObjectIdentifier; pOidSrc: TAsnObjectIdentifier):
SNMPAPI; stdcall external snmpapidll name 'SnmpUtilOidCpy';
function SnmpUtilOidAppend(pOidDst: TAsnObjectIdentifier; pOidSrc:
TAsnObjectIdentifier): SNMPAPI; stdcall; external snmpapidll name
'SnmpUtilOidAppend';
function SnmpUtilOidNCmp(pOid1: TAsnObjectIdentifier; pOid2: TAsnObjectIdentifier;
nSubIds: UINT): SNMPAPI; stdcall; external snmpapidll name 'SnmpUtilOidNCmp';
function SnmpUtilOidCmp(pOid1: TAsnObjectIdentifier; pOid2: TAsnObjectIdentifier):
SNMPAPI; stdcall; external snmpapidll name 'SnmpUtilOidCmp';
procedure SnmpUtilOidFree(pOid: TAsnObjectIdentifier); stdcall; external snmpapidll
name 'SnmpUtilOidFree';
function SnmpUtilOctetsCmp(pOctets1: TAsnOctetString; pOctets2: TAsnOctetString):
SNMPAPI; stdcall; external snmpapidll name 'SnmpUtilOctetsCmp';
function SnmpUtilOctetsNCmp(pOctets1: TAsnOctetString; pOctets2: TAsnOctetString;
nChars: UINT): SNMPAPI; stdcall; external snmpapidll name 'SnmpUtilOctetsNCmp';
function SnmpUtilOctetsCpy(pOctetsDst: TAsnOctetString; pOctetsSrc: TAsnOctetString):
SNMPAPI; stdcall; external snmpapidll name 'SnmpUtilOctetsCpy';
procedure SnmpUtilOctetsFree(pOctets: TAsnOctetString); stdcall; external snmpapidll
name 'SnmpUtilOctetsFree';
function SnmpUtilAsnAnyCpy(pAnyDst: TAsnAny; pAnySrc: TAsnAny): SNMPAPI; stdcall;
external snmpapidll name 'SnmpUtilAsnAnyCpy';
procedure SnmpUtilAsnAnyFree(pAny: TAsnAny); stdcall; external snmpapidll name
'SnmpUtilAsnAnyFree';
function SnmpUtilVarBindCpy(pVbDst: TSnmpVarBind; pVbSrc: TSnmpVarBind): SNMPAPI;
stdcall; external snmpapidll name 'SnmpUtilVarBindCpy';
procedure SnmpUtilVarBindFree(pVb: TSnmpVarBind); stdcall; external snmpapidll name
'SnmpUtilVarBindFree';
function SnmpUtilVarBindListCpy(pVblDst: TSnmpVarBindList; pVblSrc: TSnmpVarBindList):
SNMPAPI; stdcall; external snmpapidll name 'SnmpUtilVarBindListCpy';
procedure SnmpUtilVarBindListFree(pVbl: TSnmpVarBindList); stdcall; external snmpapidll
name 'SnmpUtilVarBindListFree';
procedure SnmpUtilMemFree(pMem: pointer); stdcall; external snmpapidll name
'SnmpUtilMemFree';
function SnmpUtilMemAlloc(nBytes: UINT): pointer; stdcall; external snmpapidll name
'SnmpUtilMemAlloc';
function SnmpUtilMemReAlloc(pMem: pointer; nBytes: UINT): pointer; stdcall; external
snmpapidll name 'SnmpUtilMemReAlloc';
function SnmpUtilOidToA(Oid: TAsnObjectIdentifier): pchar; stdcall; external snmpapidll
name 'SnmpUtilOidToA';
function SnmpUtilIdsToA(Ids: UINT; IdLength: UINT): pchar; stdcall; external snmpapidll
name 'SnmpUtilIdsToA';
procedure SnmpUtilPrintOid(Oid: TAsnObjectIdentifier); stdcall; external snmpapidll
name 'SnmpUtilPrintOid';
procedure SnmpUtilPrintAsnAny(pAny: TAsnAny); stdcall; external snmpapidll name
'SnmpUtilPrintAsnAny';
function SnmpSvcGetUptime: DWORD; stdcall; external snmpapidll name
'SnmpSvcGetUptime';
procedure SnmpSvcSetLogLevel(nLogLevel: integer); stdcall; external snmpapidll name
'SnmpSvcSetLogLevel';
procedure SnmpSvcSetLogType(nLogType: integer); stdcall; external snmpapidll name
'SnmpSvcSetLogType';
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Debugging Definitions //
// //
///////////////////////////////////////////////////////////////////////////////
const
SNMP_LOG_SILENT = $0;
SNMP_LOG_FATAL = $1;
SNMP_LOG_ERROR = $2;
SNMP_LOG_WARNING = $3;
SNMP_LOG_TRACE = $4;
SNMP_LOG_VERBOSE = $5;
SNMP_OUTPUT_TO_CONSOLE = $1;
SNMP_OUTPUT_TO_LOGFILE = $2;
SNMP_OUTPUT_TO_EVENTLOG = $4; // no longer supported
SNMP_OUTPUT_TO_DEBUGGER = $8;
///////////////////////////////////////////////////////////////////////////////
// //
// SNMP Debugging Prototypes //
// //
///////////////////////////////////////////////////////////////////////////////
procedure SnmpUtilDbgPrint(nLogLevel: integer; // see log levels above...
szFormat: pchar); stdcall; external snmpapidll name 'SnmpUtilDbgPrint';
{$IFDEF DBG}
{$DEFINE SNMPDBG(_x_)SnmpUtilDbgPrint _x_}
{$ELSE}
{$DEFINE SNMPDBG(_x_)}
{$ENDIF}
///////////////////////////////////////////////////////////////////////////////
// //
// Miscellaneous definitions //
// //
///////////////////////////////////////////////////////////////////////////////
const
// DEFINE_SIZEOF=(array)(sizeof(array) / sizeof((array)[0]))
// DEFINE_OID(SubIdArray) {DEFINE_SIZEOF(SubIdArray),(SubIdArray)}
// DEFINE_NULLOID() {0,NULL}
// DEFINE_NULLOCTETS() {NULL,0,FALSE}
DEFAULT_SNMP_PORT_UDP = 161;
DEFAULT_SNMP_PORT_IPX = 36879;
DEFAULT_SNMPTRAP_PORT_UDP = 162;
DEFAULT_SNMPTRAP_PORT_IPX = 36880;
SNMP_MAX_OID_LEN = 128;
///////////////////////////////////////////////////////////////////////////////
// //
// API Error Code Definitions //
// //
///////////////////////////////////////////////////////////////////////////////
SNMP_MEM_ALLOC_ERROR = 1;
SNMP_BERAPI_INVALID_LENGTH = 10;
SNMP_BERAPI_INVALID_TAG = 11;
SNMP_BERAPI_OVERFLOW = 12;
SNMP_BERAPI_SHORT_BUFFER = 13;
SNMP_BERAPI_INVALID_OBJELEM = 14;
SNMP_PDUAPI_UNRECOGNIZED_PDU = 20;
SNMP_PDUAPI_INVALID_ES = 21;
SNMP_PDUAPI_INVALID_GT = 22;
SNMP_AUTHAPI_INVALID_VERSION = 30;
SNMP_AUTHAPI_INVALID_MSG_TYPE = 31;
SNMP_AUTHAPI_TRIV_AUTH_FAILED = 32;
///////////////////////////////////////////////////////////////////////////////
// //
// Support for old definitions (support disabled via SNMPSTRICT) //
// //
///////////////////////////////////////////////////////////////////////////////
{$IFNDEF SNMPSTRICT}
const
ASN_RFC1155_IPADDRESS = ASN_IPADDRESS;
ASN_RFC1155_COUNTER = ASN_COUNTER32;
ASN_RFC1155_GAUGE = ASN_GAUGE32;
ASN_RFC1155_TIMETICKS = ASN_TIMETICKS;
ASN_RFC1155_OPAQUE = ASN_OPAQUE;
ASN_RFC1213_DISPSTRING = ASN_OCTETSTRING;
ASN_RFC1157_GETREQUEST = SNMP_PDU_GET;
ASN_RFC1157_GETNEXTREQUEST = SNMP_PDU_GETNEXT;
ASN_RFC1157_GETRESPONSE = SNMP_PDU_RESPONSE;
ASN_RFC1157_SETREQUEST = SNMP_PDU_SET;
ASN_RFC1157_TRAP = SNMP_PDU_V1TRAP;
ASN_CONTEXTSPECIFIC = ASN_CONTEXT;
ASN_PRIMATIVE = ASN_PRIMITIVE;
type
RFC1157VarBindList = TSnmpVarBindList;
RFC1157VarBind = TSnmpVarBind;
AsnInteger = TAsnInteger32;
AsnCounter = TAsnCounter32;
AsnGauge = TAsnGauge32;
{$ENDIF} // SNMPSTRICT
implementation
end.
 

Similar threads

I
回复
0
查看
578
import
I
I
回复
0
查看
616
import
I
I
回复
0
查看
620
import
I
后退
顶部