コード例 #1
0
        /// <summary>
        /// Constructor. Initializes and binds the Socket class
        /// </summary>
        public UdpTransport(SnmpMessenger messengerSession)
        {
            this._session = messengerSession;
            _socket       = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 0);
            EndPoint   ep         = (EndPoint)ipEndPoint;

            _socket.Bind(ep);
        }
コード例 #2
0
        /// <summary>
        /// Removes the Hdlc Transparency from a List of Byte
        /// </summary>
        /// <param name="Bytes">The List of Byte to remove the Hdlc Transparency from</param>
        /// <param name="IncludeHdlcFields">Specifies the Hdlc Fields retrieved should be included in the the returned Bytes</param>
        /// <returns>A List of Bytes which have been decoded from a Transparent state</returns>
        public static List <byte> PmppDecode(this List <byte> Bytes, bool IncludeHdlcFields, Transport.SnmpMessenger messengerSession)
        {
            if (Bytes.Count == 0)
            {
                return(Bytes);
            }
            if (Bytes.First() != 0x7e && Bytes.Last() != 0x7e)
            {
                int firstByte = Bytes.IndexOf(PMPP);
                int lastByte  = Bytes.LastIndexOf(PMPP);
                if (firstByte == lastByte)
                {
                    //offsets are the same....
                    return(Bytes);
                }
                Bytes = Bytes.GetRange(firstByte, lastByte);
            }

            //Removes PMPP Frameing Chars
            Bytes.RemoveAt(0);
            Bytes.RemoveAt(Bytes.Count - 1);

            //Remove Transparency
            Int32 Position = 0;

            List <byte> Decoded = new List <byte>();

            if (!Bytes.Any(b => b == PMPP || b == PMPP_ESCAPE))
            {
                Decoded.AddRange(Bytes);
            }
            else
            {
                for (int end = Bytes.Count; Position < end; ++Position)
                {
                    if (Bytes[Position] == PMPP_ESCAPE)
                    {
                        if (Bytes[Position + 1] == 0x5e)
                        {
                            Decoded.Add(PMPP);
                            ++Position;
                        }
                        else if (Bytes[Position + 1] == 0x5d)
                        {
                            Decoded.Add(PMPP_ESCAPE);
                            ++Position;
                        }
                    }
                    else
                    {
                        Decoded.Add(Bytes[Position]);
                    }
                }
            }



            //Get Checksum
            List <byte> Checksum = Decoded.GetRange(Decoded.Count - 2, 2);

            //Remove Checksum from the working range
            Decoded.RemoveRange(Decoded.Count - 2, 2);

            //Calculate a Crc16 on the InformationPayload
            Crc16 alg = new Crc16();

            alg.ComputeHash(Decoded.ToArray());

            int?packetChecksum = System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToUInt16(Checksum.ToArray(), 0));
            int?pseudoChecksum = System.Net.IPAddress.HostToNetworkOrder((int)alg.CrcValue);

            alg      = null;
            Checksum = null;

            //Compare Checksums
            if (packetChecksum != pseudoChecksum)
            {
                if (null != messengerSession)
                {
                    messengerSession.PmppCrcErrors++;
                }
            }
            packetChecksum = null;
            pseudoChecksum = null;

            //back at the beginning to decode the Hdlc fields
            Position = 0;

            List <byte> HdlcAddress = new List <byte>();
            Byte?       HdlcControlField;
            List <byte> HdlcProtocolIdentifier = new List <byte>();

            HdlcAddress            = GetHdlcField(ref Decoded, ref Position);
            HdlcControlField       = Bytes[Position++];
            HdlcProtocolIdentifier = GetHdlcField(ref Decoded, ref Position);


            if (!IncludeHdlcFields)
            {
                //Remove the fields we retrieved
                Decoded.RemoveRange(0, Position);
            }

            HdlcAddress            = null;
            HdlcControlField       = null;
            HdlcProtocolIdentifier = null;

            Bytes.Clear();

            Bytes.AddRange(Decoded);

            return(Bytes);
        }
コード例 #3
0
 public static List <byte> PmppEncode(this List <byte> InformationPayload, Transport.SnmpMessenger messengerSession)
 {
     return(PmppEncode(InformationPayload, messengerSession.PmppEndPoint.Value.Address, messengerSession.PmppEndPoint.Value.Control, messengerSession.PmppEndPoint.Value.ProtocolIdentifier));
 }
コード例 #4
0
 public TcpTransport(SnmpMessenger messengerSession, TcpClient existingClient)
 {
     this._session = messengerSession;
     this._client  = existingClient;
 }
コード例 #5
0
 /// <summary>
 /// Constructor. Initializes and binds the Socket class
 /// </summary>
 public TcpTransport(SnmpMessenger messengerSession)
 {
     this._session = messengerSession;
 }
コード例 #6
0
 public UdpTransport(SnmpMessenger messengerSession, UdpClient existingClient)
 {
     this._session = messengerSession;
     this._socket  = existingClient.Client;
 }