コード例 #1
0
ファイル: Form1.cs プロジェクト: ArcLoyalty/PacketSniffer
 private string[] MakeUDP(UDPHeader udpHeader)
 {
     string[] UDPNode = new string[] { "UDP", "Source Port: " + udpHeader.SourcePort,
                                       "Destination Port: " + udpHeader.DestinationPort,
                                       "Length: " + udpHeader.Length,
                                       "Checksum: " + udpHeader.Checksum };
     return(UDPNode);
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ArcLoyalty/PacketSniffer
        private void ParseData(byte[] byteData, int nReceived)
        {
            if (PacketNum == Convert.ToInt32(this.tscbNum.Text))
            {
                PacketNum = 1;
                this.lvReceivedPackets.Items.Clear();
            }
            IPHeader ipHeader = new IPHeader(byteData, nReceived);

            string[] lvStrArr = new string[] { PacketNum.ToString(), DateTime.Now.ToString(),
                     ipHeader.SourceAddress.ToString(), ipHeader.DestinationAddress.ToString(),
                     ipHeader.ProtocolType.ToString(), ipHeader.TotalLength };

            string[] IpStrArr = MakeIP(ipHeader, ipHeader.ProtocolType.ToString());

            string[] MergeIPArr = new string[lvStrArr.Length + IpStrArr.Length];
            Array.Copy(lvStrArr, 0, MergeIPArr, 0, lvStrArr.Length);
            Array.Copy(IpStrArr, 0, MergeIPArr, lvStrArr.Length, IpStrArr.Length);

            string[] MergeTCP = null;
            string[] MergeUDP = null;
            string[] MergeAll = null;

            switch (ipHeader.ProtocolType) // fixed
            {
            case Protocol.TCP:
                TCPHeader tcpHeader = new TCPHeader(ipHeader.Data,
                                                    ipHeader.MessageLength);
                MergeTCP = MakeTCP(tcpHeader);
                MergeAll = new string[MergeIPArr.Length + MergeTCP.Length];
                Array.Copy(MergeIPArr, 0, MergeAll, 0, MergeIPArr.Length);
                Array.Copy(MergeTCP, 0, MergeAll, MergeIPArr.Length, MergeTCP.Length);
                break;

            case Protocol.UDP:
                UDPHeader udpHeader = new UDPHeader(ipHeader.Data,
                                                    (int)ipHeader.MessageLength);
                MergeUDP = MakeUDP(udpHeader);
                MergeAll = new string[MergeIPArr.Length + MergeUDP.Length];
                Array.Copy(MergeIPArr, 0, MergeAll, 0, MergeIPArr.Length);
                Array.Copy(MergeUDP, 0, MergeAll, MergeIPArr.Length, MergeUDP.Length);
                break;

            case Protocol.ICMP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.IGMP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.IGRP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.AH:
                MergeAll = MergeIPArr;
                break;

            case Protocol.EIGRP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.ESP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.GRE:
                MergeAll = MergeIPArr;
                break;

            case Protocol.L2TP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.OSPF:
                MergeAll = MergeIPArr;
                break;

            case Protocol.SKIP:
                MergeAll = MergeIPArr;
                break;

            case Protocol.Unknown:
                MergeAll = MergeIPArr;
                break;
            }
            var lvt = new ListViewItem(MergeAll);

            this.lvReceivedPackets.Items.Add(lvt);
            PacketNum++;
        }