-
Notifications
You must be signed in to change notification settings - Fork 17
/
Program.cs
38 lines (32 loc) · 1.03 KB
/
Program.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
35
36
37
38
using PacketDotNet;
using SharpPcap;
namespace PhotonPackageParser.Example
{
class Program
{
private readonly PhotonParser photonParser;
public Program()
{
photonParser = new ExampleParser();
}
public static void Main(string[] args)
{
new Program().Start();
}
private void Start()
{
ICaptureDevice device = PacketDeviceSelector.AskForPacketDevice();
device.OnPacketArrival += new PacketArrivalEventHandler(PacketHandler);
device.Open(DeviceMode.Promiscuous, 1000);
device.StartCapture();
}
private void PacketHandler(object sender, CaptureEventArgs e)
{
UdpPacket packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data).Extract<UdpPacket>();
if (packet != null && (packet.SourcePort == 5056 || packet.DestinationPort == 5056))
{
photonParser.ReceivePacket(packet.PayloadData);
}
}
}
}