Example #1
0
        public override bool VerifyCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = (12) + HeaderLength + data.Length;

            if ((pHeaderLen & 1) != 0)
            {
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            int    counter       = 0;

            NetLib.WriteByteArray(headerSegment, ref counter, srcIP);
            NetLib.WriteByteArray(headerSegment, ref counter, dstIP);
            counter += 1;//[8] = 0
            NetLib.WriteByte08(headerSegment, ref counter, Protocol);
            NetLib.WriteUInt16(headerSegment, ref counter, Length);

            //Pseudo Header added
            //Rest of data is normal Header+data (with zerored checksum feild)
            NetLib.WriteByteArray(headerSegment, ref counter, GetBytes());

            UInt16 CsumCal = IPPacket.InternetChecksum(headerSegment);

            //Error.WriteLine("UDP Checksum Good = " + (CsumCal == 0));
            return(CsumCal == 0);
        }
Example #2
0
        public override void CalculateCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = (12) + HeaderLength + data.Length;

            if ((pHeaderLen & 1) != 0)
            {
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            int    counter       = 0;

            NetLib.WriteByteArray(headerSegment, ref counter, srcIP);
            NetLib.WriteByteArray(headerSegment, ref counter, dstIP);
            counter += 1;//[8] = 0
            NetLib.WriteByte08(headerSegment, ref counter, Protocol);
            NetLib.WriteUInt16(headerSegment, ref counter, Length);

            //Pseudo Header added
            //Rest of data is normal Header+data (with zerored checksum feild)
            //Null Checksum
            checksum = 0;
            NetLib.WriteByteArray(headerSegment, ref counter, GetBytes());

            checksum = IPPacket.InternetChecksum(headerSegment); //For performance, we can set this to = zero
        }
