UdpTransport.docx

上传人:b****6 文档编号:5023347 上传时间:2022-12-12 格式:DOCX 页数:20 大小:18.98KB
下载 相关 举报
UdpTransport.docx_第1页
第1页 / 共20页
UdpTransport.docx_第2页
第2页 / 共20页
UdpTransport.docx_第3页
第3页 / 共20页
UdpTransport.docx_第4页
第4页 / 共20页
UdpTransport.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

UdpTransport.docx

《UdpTransport.docx》由会员分享,可在线阅读,更多相关《UdpTransport.docx(20页珍藏版)》请在冰豆网上搜索。

UdpTransport.docx

UdpTransport

UdpTransport

usingSystem;

usingSystem.Net;

usingSystem.Net.Sockets;

namespaceSnmpSharpNet

{

//摘要:

//IP/UDPtransportclass.

publicclassUdpTransport:

IDisposable

{

//摘要:

//FlagshowingifclassisusingIPv6orIPv4

protectedbool_isIPv6;

//

//摘要:

//InternalvariableusedtodisablehostIPaddress/portnumbercheckonreceived

//SNMPreplypackets.Ifthisoptionisdisabled(default)onlyrepliesfrom

//theIPaddress/portnumbercombinationtowhichtherequestwassentwill

//beacceptedasvalidpackets.ThisvalueissetintheAgentParametersclass

//andisonlyvalidforSNMPv1andv2crequests.

protectedbool_noSourceCheck;

//

//摘要:

//Socket

protectedSocket_socket;

//摘要:

//Constructor.InitializesandbindstheSocketclass

//

//参数:

//useV6:

//SettotrueifyouwishtoinitializethetransportforIPv6

publicUdpTransport(booluseV6);

//摘要:

//Isclassbusy.Thispropertyistruewhenclassisservicinganotherrequest,

//falseifreadytoprocessanewrequest.

publicboolIsBusy{get;}

//

//摘要:

//FlagusedtodetermineifclassisusingIPversion6(true)orIPversion

//4(false)

publicboolIsIPv6{get;}

//摘要:

//Closenetworksocket

publicvoidClose();

//

//摘要:

//Disposeoftheclass.

publicvoidDispose();

//

//摘要:

//Initializeclasssocket

//

//参数:

//useV6:

//ShouldsocketbeinitializedforIPv6(true)ofIPv4(false)

protectedvoidinitSocket(booluseV6);

//

//摘要:

//MakesyncrequestusingIP/UDPwithrequesttimeoutsandretries.

//

//参数:

//peer:

//SNMPagentIPaddress

//

//port:

//SNMPagentportnumber

//

//buffer:

//Datatosendtotheagent

//

//bufferLength:

//Datalengthinthebuffer

//

//timeout:

//Timeoutinmilliseconds

//

//retries:

//Maximumnumberofretries.0=makeasinglerequestwithnoretryattempts

//

//返回结果:

//Bytearrayreturnedbytheagent.Nullonerror

//

//异常:

//SnmpSharpNet.SnmpException:

//Thrownonrequesttimedout.SnmpException.ErrorCodeissettoSnmpException.RequestTimedOut

//constant.

//

//SnmpSharpNet.SnmpException:

//ThrownwhenIPv4addressispassedtothev6socketorviceversa

publicbyte[]Request(IPAddresspeer,intport,byte[]buffer,intbufferLength,inttimeout,intretries);

}

}

SnmpVersion

usingSystem;

namespaceSnmpSharpNet

{

//摘要:

//SNMPVersionnumberenumeration

publicenumSnmpVersion

{

//摘要:

//SNMPversion1

Ver1=0,

//

//摘要:

//SNMPversion2c

Ver2=1,

//

//摘要:

//SNMPversion3

Ver3=3,

}

}

Pdu

usingSystem;

usingSystem.Collections;

usingSystem.Collections.Generic;

usingSystem.Reflection;

namespaceSnmpSharpNet

