This project is read-only.

Add VLAN layer

Mar 12, 2014 at 10:55 PM
I have Pcap file that i try to add VLAN layer so i am using PcapDotNet DLLs like this example:
private Packet AddVlan(Packet packet)
        ILayer ethernet = packet.Ethernet.ExtractLayer();
        IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.VLanTaggedFrame.IpV4.ExtractLayer();
        ILayer payload = packet.Ethernet.IpV4.Payload.ExtractLayer();
        DateTime packetTimestamp = packet.Timestamp;
        ipV4Layer.HeaderChecksum = null;
        VLanTaggedFrameLayer vLanTaggedFrameLayer =
            new VLanTaggedFrameLayer
                PriorityCodePoint = ClassOfService.Background,
                CanonicalFormatIndicator = false,
                VLanIdentifier = 50,
                EtherType = EthernetType.IpV4,

        return PacketBuilder.Build(packetTimestamp, ethernet, vLanTaggedFrameLayer, ipV4Layer, payload);
    catch (Exception)
        return null;

Any idea how solve it ?
Mar 14, 2014 at 11:04 AM
Hi gshhar,

Is the original packet IPv4 over VLAN over Ethernet?
You say you want to add VLAN layer but you also assume in the code that the original packet already has VLAN layer.

Mar 14, 2014 at 12:04 PM
Edited Mar 14, 2014 at 12:04 PM

the original packet is without Vlan (TCP, UDP) layer, any option to take Pcap file and add Vlan layer to all the packets ? (all the packet without Vlan layer of course..)
Mar 14, 2014 at 12:32 PM
If the original packet is without VLAN, then this line is wrong:

IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.VLanTaggedFrame.IpV4.ExtractLayer();

Also, you will need to reset the Ethernet layer's EtherType to VLAN, or to None (which will automatically choose VLAN) so it would work correctly.

I hope this helps,

Mar 14, 2014 at 12:41 PM
Edited Mar 14, 2014 at 12:42 PM
First extract Ethernet layer:
ILayer ethernet = packet.Ethernet.ExtractLayer();
What next ?
Mar 14, 2014 at 1:02 PM
Cast it to EthernetLayer and set EtherType to None.
Mar 14, 2014 at 1:14 PM
Edited Mar 14, 2014 at 1:30 PM
Ok it works fone now.
BTW, can i choose different VLAN ?
Mar 14, 2014 at 4:39 PM
What do you mean by a different VLAN?
Mar 14, 2014 at 5:19 PM
What does ClassOfService and VLanIdentifier mean ?
Mar 15, 2014 at 9:29 AM
From the documentation on these fields:

A VLAN-aware Bridge may not support the full range of VID values but shall support the use of all VID values in the range 0 through a maximum N,
less than or equal to 4094 and specified for that implementation.
PriorityCodePoint (of ClassOfService):
Indicates the frame priority level.
Values are from 0 (best effort) to 7 (highest); 1 represents the lowest priority.
These values can be used to prioritize different classes of traffic (voice, video, data, etc.).
Mar 16, 2014 at 4:26 PM
I think VLanIdentifier can be also 4095 (0 to 4095)
Mar 16, 2014 at 8:55 PM
From wikipedia:
VLAN identifier (VID): a 12-bit field specifying the VLAN to which the frame belongs. The hexadecimal values of 0x000 and 0xFFF are reserved. All other values may be used as VLAN identifiers, allowing up to 4,094 VLANs. The reserved value 0x000 indicates that the frame does not belong to any VLAN; in this case, the 802.1Q tag specifies only a priority and is referred to as a priority tag. On bridges, VLAN 1 (the default VLAN ID) is often reserved for a management VLAN; this is vendor-specific.
Mar 17, 2014 at 12:32 PM
Edited Mar 17, 2014 at 12:32 PM
Thanks !

BTW, if i want to implement (in myself) add PPPOE layer, this Encapsulation ontains also several fields (like VLanIdentifier, PriorityCodePoint ) or not ?
Mar 18, 2014 at 4:08 PM
I'm not that familiar with the details of PPPoE.