공부,일/C# 네트워크
packet 분석기 만들기 (4)
fromnothing1
2021. 9. 28. 11:45
2계층 헤더 분석

1. Version : ip version 을 나타냄
2. IHL : ip header 크기 최대 60 byte 까지 가능 ,4bit 로 표현하기 때문에 줄수만 표현한다.
3. TOS : Type of Service
4. Total Length : 1계층 헤더를 제외한 데이터의 크기
위의 2 layer 를 분석해서 출력해주는 함수 생성 (Print_IP)
static void Print_IP(byte[] bEther, int ioffest)
{
Console.WriteLine("IP_VERSION : {0} ", bEther[ioffest] >> 4);
Console.WriteLine("IHL(IP Head Length) : {0} Byte", (bEther[ioffest] & 0x0f) * 4); // bEther[ioffest] * 4 = IHL ip header 크기 -> 4bit 로 최대 60 byte 를 표현하기 위해서 4를 곱해준다.
Console.WriteLine("Type of Service : 0x{0:X02} Byte", bEther[ioffest+1]);
byte[] bType = new byte[2];
Array.Copy(bEther, ioffest+2, bType, 0, 2);
if (BitConverter.IsLittleEndian)
{
Array.Reverse(bType);
}
short sTemp = BitConverter.ToInt16(bType, 0);
Console.WriteLine("Total Length : {0} Bytes", sTemp);
}