السلام عليكم ورحمة الله وبركاته
قرأت عن كيفية قراءة الباكت لكن حاولت افهم هذه الجملة لكن للحقيقة لم افهمها
فمثلا
m_Version = (raw(0) & &HF0) >> 4
هذا الكود يستخدم فى معرفة ipv
الذى توصلت له هو معنى هذه الجزء
(raw(0) & &HF0)
وهو يقوم بعملية
andding
وهذا الجزء
>> 4
يساوى
قسمة الناتج على 2 اس 4
لكن انا لم افهم الجملة على بعضها
يعنى ليه كل هذه اللفة الطويلة
لماذا لم يتم كتابة ipv
هكذا 4
او هكذا 6
هذا هو الكود بالكامل
public Packet(byte[] raw, DateTime time) {
if (raw == null)
throw new ArgumentNullException();
if (raw.Length < 20)
throw new ArgumentException(); // invalid IP packet
m_Raw = raw;
m_Time = time;
m_Version = (raw[0] & 0xF0) >> 4;
var x = 69 & 0xF0;
int xx = 33 & 240;
int xxx = 64 >> 3;
m_HeaderLength = (raw[0] & 0x0F) * 4 /* sizeof(int) */;
if ((raw[0] & 0x0F) < 5)
throw new ArgumentException(); // invalid header of packet
m_Precedence = (Precedence)((raw[1] & 0xE0) >> 5);
m_Delay = (Delay)((raw[1] & 0x10) >> 4);
m_Throughput = (Throughput)((raw[1] & 0x8) >> 3);
m_Reliability = (Reliability)((raw[1] & 0x4) >> 2);
m_TotalLength = raw[2] * 256 + raw[3];
if (m_TotalLength != raw.Length)
throw new ArgumentException(); // invalid size of packet
m_Identification = raw[4] * 256 + raw[5];
m_TimeToLive = raw[8];
if (Enum.IsDefined(typeof(Protocol), (int)raw[9]))
m_Protocol = (Protocol)raw[9];
else
m_Protocol = Protocol.Other;
m_Checksum = new byte[2];
m_Checksum[0] = raw[11];
m_Checksum[1] = raw[10];
m_SourceAddress = new IPAddress(BitConverter.ToUInt32(raw, 12));
m_DestinationAddress = new IPAddress(BitConverter.ToUInt32(raw, 16));
if (m_Protocol == Protocol.Tcp || m_Protocol == Protocol.Udp) {
m_SourcePort = raw[m_HeaderLength] * 256 + raw[m_HeaderLength + 1];
m_DestinationPort = raw[m_HeaderLength + 2] * 256 + raw[m_HeaderLength + 3];
} else {
m_SourcePort = -1;
m_DestinationPort = -1;
}
}
وجزاكم الله خيرا