using (var communicator = _selectedDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000))
{
PacketBuilder builder = new PacketBuilder(new EthernetLayer
{
Source = new MacAddress("01:01:01:01:01:01"),
Destination = new MacAddress("02:02:02:02:02:02"),
EtherType = EthernetType.None, // Will be filled automatically.
}, new IpV4Layer
{
Source = new IpV4Address(string.Join(".", _localIpAddress)),
CurrentDestination = new IpV4Address(string.Join(".", _remoteIpAddress)),
Fragmentation = IpV4Fragmentation.None,
HeaderChecksum = null, // Will be filled automatically.
Identification = 123,
Options = IpV4Options.None,
Protocol = null, // Will be filled automatically.
Ttl = 100,
TypeOfService = 0
}, new UdpLayer
{
SourcePort = (ushort) localPort,
DestinationPort = (ushort) remotePort,
Checksum = null, // Will be filled automatically.
CalculateChecksumValue = true,
}, new PayloadLayer
{
Data = new Datagram(data),
});
// Build and send the packet
communicator.SendPacket(builder.Build(DateTime.Now));
}