Example #3
0
        public override bool VerifyCheckSum(byte[] srcIP, byte[] dstIP)
        {
            UInt16 TCPLength  = (UInt16)(Length);
            int    pHeaderLen = (12 + TCPLength);

            if ((pHeaderLen & 1) != 0)
            {
                //Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            int    counter       = 0;

            NetLib.WriteByteArray(headerSegment, ref counter, srcIP);
            NetLib.WriteByteArray(headerSegment, ref counter, dstIP);
            counter += 1;//[8] = 0
            NetLib.WriteByte08(headerSegment, ref counter, Protocol);
            NetLib.WriteUInt16(headerSegment, ref counter, (UInt16)TCPLength);
            //Pseudo Header added
            //Rest of data is normal neader+data
            NetLib.WriteByteArray(headerSegment, ref counter, GetBytes());

            UInt16 CsumCal = IPPacket.InternetChecksum(headerSegment);

            //Error.WriteLine("Checksum Good = " + (CsumCal == 0));
            return(CsumCal == 0);
        }
Example #4
0
        public override void CalculateCheckSum(byte[] srcIP, byte[] dstIP)
        {
            Int16 TCPLength  = (Int16)(headerLength + data.Length);
            int   pHeaderLen = (12 + TCPLength);

            if ((pHeaderLen & 1) != 0)
            {
                //Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            int    counter       = 0;

            NetLib.WriteByteArray(headerSegment, ref counter, srcIP);
            NetLib.WriteByteArray(headerSegment, ref counter, dstIP);
            counter += 1;//[8] = 0
            NetLib.WriteByte08(headerSegment, ref counter, Protocol);
            NetLib.WriteUInt16(headerSegment, ref counter, (UInt16)TCPLength);
            //Pseudo Header added
            //Rest of data is normal Header+data (with zerored checksum feild)
            //Null Checksum
            checksum = 0;
            NetLib.WriteByteArray(headerSegment, ref counter, GetBytes());

            checksum = IPPacket.InternetChecksum(headerSegment);
        }
Example #5
0
        public override void CalculateCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = ((Length));

            if ((pHeaderLen & 1) != 0)
            {
                //Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            int    counter       = 0;

            checksum = 0;
            NetLib.WriteByteArray(headerSegment, ref counter, GetBytes());

            checksum = IPPacket.InternetChecksum(headerSegment);
        }
Example #6
0
        public override bool VerifyCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = ((Length));

            if ((pHeaderLen & 1) != 0)
            {
                //Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            int    counter       = 0;

            NetLib.WriteByteArray(headerSegment, ref counter, GetBytes());

            UInt16 CsumCal = IPPacket.InternetChecksum(headerSegment);

            //Error.WriteLine("IGMP Checksum Good = " + (CsumCal == 0));
            return(CsumCal == 0);
        }
Example #7
0
        public override bool Recv(ref NetPacket pkt)
        {
            if (dhcpActive)
            {
                IPPayload retDHCP = dhcp.Recv();
                if (retDHCP != null)
                {
                    IPPacket retIP = new IPPacket(retDHCP);
                    retIP.DestinationIP = new byte[] { 255, 255, 255, 255 };
                    retIP.SourceIP = DefaultDHCPConfig.DHCP_IP;

                    EthernetFrame ef = new EthernetFrame(retIP);
                    ef.SourceMAC = virturalDHCPMAC;
                    ef.DestinationMAC = ps2MAC;
                    ef.Protocol = (UInt16)EtherFrameType.IPv4;
                    pkt = ef.CreatePacket();
                    return true;
                }
            }
            return false;
        }
Example #8
0
        public override bool Send(IPPayload payload)
        {
            ICMP icmp = (ICMP)payload;

            switch (icmp.Type)
            {
                case 8: //Echo
                    //Code == zero
                    Log_Verb("Send Ping");
                    lock (sentry)
                    {
                        open += 1;
                    }
                    PingData pd;
                    pd.Data = icmp.Data;
                    pd.HeaderData = icmp.HeaderData;
                    Ping nPing = new Ping();
                    nPing.PingCompleted += PingCompleate;
                    lock (sentry)
                    {
                        pings.Add(nPing);
                    }
                    nPing.SendAsync(new IPAddress(DestIP), pd);
                    System.Threading.Thread.Sleep(1); //Hack Fix
                    break;
                case 3: //
                    switch (icmp.Code)
                    {
                        case 3:
                            Log_Error("Recived Packet Rejected, Port Closed");
                            IPPacket retPkt = new IPPacket(icmp);
                            byte[] srvIP = retPkt.SourceIP;
                            byte prot = retPkt.Protocol;
                            UInt16 srvPort = 0;
                            UInt16 ps2Port = 0;
                            switch (prot)
                            {
                                case (byte)IPType.TCP:
                                    TCP tcp = (TCP)retPkt.Payload;
                                    srvPort = tcp.SourcePort;
                                    ps2Port = tcp.DestinationPort;
                                    break;
                                case (byte)IPType.UDP:
                                    UDP udp = (UDP)retPkt.Payload;
                                    srvPort = udp.SourcePort;
                                    ps2Port = udp.DestinationPort;
                                    break;
                            }
                            ConnectionKey Key = new ConnectionKey();
                            Key.IP0 = srvIP[0]; Key.IP1 = srvIP[1]; Key.IP2 = srvIP[2]; Key.IP3 = srvIP[3];
                            Key.Protocol = prot;
                            Key.PS2Port = ps2Port;
                            Key.SRVPort = srvPort;

                            Session s;
                            connections.TryGetValue(Key, out s);

                            if (s != null)
                            {
                                s.Reset();
                                Log_Info("Reset Rejected Connection");
                            }
                            else
                            {
                                Log_Error("Failed To Reset Rejected Connection");
                            }
                            break;
                        default:
                            throw new NotImplementedException("Unsupported ICMP Code For Destination Unreachable" + icmp.Code);
                    }
                    break;
                default:
                    throw new NotImplementedException("Unsupported ICMP Type" + icmp.Type);
            }

            return true;
        }