UdpTransport.docx
《UdpTransport.docx》由会员分享,可在线阅读,更多相关《UdpTransport.docx(20页珍藏版)》请在冰豆网上搜索。
![UdpTransport.docx](https://file1.bdocx.com/fileroot1/2022-12/12/6d0ccf92-6c41-4e5b-a0e3-e5dd059855d8/6d0ccf92-6c41-4e5b-a0e3-e5dd059855d81.gif)
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