Пример #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);
        }
Пример #2
0
    private void Awake()
    {
        // Destroy the game object if there is already an OsFps instance.
        if (Instance != null)
        {
            enabled = false;
            gameObject.SetActive(false);
            Destroy(gameObject);
            return;
        }

        Assert.raiseExceptions = true;

        Instance = this;
        DontDestroyOnLoad(gameObject);

        GameObject guiContainer = Instantiate(GUIContainerPrefab);

        DontDestroyOnLoad(guiContainer);

        CreateDataObject();
        CanvasObject = guiContainer.FindDescendant("Canvas");

        var networkMatch = gameObject.AddComponent <NetworkMatch>();

        NetLib.NetworkMatch = networkMatch;
        NetLib.Setup();

        Settings.LoadFromFile(SettingsFilePath);
    }
Пример #3
0
        private void ReadDNSString(byte[] buffer, ref int offset, out string value)
        {
            value = "";
            while (buffer[offset] != 0)
            {
                int    len = buffer[offset];
                string o;

                if (len >= 192)
                {
                    byte[] addrB;
                    DataLib.ReadByteArray(buffer, ref offset, 2, out addrB);

                    addrB[0] &= unchecked ((byte)~0xC0);
                    UInt16 addr;
                    int    tmp = 0;
                    NetLib.ReadUInt16(addrB, ref tmp, out addr);
                    tmp = addr;
                    ReadDNSString(buffer, ref tmp, out o);

                    value  += o + ".";
                    offset -= 1;
                    break;
                }
                else
                {
                    offset += 1;
                    NetLib.ReadCString(buffer, ref offset, len, out o);
                }
                offset -= 1;
                value  += o + ".";
            }
            value   = value.Substring(0, value.Length - 1);
            offset += 1;
        }
Пример #4
0
        public ARPPacket(EthernetFrame Ef)
        {
            int pktOffset = Ef.HeaderLength;

            NetLib.ReadUInt16(Ef.RawPacket.buffer, ref pktOffset, out HardWareType);
            //
            DataLib.ReadUInt16(Ef.RawPacket.buffer, ref pktOffset, out Protocol);
            //
            NetLib.ReadByte08(Ef.RawPacket.buffer, ref pktOffset, out HardwareAddressLength);
            NetLib.ReadByte08(Ef.RawPacket.buffer, ref pktOffset, out ProtocolAddressLength);
            NetLib.ReadUInt16(Ef.RawPacket.buffer, ref pktOffset, out OP);
            //Error.WriteLine("OP" + OP);

            NetLib.ReadByteArray(Ef.RawPacket.buffer, ref pktOffset, HardwareAddressLength, out SenderHardwareAddress);
            //WriteLine("sender MAC :" + SenderHardwareAddress[0] + ":" + SenderHardwareAddress[1] + ":" + SenderHardwareAddress[2] + ":" + SenderHardwareAddress[3] + ":" + SenderHardwareAddress[4] + ":" + SenderHardwareAddress[5]);

            NetLib.ReadByteArray(Ef.RawPacket.buffer, ref pktOffset, ProtocolAddressLength, out SenderProtocolAddress);
            //WriteLine("sender IP :" + SenderProtocolAddress[0] + "." + SenderProtocolAddress[1] + "." + SenderProtocolAddress[2] + "." + SenderProtocolAddress[3]);

            NetLib.ReadByteArray(Ef.RawPacket.buffer, ref pktOffset, HardwareAddressLength, out TargetHardwareAddress);
            //WriteLine("target MAC :" + TargetHardwareAddress[0] + ":" + TargetHardwareAddress[1] + ":" + TargetHardwareAddress[2] + ":" + TargetHardwareAddress[3] + ":" + TargetHardwareAddress[4] + ":" + TargetHardwareAddress[5]);

            NetLib.ReadByteArray(Ef.RawPacket.buffer, ref pktOffset, ProtocolAddressLength, out TargetProtocolAddress);
            //WriteLine("target IP :" + TargetProtocolAddress[0] + "." + TargetProtocolAddress[1] + "." + TargetProtocolAddress[2] + "." + TargetProtocolAddress[3]);
        }
Пример #5
0
 public DHCPopClientID(byte[] data, int offset) //Offset will include Kind and Len
 {
     offset += 1;
     NetLib.ReadByte08(data, ref offset, out len);
     //ClientID = new byte[len];
     NetLib.ReadByteArray(data, ref offset, len, out clientID);
 }
