Exemplo n.º 1
0
 public TCPopTS(byte[] data, int offset) //Offset will include Kind and Len
 {
     //'(80 bits)'
     offset += 2;
     NetLib.ReadUInt32(data, ref offset, out SenderTimeStamp);
     NetLib.ReadUInt32(data, ref offset, out EchoTimeStamp);
 }
Exemplo n.º 2
0
        public DNSResponseEntry(byte[] buffer, int offset) : base(buffer, offset)
        {
            offset += base.Length;
            UInt16 dataLen;

            NetLib.ReadUInt32(buffer, ref offset, out ttl);
            NetLib.ReadUInt16(buffer, ref offset, out dataLen);
            NetLib.ReadByteArray(buffer, ref offset, dataLen, out data);
        }
Exemplo n.º 3
0
        public DHCP(byte[] data)
        {
            int offset = 0;

            //Bits 0-31 //Bytes 0-3
            NetLib.ReadByte08(data, ref offset, out OP);
            Log_Verb("OP " + OP);
            NetLib.ReadByte08(data, ref offset, out HardwareType);
            //Error.WriteLine("HWt " + HardwareType);
            NetLib.ReadByte08(data, ref offset, out HardwareAddressLength);
            //Error.WriteLine("HWaddrlen " + HardwareAddressLength);
            NetLib.ReadByte08(data, ref offset, out Hops);
            //Error.WriteLine("Hops " + Hops);

            //Bits 32-63 //Bytes 4-7
            //TransactionID = BitConverter.ToInt32(data, 4);
            NetLib.ReadUInt32(data, ref offset, out TransactionID);
            Log_Verb("xid " + TransactionID);

            //Bits 64-95 //Bytes 8-11
            NetLib.ReadUInt16(data, ref offset, out Seconds);
            //Error.WriteLine("sec " + Seconds);
            NetLib.ReadUInt16(data, ref offset, out Flags);
            //Error.WriteLine("Flags " + Flags);

            //Bits 96-127 //Bytes 12-15
            NetLib.ReadByteArray(data, ref offset, 4, out ClientIP);
            Log_Info("CIP " + ClientIP[0] + "." + ClientIP[1] + "." + ClientIP[2] + "." + ClientIP[3]);

            //Bits 128-159 //Bytes 16-19
            NetLib.ReadByteArray(data, ref offset, 4, out YourIP);
            Log_Info("YIP " + YourIP[0] + "." + YourIP[1] + "." + YourIP[2] + "." + YourIP[3]);

            //Bits 160-191 //Bytes 20-23
            NetLib.ReadByteArray(data, ref offset, 4, out ServerIP);
            Log_Info("SIP " + ServerIP[0] + "." + ServerIP[1] + "." + ServerIP[2] + "." + ServerIP[3]);

            //Bits 192-223 //Bytes 24-27
            NetLib.ReadByteArray(data, ref offset, 4, out GatewayIP);
            Log_Info("GIP " + GatewayIP[0] + "." + GatewayIP[1] + "." + GatewayIP[2] + "." + GatewayIP[3]);

            //Bits 192+ //Bytes 28-43
            NetLib.ReadByteArray(data, ref offset, 16, out ClientHardwareAddress);

            //Bytes 44-107

            byte[] sNamebytes;
            NetLib.ReadByteArray(data, ref offset, 64, out sNamebytes);

            //Bytes 108-235
            byte[] filebytes;
            NetLib.ReadByteArray(data, ref offset, 128, out filebytes);

            //Bytes 236-239
            NetLib.ReadUInt32(data, ref offset, out MagicCookie);
            //Error.WriteLine("Cookie " + MagicCookie);
            bool opReadFin = false;

            //int op_offset = 240;
            do
            {
                byte opKind = data[offset];
                if (opKind == 255)
                {
                    Options.Add(new DHCPopEND());
                    opReadFin = true;
                    offset   += 1;
                    continue;
                }
                if ((offset + 1) >= data.Length)
                {
                    Log_Error("Unexpected end of packet");
                    Options.Add(new DHCPopEND());
                    opReadFin = true;
                    continue;
                }
                byte opLen = data[offset + 1];
                switch (opKind)
                {
                case 0:
                    //Error.WriteLine("Got NOP");
                    Options.Add(new DHCPopNOP());
                    offset += 1;
                    continue;

                case 1:
                    //Error.WriteLine("Got Subnet");
                    Options.Add(new DHCPopSubnet(data, offset));
                    break;

                case 3:
                    //Error.WriteLine("Got Router");
                    Options.Add(new DHCPopRouter(data, offset));
                    break;

                case 6:
                    //Error.WriteLine("Got DNS Servers");
                    Options.Add(new DHCPopDNS(data, offset));
                    break;

                case 12:
                    Options.Add(new DHCPopHOSTNAME(data, offset));
                    break;

                case 15:
                    //Error.WriteLine("Got Domain Name (Not supported)");
                    Options.Add(new DHCPopDNSNAME(data, offset));
                    break;

                case 28:
                    //Error.WriteLine("Got broadcast");
                    Options.Add(new DHCPopBCIP(data, offset));
                    break;

                case 46:
                    //Error.WriteLine("Got Request IP");
                    Options.Add(new DHCPopNBOIPType(data, offset));
                    break;

                case 50:
                    //Error.WriteLine("Got Request IP");
                    Options.Add(new DHCPopREQIP(data, offset));
                    break;

                case 51:
                    //Error.WriteLine("Got IP Address Lease Time");
                    Options.Add(new DHCPopIPLT(data, offset));
                    break;

                case 53:
                    //Error.WriteLine("Got MSG");
                    Options.Add(new DHCPopMSG(data, offset));
                    break;

                case 54:
                    //Error.WriteLine("Got Server IP");
                    Options.Add(new DHCPopSERVIP(data, offset));
                    break;

                case 55:
                    //Error.WriteLine("Got Request List");
                    Options.Add(new DHCPopREQLIST(data, offset));
                    break;

                case 56:
                    Options.Add(new DHCPopMSGStr(data, offset));
                    break;

                case 57:
                    //Error.WriteLine("Got Max Message Size");
                    Options.Add(new DHCPopMMSGS(data, offset));
                    break;

                case 58:
                    //Error.WriteLine("Got Renewal (T1) Time");
                    Options.Add(new DHCPopT1(data, offset));
                    break;

                case 59:
                    //Error.WriteLine("Got Rebinding (T2) Time");
                    Options.Add(new DHCPopT2(data, offset));
                    break;

                case 60:
                    //Error.WriteLine("Got Max Message Size");
                    Options.Add(new DHCPopClassID(data, offset));
                    break;

                case 61:
                    //Error.WriteLine("Got Client ID");
                    Options.Add(new DHCPopClientID(data, offset));
                    break;

                default:
                    Log_Error("Got Unknown Option " + opKind + " with len " + opLen);
                    break;
                }
                offset += opLen + 2;
                if (offset >= data.Length)
                {
                    Log_Error("Unexpected end of packet");
                    Options.Add(new DHCPopEND());
                    opReadFin = true;
                }
            } while (opReadFin == false);
        }
