static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); byte[] datagram = new byte[277777]; for (int i = 0; i < datagram.Length; i++) { datagram[i] = 1; } ICollection <UdpPacket> packets = UdpPacketSplitter.Split(1024, datagram, 65535); foreach (var packet in packets) { Console.WriteLine(packet.ToString()); } foreach (var packet in packets) { byte[] data = packet.ToArray(); UdpPacket convert = UdpPacket.FromArray(data); Console.WriteLine(convert.ToString()); } Console.ReadKey(); }
private static UdpPacket ExtractUdpPacket(IpPacket ip_packet) { UdpPacket udp_packet = (UdpPacket)ip_packet.Extract(typeof(UdpPacket)); Debug.WriteLineIf(udp_packet != null, "UDP packet: " + udp_packet.ToString()); return(udp_packet); }
private void lbxCapturedPacketList_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { gbxPacketInfo.Visibility = Visibility.Visible; Packet packet = lbxCapturedPacketList.SelectedItem as Packet; Console.WriteLine(packet.GetType()); TcpPacket tcp = (TcpPacket)packet.Extract(typeof(TcpPacket)); IpPacket ip = (IpPacket)packet.Extract(typeof(IpPacket)); EthernetPacket ethernet = (EthernetPacket)packet.Extract(typeof(EthernetPacket)); UdpPacket udp = (UdpPacket)packet.Extract(typeof(UdpPacket)); ICMPv4Packet icmpv4 = (ICMPv4Packet)packet.Extract(typeof(ICMPv4Packet)); ICMPv6Packet icmpv6 = (ICMPv6Packet)packet.Extract(typeof(ICMPv6Packet)); ICMPv6Packet igmp = (ICMPv6Packet)packet.Extract(typeof(ICMPv6Packet)); PPPoEPacket PPPoE = (PPPoEPacket)packet.Extract(typeof(PPPoEPacket)); PPPPacket pppp = (PPPPacket)packet.Extract(typeof(PPPPacket)); LLDPPacket LLDP = (LLDPPacket)packet.Extract(typeof(LLDPPacket)); WakeOnLanPacket WOL = (WakeOnLanPacket)packet.Extract(typeof(WakeOnLanPacket)); if (tcp != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = tcp.ToString(StringOutputType.Verbose); })); } if (ip != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = ip.ToString(StringOutputType.Verbose); })); } if (ethernet != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = ethernet.ToString(StringOutputType.Verbose); })); } if (udp != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = udp.ToString(StringOutputType.Verbose); })); } if (icmpv4 != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = icmpv4.ToString(StringOutputType.Verbose); })); } if (icmpv6 != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = icmpv6.ToString(StringOutputType.Verbose); })); } if (igmp != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = igmp.ToString(StringOutputType.Verbose); })); } if (PPPoE != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = PPPoE.ToString(StringOutputType.Verbose); })); } if (pppp != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = pppp.ToString(StringOutputType.Verbose); })); } if (LLDP != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = LLDP.ToString(StringOutputType.Verbose); })); } if (WOL != null) { this.Dispatcher.Invoke((Action)(() => { tbxInfo.Text = WOL.ToString(StringOutputType.Verbose); })); } } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); } }