Пример #6
0
        private void CalculateCheckSum()
        {
            //if (!(i == 5)) //checksum feild is 10-11th byte (5th short), which is skipped
            ReComputeHeaderLen();
            byte[] headerSegment = new byte[hLen];
            int    counter       = 0;

            NetLib.WriteByte08(headerSegment, ref counter, (byte)(_verHi + (hLen >> 2)));
            NetLib.WriteByte08(headerSegment, ref counter, typeOfService);//DSCP/ECN
            NetLib.WriteUInt16(headerSegment, ref counter, length);

            NetLib.WriteUInt16(headerSegment, ref counter, id);
            NetLib.WriteByte08(headerSegment, ref counter, fragmentFlags1);
            NetLib.WriteByte08(headerSegment, ref counter, fragmentFlags2);

            NetLib.WriteByte08(headerSegment, ref counter, ttl);
            NetLib.WriteByte08(headerSegment, ref counter, Protocol);
            NetLib.WriteUInt16(headerSegment, ref counter, 0); //header csum

            NetLib.WriteByteArray(headerSegment, ref counter, SourceIP);
            NetLib.WriteByteArray(headerSegment, ref counter, DestinationIP);

            //options
            for (int i = 0; i < Options.Count; i++)
            {
                NetLib.WriteByteArray(headerSegment, ref counter, Options[i].GetBytes());
            }
            counter = hLen;

            checksum = InternetChecksum(headerSegment);
        }
Пример #7
0
        public bool VerifyCheckSum()
        {
            ReComputeHeaderLen();
            byte[] headerSegment = new byte[hLen];
            int    counter       = 0;

            NetLib.WriteByte08(headerSegment, ref counter, (byte)(_verHi + (hLen >> 2)));
            NetLib.WriteByte08(headerSegment, ref counter, typeOfService);//DSCP/ECN
            NetLib.WriteUInt16(headerSegment, ref counter, length);

            NetLib.WriteUInt16(headerSegment, ref counter, id);
            NetLib.WriteByte08(headerSegment, ref counter, fragmentFlags1);
            NetLib.WriteByte08(headerSegment, ref counter, fragmentFlags2);

            NetLib.WriteByte08(headerSegment, ref counter, ttl);
            NetLib.WriteByte08(headerSegment, ref counter, Protocol);
            NetLib.WriteUInt16(headerSegment, ref counter, checksum); //header csum

            NetLib.WriteByteArray(headerSegment, ref counter, SourceIP);
            NetLib.WriteByteArray(headerSegment, ref counter, DestinationIP);

            //options
            for (int i = 0; i < Options.Count; i++)
            {
                NetLib.WriteByteArray(headerSegment, ref counter, Options[i].GetBytes());
            }
            counter = hLen;

            UInt16 CsumCal = InternetChecksum(headerSegment);

            return(CsumCal == 0);
        }
Пример #8
0
 public TCPopWS(byte[] data, int offset) //Offset will include Kind and Len
 {
     //'(24 bits)'
     offset += 2;
     NetLib.ReadByte08(data, ref offset, out WindowScale);
     Log_Verb("Got Window scale of " + WindowScale);
 }
Пример #9
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);
 }
Пример #10
0
 private void Awake()
 {
     serverState = new State();
     clientState = new State();
     networkedComponentTypeInfo = NetLib.GetNetworkedComponentTypeInfo(typeof(State));
     sendUpdateAction           = new ThrottledAction(SendUpdate, 0.25f);
 }
Пример #11
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
        }
Пример #12
0
        public override byte[] GetBytes()
        {
            int len = Length;

            byte[] ret     = new byte[len];
            int    counter = 0;

            NetLib.WriteUInt16(ret, ref counter, SourcePort);
            NetLib.WriteUInt16(ret, ref counter, DestinationPort);
            NetLib.WriteUInt32(ret, ref counter, SequenceNumber);
            NetLib.WriteUInt32(ret, ref counter, AcknowledgementNumber);
            NetLib.WriteByte08(ret, ref counter, dataOffsetAndNS_Flag);
            NetLib.WriteByte08(ret, ref counter, flags);
            NetLib.WriteUInt16(ret, ref counter, WindowSize);
            NetLib.WriteUInt16(ret, ref counter, checksum);
            NetLib.WriteUInt16(ret, ref counter, urgentPointer);

            //options
            for (int i = 0; i < Options.Count; i++)
            {
                NetLib.WriteByteArray(ret, ref counter, Options[i].GetBytes());
            }
            counter = headerLength;
            NetLib.WriteByteArray(ret, ref counter, data);
            return(ret);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
 public TCPopMSS(byte[] data, int offset) //Offset will include Kind and Len
 {
     //'(32 bits)'
     offset += 2;
     NetLib.ReadUInt16(data, ref offset, out MaxSegmentSize);
     Log_Verb("Got Maximum segment size of " + MaxSegmentSize);
 }
Пример #16
0
        public override byte[] GetBytes()
        {
            CalculateCheckSum(); //ReComputeHeaderLen called in CalculateCheckSum
            _pl.CalculateCheckSum(SourceIP, DestinationIP);

            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, (byte)(_verHi + (hLen >> 2)));
            NetLib.WriteByte08(ret, ref counter, typeOfService);//DSCP/ECN
            NetLib.WriteUInt16(ret, ref counter, length);

            NetLib.WriteUInt16(ret, ref counter, id);
            NetLib.WriteByte08(ret, ref counter, fragmentFlags1);
            NetLib.WriteByte08(ret, ref counter, fragmentFlags2);

            NetLib.WriteByte08(ret, ref counter, ttl);
            NetLib.WriteByte08(ret, ref counter, Protocol);
            NetLib.WriteUInt16(ret, ref counter, checksum); //header csum

            NetLib.WriteByteArray(ret, ref counter, SourceIP);
            NetLib.WriteByteArray(ret, ref counter, DestinationIP);;

            //options
            for (int i = 0; i < Options.Count; i++)
            {
                NetLib.WriteByteArray(ret, ref counter, Options[i].GetBytes());
            }
            counter = hLen;

            byte[] plBytes = _pl.GetBytes();
            NetLib.WriteByteArray(ret, ref counter, plBytes);
            return(ret);
        }
