Example #1
0
        public DataRequest(byte[] data) : base(new MemoryStream(data))
        {
            try
            {
                Version     = ReadByte();
                Command     = (Command)Enum.ToObject(typeof(Command), ReadByte());
                Reserved    = ReadByte();
                AddressType = (AddressType)Enum.ToObject(typeof(AddressType), ReadByte());

                var data2 = Encoding.ASCII.GetString(data);
                switch (AddressType)
                {
                case AddressType.IPv4:
                    DestinationAddress = new IPAddress(ReadBytes(4));
                    DestinationBytes   = DestinationAddress.GetAddressBytes();
                    break;

                case AddressType.IPv6:
                    DestinationAddress = new IPAddress(ReadBytes(16));
                    DestinationBytes   = DestinationAddress.GetAddressBytes();
                    break;

                case AddressType.DomainName:
                    var octets      = ReadByte();
                    var domainBytes = ReadBytes(octets);
                    var domainName  = Encoding.ASCII.GetString(domainBytes);

                    byte[] count = new byte[1] {
                        octets
                    };

                    DestinationBytes   = count.Concat(domainBytes).ToArray();
                    DestinationAddress = Dns.GetHostAddresses(domainName)[0];
                    break;

                default:
                    Valid = false;
                    break;
                }

                PortBytes = ReadBytes(2);
                Port      = BitConverter.ToUInt16(PortBytes.Reverse().ToArray(), 0);
            }
            catch
            {
                Valid = false;
            }
        }
Example #2
0
 private void showToTBox()
 {
     while (true)
     {
         Application.DoEvents();
         if (listBytes.Count > 0)
         {
             PortBytes portBytes = new PortBytes(show);
             tBoxPortOut.FindForm().BeginInvoke(portBytes, listBytes[0]);
             OutPutEvent.WaitOne();
         }
         else
         {
             Thread.Sleep(1);
             continue;
         }
     }
 }