Reputation: 61
In my C# application I'm using the PacketDotNet lib. So, I'm trying to send a vlan tagged frame, but can't build it correctly. My code:
public static void Main(string[] args)
{
const ushort udpSourcePort = 123;
const ushort udpDestinationPort = 321;
var udpPacket = new UdpPacket(udpSourcePort, udpDestinationPort);
var ipSourceAddress = System.Net.IPAddress.Parse("192.168.1.1");
var ipDestinationAddress = System.Net.IPAddress.Parse("192.168.1.2");
var iPv4Packet = new IPv4Packet(ipSourceAddress, ipDestinationAddress);
var vlan = new Ieee8021QPacket(iPv4Packet.BytesSegment)
{
VlanIdentifier = 14
};
const string sourceHwAddress = "90-90-90-90-90-90";
var ethernetSourceHwAddress = System.Net.NetworkInformation.PhysicalAddress.Parse(sourceHwAddress);
const string destinationHwAddress = "80-80-80-80-80-80";
var ethernetDestinationHwAddress = System.Net.NetworkInformation.PhysicalAddress.Parse(destinationHwAddress);
var ethernetPacket = new EthernetPacket(ethernetSourceHwAddress,
ethernetDestinationHwAddress,
EthernetType.None);
// Now stitch all of the packets together
iPv4Packet.PayloadPacket = udpPacket;
vlan.PayloadPacket = iPv4Packet;
ethernetPacket.PayloadPacket = vlan;
// and print out the packet to see that it looks just like we wanted it to
Console.WriteLine(ethernetPacket.ToString());
}
However, the output created by seems not to be correct.
How to build the vlan tagged frame in PacketDotNet correctly?
Upvotes: 0
Views: 540