2016-04-14 49 views
0

我按照這個教程PcapDotNet/Pcap.Net。但我會盡力建立一個像這樣的圖片Ethernet frame如何構建一個沒有任何protocole Pcap.net c#的以太網數據包?

private static Packet BuildEthernetPacket() 
    { 
     EthernetLayer ethernetLayer = 
      new EthernetLayer 
      { 
       Destination = new MacAddress("00:00:00:00:00:00"), 
       Source = new MacAddress("11:11:11:11:11:11"), 
       EtherType = EthernetType.None, // I select NONE for no IPV4 or ARP and so one protocole ... 
      }; 

     PayloadLayer payloadLayer = 
      new PayloadLayer 
      { 
       Data = new Datagram(Encoding.ASCII.GetBytes("Hello stackoverflow")), 
      }; 
     // The probleme it's here but the code build : 
     PacketBuilder builder = new PacketBuilder(ethernetLayer, payloadLayer); 
     return builder.Build(DateTime.Now); 
    } 

Visual Studio中社區檢測錯誤在PcapDotNet.Packets.dll
但是,如果我改變&「System.ArgumentException」「無法從下一層(PcapDotNet.Packets.PayloadLayer)自動確定醚型」 EthernetType.None由EthernetType.IpV4或IpV6或ARP等等..沒有問題,但我不想添加其他協議。

在此先感謝。

回答

0

EtherType不能在數據包中爲無。 您應該將其設置爲某個值。 當它設置爲無(或未設置)時,Pcap.Net會嘗試使用下一層自動計算它。 但是,代碼中的下一層是PayloadLayer,它不提供有關EtherType的信息。

基本上,以太網類型應該說如何解析以太網負載。如果你把一些有效載荷,應該有一種方法來解析它。

相關問題