{

//摘要:

//SNMPProtocolDataUnit

//

//备注:

//SNMPPDUclassthatisthebasesforallSNMPrequestsandreplies.Itis

//capableofprocessingSNMPv1GET,GET-NEXT,REPLYandSNMPv2GET,GET-NEXT,

//GET-BULK,REPLY,V2TRAP,INFORMandREPORTPDUs.Pdupdu=newPdu();pdu.Type

//=PduType.Get;pdu.VbList.AddVb("1.3.6.1.2.1.1.1.0");pdu.VbList.AddVb("1.3.6.1.2.1.1.2.0");

//Bydefault,PduclassinitializestheRequestId(uniqueidentifierofeach

//SNMPrequestmadebythemanager)witharandomvalue.Usercanforceanew,

//randomrequestidgenerationatthetimepacketisencodingbychangingRequestId

//to0.IfyouwishtosetaspecificRequestId,youcandoitthisway:

Pdu

//pdu=newPdu();pdu.Type=PduType.GetNext;pdu.RequestId=11;//Seta

//customrequestidpdu.VbList.AddVb("1.3.6.1.2.1.1");Pdutypeswithspecial

//optionsarenotificationPDUs,V2TRAPandINFORM,andGet-Bulkrequests.

//Get-Bulkrequestisavailableinversion2cand3oftheSNMP.Twospecial

//optionscanbesetfortheserequests,NonRepeatersandMaxRepetitions.NonRepeaters

//isavaluetellingtheagenthowmanyOIDsintheVbListaretobetreated

//asasingleGetNextrequest.MaxRepeaterstellstheagenthowmanyvariable

//bindingstoreturninasinglePduforeachrequestedOid.

publicclassPdu:

AsnType,ICloneable,IEnumerable,IEnumerable

{

//摘要:

//Errorindexvalue.

//

//备注:

//PointstotheVbsequencethatcausedtheerror.IfnotVbthecauseofthe

//error,orifthereisnoerror,thisvalueis0.

protectedInteger32_errorIndex;

//

//摘要:

//Errorstatusvalue.

//

//备注:

//SeeSnmpSharpNet.SnmpConstantsclassfordefinitionoferrorvalues.Ifno

//errorisencountered,thisvalueissetto0.

protectedInteger32_errorStatus;

//

//摘要:

//Requestidvalue.

//

//备注:

//Integer32valuethatuniquelyrepresentsthisrequest.Usedtomatchrequests

//andreplies.

protectedInteger32_requestId;

//

//摘要:

//SNMPv2trapsecondVbisthetrapobjectID.

//

//备注:

//ThisvariableshouldbesettothetrapOIDandwillbeinsertedintothe

//encodedpacket.

protectedOid_trapObjectID;

//

//摘要:

//SNMPv2trapfirstVbisthetraptimestamp.TocreateanSNMPv2TRAPpacket,

//setthetimestampvalueinthisvariable

protectedTimeTicks_trapTimeStamp;

//

//摘要:

//Variablebindingcollection

protectedVbCollection_vbs;

//摘要:

//Constructor.

//

//备注:

//InitializesallvaluestoNULLandPDUtypetoGET

publicPdu();

//

//摘要:

//Constructor

//

//参数:

//pdu:

//Pduclasstouseassourceofinformationtoinitilizethisclass.

//

//备注:

//Initializeclassfromthepassedpduclass.

publicPdu(Pdupdu);

//

//摘要:

//Constructor.

//

//参数:

//pduType:

//Pdutype.ForavailablevaluesseeSnmpSharpNet.PduType

//

//备注:

//CreatePduofspecifictype.

publicPdu(PduTypepduType);

//

//摘要:

//Constructor.

//

//参数:

//vbs:

//VarBindlisttoinitializetheinternalVbListto.

//

//备注:

//SetstheVarBindlisttotheClonecopyofthesuppliedlist.

publicPdu(VbCollectionvbs);

//

//摘要:

//Constructor.

//

//参数:

//vbs:

//VarBindlist

//

//type:

//PDUtype

//

//requestId:

//Requestid

//

//备注:

//InitializesPDUclasswithsuppliedvalues.

publicPdu(VbCollectionvbs,PduTypetype,intrequestId);

//摘要:

//ErrorIndexPduvalue

//

//异常:

//SnmpSharpNet.SnmpInvalidPduTypeException:

//ThrownwhenpropertyisaccessforGetBulkPdu

//

//备注:

//ErrorindexpointstotheVbListentrythatErrorStatuserrorcoderefers

//to.ValidforallPdutypesexceptGetBulkrequests.

publicintErrorIndex{get;set;}

//

//摘要:

//ErrorStatusPduvalue

//

//异常:

//SnmpSharpNet.SnmpInvalidPduTypeException:

//ThrownwhenpropertyisaccessforGetBulkPdu

//

//备注:

//StoreserrorstatusreturnedbytheSNMPagent.Value0representsnoerror.

//ValidforallPdutypesexceptGetBulkrequests.

publicintErrorStatus{get;set;}

//

//摘要:

//TellsSNMPAgenthowmanyVBstoincludeinasinglerequest.Onlyvalid

//onGETBULKrequests.

//

//异常:

//SnmpSharpNet.SnmpInvalidPduTypeException:

//ThrownwhenPDUtypeisnotGET-BULK

publicintMaxRepetitions{get;set;}

//

//摘要:

//Get/SetGET-BULKNonRepeatersvalue

//

//异常:

//SnmpSharpNet.SnmpInvalidPduTypeException:

//ThrownwhenPDUtypeisnotGET-BULK

//

//备注:

//NonrepeatersvariabletellstheSNMPAgenthowmanyGETNEXTlikevariables

//toretrieve(singleVbreturnedperrequest)beforeMaxRepetitionsvalue

//takesaffect.Ifyouwishtoretrieveasmanyvaluesasyoucaninasingle

//request,setthisvalueto0.

publicintNonRepeaters{get;set;}

//

//摘要:

//SNMPpacketrequestidthatissenttotheSNMPagent.SETthisvaluebefore

//makingSNMPrequests.

publicintRequestId{get;set;}

//

//摘要:

//GetTRAPObjectIDclassfromSNMPv2TRAPandINFORMPDUs

//

//异常:

//SnmpSharpNet.SnmpInvalidPduTypeException:

//ThrownwhenpropertyisaccessforaPduofatypeotherthenV2TRAP,INFORM

//orRESPONSE

publicOidTrapObjectID{get;set;}

//

//摘要:

//GetTRAPTimeStampclassfromSNMPv2TRAPandINFORMPDUs

publicTimeTicksTrapSysUpTime{get;}

//

//摘要:

//GetorSETthePDUtype.AvailabletypesareGET,GETNEXT,SET,GETBULK.

//PDUtypesaredefinedinPduclass.

publicPduTypeType{get;set;}

//

//摘要:

//ReturnthenumberofVBentriesintheVarBindlist

publicintVbCount{get;}

//

//摘要:

//VarBindlist

publicVbCollectionVbList{get;}

//摘要:

//IndexedaccesstoVarBindcollectionofthePdu.

//

//参数:

//index:

//IndexpositionoftheVarBindentry

//

//返回结果:

//VarBindentryatthespecifiedindex

//

//异常:

//System.IndexOutOfRangeException:

//Thrownwhenindexisoutsidetheboundsofthecollection

publicVbthis[intindex]{get;}

//

//摘要:

//AccessvariablebindingsusingVbOidvalue

//

//参数:

//oid:

//RequiredOidvalue

//

//返回结果:

//VariablebindingwiththeOidmatchingtheparameter,otherwisenull

publicVbthis[Oidoid]{get;}

//

//摘要:

//AccessvariablebindingsusingVbOidvalueinthestringformat

//

//参数:

//oid:

//Oidvalueinstringrepresentation

//

//返回结果:

//VariablebindingwiththeOidmatchingtheparameter,otherwisenull

publicVbthis[stringoid]{get;}

//摘要:

//Clonethisobject

//

//返回结果:

//CopyofthisobjectcastastypeSystem.Object

publicoverrideobjectClone();

//

//摘要:

//DecodeBERencodedPdu

//

//参数:

//buffer:

//BERencodedbuffer

//

//offset:

//Theoffsetbytetobegindecoding

//

//返回结果:

//Bufferpositionafterthedecodedvalue

//

//异常:

//System.OverflowException:

//Thrownwhenheaderpointstomor

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1