{******************************************************************}
{ }
{ Borland Delphi Runtime Library }
{ SNMP functions interface unit }
{ }
{ Portions created by Microsoft are }
{ Copyright (C) 1992-1999 Microsoft Corporation. }
{ All Rights Reserved. }
{ }
{ The original file is: snmp.h }
{ The original Pascal code is: Snmp.pas, released 05 Oct 2001. }
{ The initial developer of the Pascal code is Petr Vones }
{ (petr.v@mujmail.cz). }
{ }
{ Portions created by Petr Vones are }
{ Copyright (C) 2001 Petr Vones }
{ }
{ Obtained through: }
{ }
{ Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project }
{ JEDI home page, located at http://delphi-jedi.org }
{ }
{ The contents of this file are used with permission, subject to }
{ the Mozilla Public License Version 1.1 (the "License"); you may }
{ not use this file except in compliance with the License. You may }
{ obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
{ implied. See the License for the specific language governing }
{ rights and limitations under the License. }
{ }
{******************************************************************}
SNMP_PDU_GET = (ASN_CONTEXT or ASN_CONSTRUCTOR or $0);
{$EXTERNALSYM SNMP_PDU_GET}
SNMP_PDU_GETNEXT = (ASN_CONTEXT or ASN_CONSTRUCTOR or $1);
{$EXTERNALSYM SNMP_PDU_GETNEXT}
SNMP_PDU_RESPONSE = (ASN_CONTEXT or ASN_CONSTRUCTOR or $2);
{$EXTERNALSYM SNMP_PDU_RESPONSE}
SNMP_PDU_SET = (ASN_CONTEXT or ASN_CONSTRUCTOR or $3);
{$EXTERNALSYM SNMP_PDU_SET}
SNMP_PDU_V1TRAP = (ASN_CONTEXT or ASN_CONSTRUCTOR or $4);
{$EXTERNALSYM SNMP_PDU_V1TRAP}
SNMP_PDU_GETBULK = (ASN_CONTEXT or ASN_CONSTRUCTOR or $5);
{$EXTERNALSYM SNMP_PDU_GETBULK}
SNMP_PDU_INFORM = (ASN_CONTEXT or ASN_CONSTRUCTOR or $6);
{$EXTERNALSYM SNMP_PDU_INFORM}
SNMP_PDU_TRAP = (ASN_CONTEXT or ASN_CONSTRUCTOR or $7);
{$EXTERNALSYM SNMP_PDU_TRAP}
{$ENDIF _INC_WINSNMP}
{ SNMP Simple Syntax Values }
ASN_INTEGER = (ASN_UNIVERSAL or ASN_PRIMITIVE or $02);
{$EXTERNALSYM ASN_INTEGER}
ASN_BITS = (ASN_UNIVERSAL or ASN_PRIMITIVE or $03);
{$EXTERNALSYM ASN_BITS}
ASN_OCTETSTRING = (ASN_UNIVERSAL or ASN_PRIMITIVE or $04);
{$EXTERNALSYM ASN_OCTETSTRING}
ASN_NULL = (ASN_UNIVERSAL or ASN_PRIMITIVE or $05);
{$EXTERNALSYM ASN_NULL}
ASN_OBJECTIDENTIFIER = (ASN_UNIVERSAL or ASN_PRIMITIVE or $06);
{$EXTERNALSYM ASN_OBJECTIDENTIFIER}
ASN_INTEGER32 = ASN_INTEGER;
{$EXTERNALSYM ASN_INTEGER32}
{ SNMP Constructor Syntax Values }
ASN_SEQUENCE = (ASN_UNIVERSAL or ASN_CONSTRUCTOR or $10);
{$EXTERNALSYM ASN_SEQUENCE}
ASN_SEQUENCEOF = ASN_SEQUENCE;
{$EXTERNALSYM ASN_SEQUENCEOF}
{ SNMP Application Syntax Values }
ASN_IPADDRESS = (ASN_APPLICATION or ASN_PRIMITIVE or $00);
{$EXTERNALSYM ASN_IPADDRESS}
ASN_COUNTER32 = (ASN_APPLICATION or ASN_PRIMITIVE or $01);
{$EXTERNALSYM ASN_COUNTER32}
ASN_GAUGE32 = (ASN_APPLICATION or ASN_PRIMITIVE or $02);
{$EXTERNALSYM ASN_GAUGE32}
ASN_TIMETICKS = (ASN_APPLICATION or ASN_PRIMITIVE or $03);
{$EXTERNALSYM ASN_TIMETICKS}
ASN_OPAQUE = (ASN_APPLICATION or ASN_PRIMITIVE or $04);
{$EXTERNALSYM ASN_OPAQUE}
ASN_COUNTER64 = (ASN_APPLICATION or ASN_PRIMITIVE or $06);
{$EXTERNALSYM ASN_COUNTER64}
ASN_UNSIGNED32 = (ASN_APPLICATION or ASN_PRIMITIVE or $07);
{$EXTERNALSYM ASN_UNSIGNED32}
{ SNMP Exception Conditions }
SNMP_EXCEPTION_NOSUCHOBJECT = (ASN_CONTEXT or ASN_PRIMITIVE or $00);
{$EXTERNALSYM SNMP_EXCEPTION_NOSUCHOBJECT}
SNMP_EXCEPTION_NOSUCHINSTANCE = (ASN_CONTEXT or ASN_PRIMITIVE or $01);
{$EXTERNALSYM SNMP_EXCEPTION_NOSUCHINSTANCE}
SNMP_EXCEPTION_ENDOFMIBVIEW = (ASN_CONTEXT or ASN_PRIMITIVE or $02);
{$EXTERNALSYM SNMP_EXCEPTION_ENDOFMIBVIEW}
{ SNMP Request Types (used in SnmpExtensionQueryEx) }
SNMP_EXTENSION_GET = SNMP_PDU_GET;
{$EXTERNALSYM SNMP_EXTENSION_GET}
SNMP_EXTENSION_GET_NEXT = SNMP_PDU_GETNEXT;
{$EXTERNALSYM SNMP_EXTENSION_GET_NEXT}
SNMP_EXTENSION_GET_BULK = SNMP_PDU_GETBULK;
{$EXTERNALSYM SNMP_EXTENSION_GET_BULK}
SNMP_EXTENSION_SET_TEST = (ASN_PRIVATE or ASN_CONSTRUCTOR or $0);
{$EXTERNALSYM SNMP_EXTENSION_SET_TEST}
SNMP_EXTENSION_SET_COMMIT = SNMP_PDU_SET;
{$EXTERNALSYM SNMP_EXTENSION_SET_COMMIT}
SNMP_EXTENSION_SET_UNDO = (ASN_PRIVATE or ASN_CONSTRUCTOR or $1);
{$EXTERNALSYM SNMP_EXTENSION_SET_UNDO}
SNMP_EXTENSION_SET_CLEANUP = (ASN_PRIVATE or ASN_CONSTRUCTOR or $2);
{$EXTERNALSYM SNMP_EXTENSION_SET_CLEANUP}
type
TSnmpExtensionInit = function (dwUptimeReference: DWORD; var phSubagentTrapEvent: THandle;
var pFirstSupportedRegion: PAsnObjectIdentifier): Boolean; stdcall;
TSnmpExtensionInitEx = function (var pNextSupportedRegion: PAsnObjectIdentifier): Boolean; stdcall;
TSnmpExtensionMonitor = function (pAgentMgmtData: Pointer): Boolean; stdcall;
TSnmpExtensionQuery = function (bPduType: Byte; var pVarBindList: TSnmpVarBindList;
var pErrorStatus: TAsnInteger32; var pErrorIndex: TAsnInteger32): Boolean; stdcall;
TSnmpExtensionQueryEx = function (nRequestType: UINT; nTransactionId: UINT; var pVarBindList: PSnmpVarBindList;
var pContextInfo: PAsnOctetString; var pErrorStatus: TAsnInteger32; var pErrorIndex: TAsnInteger32): Boolean; stdcall;
TSnmpExtensionTrap = function (pEnterpriseOid: PAsnObjectIdentifier; var pGenericTrapId: TAsnInteger32;
var pSpecificTrapId: TAsnInteger32; var pTimeStamp: TAsnTimeticks; var pVarBindList: PSnmpVarBindList): Boolean; stdcall;
function SnmpExtensionLoaded: Boolean;
function LoadSnmpExtension(const LibName: string): Boolean;
function UnloadSnmpExtension: Boolean;
implementation
const
snmpapilib = 'snmpapi.dll';
var
LibHandle: THandle;
function SnmpExtensionLoaded: Boolean;
begin
Result := LibHandle <> 0;
end;
function LoadSnmpExtension(const LibName: string): Boolean;
begin
Result := UnloadSnmpExtension;
if Result then
begin
LibHandle := LoadLibrary(PChar(LibName));
Result := SnmpExtensionLoaded;
if Result then
begin
@SnmpExtensionInit := GetProcAddress(LibHandle, 'SnmpExtensionInit');
@SnmpExtensionInitEx := GetProcAddress(LibHandle, 'SnmpExtensionInitEx');
@SnmpExtensionMonitor := GetProcAddress(LibHandle, 'SnmpExtensionMonitor');
@SnmpExtensionQuery := GetProcAddress(LibHandle, 'SnmpExtensionQuery');
@SnmpExtensionQueryEx := GetProcAddress(LibHandle, 'SnmpExtensionQueryEx');
@SnmpExtensionTrap := GetProcAddress(LibHandle, 'SnmpExtensionTrap');
@SnmpExtensionClose := GetProcAddress(LibHandle, 'SnmpExtensionClose');
Result := Assigned(SnmpExtensionInit);
if not Result then
UnloadSnmpExtension;
end;
end;
end;
function UnloadSnmpExtension: Boolean;
begin
if SnmpExtensionLoaded then
begin
Result := FreeLibrary(LibHandle);
LibHandle := 0;
@SnmpExtensionInit := nil;
@SnmpExtensionInitEx := nil;
@SnmpExtensionMonitor := nil;
@SnmpExtensionQuery := nil;
@SnmpExtensionQueryEx := nil;
@SnmpExtensionTrap := nil;
@SnmpExtensionClose := nil;
end
else
Result := True;
end;
function SnmpUtilOidCpy; external snmpapilib name 'SnmpUtilOidCpy';
function SnmpUtilOidAppend; external snmpapilib name 'SnmpUtilOidAppend';
function SnmpUtilOidNCmp; external snmpapilib name 'SnmpUtilOidNCmp';
function SnmpUtilOidCmp; external snmpapilib name 'SnmpUtilOidCmp';
procedure SnmpUtilOidFree; external snmpapilib name 'SnmpUtilOidFree';
function SnmpUtilOctetsCmp; external snmpapilib name 'SnmpUtilOctetsCmp';
function SnmpUtilOctetsNCmp; external snmpapilib name 'SnmpUtilOctetsNCmp';
function SnmpUtilOctetsCpy; external snmpapilib name 'SnmpUtilOctetsCpy';
procedure SnmpUtilOctetsFree; external snmpapilib name 'SnmpUtilOctetsFree';
function SnmpUtilAsnAnyCpy; external snmpapilib name 'SnmpUtilAsnAnyCpy';
procedure SnmpUtilAsnAnyFree; external snmpapilib name 'SnmpUtilAsnAnyFree';
function SnmpUtilVarBindCpy; external snmpapilib name 'SnmpUtilVarBindCpy';
procedure SnmpUtilVarBindFree; external snmpapilib name 'SnmpUtilVarBindFree';
function SnmpUtilVarBindListCpy; external snmpapilib name 'SnmpUtilVarBindListCpy';
procedure SnmpUtilVarBindListFree; external snmpapilib name 'SnmpUtilVarBindListFree';
procedure SnmpUtilMemFree; external snmpapilib name 'SnmpUtilMemFree';
function SnmpUtilMemAlloc; external snmpapilib name 'SnmpUtilMemAlloc';
function SnmpUtilMemReAlloc; external snmpapilib name 'SnmpUtilMemReAlloc';
function SnmpUtilOidToA; external snmpapilib name 'SnmpUtilOidToA';
function SnmpUtilIdsToA; external snmpapilib name 'SnmpUtilIdsToA';
procedure SnmpUtilPrintOid; external snmpapilib name 'SnmpUtilPrintOid';
procedure SnmpUtilPrintAsnAny; external snmpapilib name 'SnmpUtilPrintAsnAny';
function SnmpSvcGetUptime; external snmpapilib name 'SnmpSvcGetUptime';
procedure SnmpSvcSetLogLevel; external snmpapilib name 'SnmpSvcSetLogLevel';
procedure SnmpSvcSetLogType; external snmpapilib name 'SnmpSvcSetLogType';
procedure SnmpUtilDbgPrint; external snmpapilib name 'SnmpUtilDbgPrint';
{$IFNDEF SNMPSTRICT}
function SNMP_oidcpy; external snmpapilib name 'SnmpUtilOidCpy';
function SNMP_oidappend; external snmpapilib name 'SnmpUtilOidAppend';
function SNMP_oidncmp; external snmpapilib name 'SnmpUtilOidNCmp';
function SNMP_oidcmp; external snmpapilib name 'SnmpUtilOidCmp';
procedure SNMP_oidfree; external snmpapilib name 'SnmpUtilOidFree';
function SNMP_CopyVarBind; external snmpapilib name 'SnmpUtilVarBindCpy';
procedure SNMP_FreeVarBind; external snmpapilib name 'SnmpUtilVarBindFree';
function SNMP_CopyVarBindList; external snmpapilib name 'SnmpUtilVarBindListCpy';
procedure SNMP_FreeVarBindList; external snmpapilib name 'SnmpUtilVarBindListFree';
procedure SNMP_printany; external snmpapilib name 'SnmpUtilPrintAsnAny';
procedure SNMP_free; external snmpapilib name 'SnmpUtilMemFree';
function SNMP_malloc; external snmpapilib name 'SnmpUtilMemAlloc';
function SNMP_realloc; external snmpapilib name 'SnmpUtilMemReAlloc';
procedure SNMP_DBG_free; external snmpapilib name 'SnmpUtilMemFree';
function SNMP_DBG_malloc; external snmpapilib name 'SnmpUtilMemAlloc';
function SNMP_DBG_realloc; external snmpapilib name 'SnmpUtilMemReAlloc';
{$ENDIF SNMPSTRICT}
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;
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_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;
///////////////////////////////////////////////////////////////////////////////
// //
// Support for old definitions (support disabled via SNMPSTRICT) //
// //
///////////////////////////////////////////////////////////////////////////////