-
Notifications
You must be signed in to change notification settings - Fork 1
/
TunFrame.cs
34 lines (28 loc) · 989 Bytes
/
TunFrame.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Margatroid.Alice.Native
{
class TunFrame
{
public readonly byte[] FrameData;
public readonly int Flag;
public readonly int Proto;
public readonly IPAddress SourceAddress;
public readonly IPAddress DestinationAddress;
public TunFrame(byte[] data)
{
FrameData = data;
// Flag (2 bytes)
Flag = BitConverter.ToInt32(new byte[] { FrameData[0], FrameData[1] });
// Proto (2 bytes)
Proto = BitConverter.ToInt32(new byte[] { FrameData[2], FrameData[3] });
// IP Packet
SourceAddress = new IPAddress(Enumerable.Range(12 + 4, 4).Select(i => FrameData[i]).ToArray());
DestinationAddress = new IPAddress(Enumerable.Range(15 + 4, 4).Select(i => FrameData[i]).ToArray());
}
}
}