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); }
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); }
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; }
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]); }
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); }
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); }
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); }
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); }
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); }
private void Awake() { serverState = new State(); clientState = new State(); networkedComponentTypeInfo = NetLib.GetNetworkedComponentTypeInfo(typeof(State)); sendUpdateAction = new ThrottledAction(SendUpdate, 0.25f); }
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 }
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); }
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); }
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); }
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); }
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); }
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 }
//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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }