使用PcapDotNet添加VLAN层

时间:2014-03-12 06:19:30

标签: c# .net packet

我有Pcap file我尝试添加VLAN层,因此我使用的是PcapDotNet DLLs,例如this示例:

private Packet AddVlan(Packet packet)
{
    try
    {
        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;
    }
}

我的问题是Packet看起来缺少多个图层:

enter image description here

任何想法如何解决它?

1 个答案:

答案 0 :(得分:0)

我认为这是因为您提取的EthernetLayer将IPv4作为EtherType。如果您希望在构建数据包时自动计算它,则应将其更改为“无”。

EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
ethernet.EtherType = EthernetType.None;