Пример #17
0
 public IGMP(byte[] buffer, int offset, int Length)
 {
     NetLib.ReadByte08(buffer, ref offset, out Type);
     NetLib.ReadByte08(buffer, ref offset, out maxResponseTime);
     NetLib.ReadUInt16(buffer, ref offset, out checksum);
     NetLib.ReadByteArray(buffer, ref offset, 4, out GroupAddress);
     //TODO version 3
 }
Пример #18
0
        //TODO, add a Recompute length call, and call that in DNS.GetBytes()
        public DNSQuestionEntry(byte[] buffer, int offset)
        {
            int s = offset;

            ReadDNSString(buffer, ref offset, out _name);
            nameDNSLength = offset - s;
            NetLib.ReadUInt16(buffer, ref offset, out _type);
            NetLib.ReadUInt16(buffer, ref offset, out _class);
        }
Пример #19
0
 public int SendUdpData(string targetIP, int targetPort, object udpDataObj)
 {
     byte[] udpDataByte = ConvertLuaTableToBytes(udpDataObj);
     if (udpDataByte == null)
     {
         return((int)LuaApiResult.SendUdpDataFailed);
     }
     return((int)(NetLib.SendUdpData(targetIP, targetPort, udpDataByte) ? LuaApiResult.Success : LuaApiResult.SendUdpDataFailed));
 }
Пример #20
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);
        }
Пример #21
0
        public virtual byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            WriteDNSString(ref ret, ref counter, _name);
            NetLib.WriteUInt16(ref ret, ref counter, _type);
            NetLib.WriteUInt16(ref ret, ref counter, _class);
            return(ret);
        }
Пример #22
0
        public virtual byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByteArray(ret, ref counter, nameBytes);
            NetLib.WriteUInt16(ret, ref counter, Type);
            NetLib.WriteUInt16(ret, ref counter, Class);
            return(ret);
        }
Пример #23
0
        public override byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, Code);
            NetLib.WriteByte08(ret, ref counter, (byte)(Length - 2));
            NetLib.WriteByteArray(ret, ref counter, clientID);
            return(ret);
        }
Пример #24
0
        public override byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, Code);
            NetLib.WriteByte08(ret, ref counter, (byte)(Length - 2));
            NetLib.WriteUInt16(ret, ref counter, MaxMessageSize);
            return(ret);
        }
Пример #25
0
        public override byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, Code);
            NetLib.WriteByte08(ret, ref counter, (byte)(Length - 2));
            NetLib.WriteUInt32(ret, ref counter, IPRebindingTimeT2);
            return(ret);
        }
Пример #26
0
        public override byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, Code);
            NetLib.WriteByte08(ret, ref counter, Length);
            NetLib.WriteUInt16(ret, ref counter, MaxSegmentSize);
            return(ret);
        }
Пример #27
0
        public override byte[] GetBytes()
        {
            byte[] ret     = base.GetBytes();
            int    counter = base.Length;

            NetLib.WriteUInt32(ret, ref counter, ttl);
            NetLib.WriteUInt16(ret, ref counter, (UInt16)data.Length);
            NetLib.WriteByteArray(ret, ref counter, data);
            return(ret);
        }
Пример #28
0
        public override byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, Code);
            NetLib.WriteByte08(ret, ref counter, Length);
            NetLib.WriteByte08(ret, ref counter, WindowScale);
            return(ret);
        }
Пример #29
0
        public override byte[] GetBytes()
        {
            byte[] ret     = new byte[Length];
            int    counter = 0;

            NetLib.WriteByte08(ret, ref counter, Code);
            NetLib.WriteByte08(ret, ref counter, Length);
            NetLib.WriteUInt32(ret, ref counter, SenderTimeStamp);
            NetLib.WriteUInt32(ret, ref counter, EchoTimeStamp);
            return(ret);
        }
Пример #30
0
        public ICMP(byte[] buffer, int offset, int Length) //Length = IP payload len
        {
            NetLib.ReadByte08(buffer, ref offset, out Type);
            //Error.WriteLine("Type = " + Type);
            NetLib.ReadByte08(buffer, ref offset, out Code);
            //Error.WriteLine("Code = " + Code);
            NetLib.ReadUInt16(buffer, ref offset, out checksum);
            NetLib.ReadByteArray(buffer, ref offset, 4, out HeaderData);

            NetLib.ReadByteArray(buffer, ref offset, Length - 8, out Data);
        }