Exemplo n.º 4
0
        public DHCP()
        {
            int x = 0;

            NetLib.ReadUInt32(new byte[] { 99, 130, 83, 99 }, ref x, out MagicCookie);
        }
Exemplo n.º 5
0
 public DHCPopT2(byte[] data, int offset) //Offset will include Kind and Len
 {
     offset += 2;
     NetLib.ReadUInt32(data, ref offset, out IPRebindingTimeT2);
 }
Exemplo n.º 6
0
 public DHCPopT1(byte[] data, int offset) //Offset will include Kind and Len
 {
     offset += 2;
     NetLib.ReadUInt32(data, ref offset, out IPRenewalTimeT1);
 }
Exemplo n.º 7
0
 public DHCPopIPLT(byte[] data, int offset) //Offset will include Kind and Len
 {
     offset += 2;
     NetLib.ReadUInt32(data, ref offset, out IPLeaseTime);
 }
Exemplo n.º 8
0
        public TCP(byte[] buffer, int offset, int parLength) //Length = IP payload len
        {
            int initialOffset = offset;

            //Bits 0-31
            NetLib.ReadUInt16(buffer, ref offset, out SourcePort);
            //Error.WriteLine("src port=" + SourcePort);
            NetLib.ReadUInt16(buffer, ref offset, out DestinationPort);
            //Error.WriteLine("dts port=" + DestinationPort);

            //Bits 32-63
            NetLib.ReadUInt32(buffer, ref offset, out SequenceNumber);
            //Error.WriteLine("seq num=" + SequenceNumber); //Where in the stream the start of the payload is

            //Bits 64-95
            NetLib.ReadUInt32(buffer, ref offset, out AcknowledgementNumber);
            //Error.WriteLine("ack num=" + AcknowledgmentNumber); //the next expected byte(seq) number

            //Bits 96-127
            NetLib.ReadByte08(buffer, ref offset, out dataOffsetAndNS_Flag);
            //Error.WriteLine("TCP hlen=" + HeaderLength);
            NetLib.ReadByte08(buffer, ref offset, out flags);
            NetLib.ReadUInt16(buffer, ref offset, out WindowSize);
            //Error.WriteLine("win Size=" + WindowSize);

            //Bits 127-159
            NetLib.ReadUInt16(buffer, ref offset, out checksum);
            NetLib.ReadUInt16(buffer, ref offset, out urgentPointer);
            //Error.WriteLine("urg ptr=" + UrgentPointer);

            //Bits 160+
            if (headerLength > 20) //TCP options
            {
                bool opReadFin = false;
                do
                {
                    byte opKind = buffer[offset];
                    byte opLen  = buffer[offset + 1];
                    switch (opKind)
                    {
                    case 0:
                        //Error.WriteLine("Got End of Options List @ " + (op_offset-offset-1));
                        opReadFin = true;
                        break;

                    case 1:
                        //Error.WriteLine("Got NOP");
                        Options.Add(new TCPopNOP());
                        offset += 1;
                        continue;

                    case 2:
                        //Error.WriteLine("Got MMS");
                        Options.Add(new TCPopMSS(buffer, offset));
                        break;

                    case 3:
                        Options.Add(new TCPopWS(buffer, offset));
                        break;

                    case 8:
                        //Error.WriteLine("Got Timestamp");
                        Options.Add(new TCPopTS(buffer, offset));
                        break;

                    default:
                        Log_Error("Got TCP Unknown Option " + opKind + "with len" + opLen);
                        throw new Exception("Got TCP Unknown Option " + opKind + "with len" + opLen);
                        //break;
                    }
                    offset += opLen;
                    if (offset == initialOffset + headerLength)
                    {
                        //Error.WriteLine("Reached end of Options");
                        opReadFin = true;
                    }
                } while (opReadFin == false);
            }
            offset = initialOffset + headerLength;

            NetLib.ReadByteArray(buffer, ref offset, parLength - headerLength, out data);
            //AllDone
        }