public uint ReadUInt(NetworkPacket packet) { ushort attrLength = packet.ReadUShort(); uint value = packet.ReadUInt(); return(value); }
public override void ReadRequest(NetworkPacket packet) { segmentLen = 0; startPos = packet.ReadUInt(); //first stream segment if (startPos == 0) { uint totalBytes = packet.ReadUInt(); command = packet.ReadString(); byteData = new byte[totalBytes]; segmentLen = packet.ReadUInt(); byte[] bytes = packet.ReadBytes((int)segmentLen); SetBuffer(bytes, 0); return; } //subsequent stream segments segmentLen = packet.ReadUInt(); byteData = packet.ReadBytes((int)segmentLen); }
public string ReadErrorCode(NetworkPacket packet) { ushort attrLength = packet.ReadUShort(); uint bits = packet.ReadUInt(); uint code = bits & 0xFF; uint codeClass = (bits & 0x700) >> 8; string phrase = packet.ReadString(attrLength - 4); while ((attrLength++) % 4 != 0) { packet.ReadByte(); } return("Error (" + codeClass + code.ToString("D2") + "): " + phrase); }
public STUNAddress ReadXorMappedAddress(NetworkPacket packet) { STUNAddress sa = new STUNAddress(); ushort attrLength = packet.ReadUShort(); ushort xorFlag16 = (ushort)(magicCookie >> 16); byte empty = packet.ReadByte(); sa.family = packet.ReadByte(); sa.port = (ushort)(packet.ReadUShort() ^ xorFlag16); switch (sa.family) { case 1: byte[] xorFlagBytes = new byte[4]; Array.Copy(packet.ByteBuffer, 4, xorFlagBytes, 0, 4); Array.Reverse(xorFlagBytes); uint xorFlag32 = BitConverter.ToUInt32(xorFlagBytes, 0); sa.address = new byte[4]; uint address = packet.ReadUInt() ^ xorFlag32; sa.address[0] = (byte)((address & 0xff000000) >> 24); sa.address[1] = (byte)((address & 0x00ff0000) >> 16); sa.address[2] = (byte)((address & 0x0000ff00) >> 8); sa.address[3] = (byte)(address & 0x000000ff); break; case 2: sa.address = new byte[16]; byte[] xorFlags = new byte[16]; Array.Copy(transactionID, 0, xorFlags, xorFlags.Length, transactionID.Length); for (int i = 0; i < sa.address.Length; i++) { sa.address[i] = (byte)(packet.ReadByte() ^ xorFlags[i]); } break; } return(sa); }