创建新的gopacket图层

时间:2019-01-10 19:41:19

标签: go interface type-assertion gopacket

我想用Dot1Q层标记我的以太网数据包。我想将其插入EthernetLayer和IPv4Layer / ARP等之间。这是我尝试的代码,但我不知道出了什么问题:

sls := []gopacket.SerializableLayer{}
for _, layer := range packet.Layers() {
    sl, ok := layer.(gopacket.SerializableLayer)
    if !ok {
        log.Printf("layer %s is not serializable", layer.LayerType().String())
    }
    sls = append(sls, sl)
    if !tagged && layer.LayerType() == layers.LayerTypeEthernet {
        vlan := &layers.Dot1Q{
            VLANIdentifier: vid,
            Type: layers.EthernetTypeDot1Q,
        }
        sls = append(sls, vlan.(gopacket.SerializableLayer))
    }
}

我收到以下错误:

invalid type assertion: vlan.(gopacket.SerializableLayer) (non-interface type *layers.Dot1Q on left)

0 个答案:

没有答案