public void SetComboBoxSelectedIndex(IPProtocol.IPProtocolType ipProtocolType)
 {
     for (int i = 0; i < comboBoxIPProtocols.Items.Count; i++)
     {
         object item = comboBoxIPProtocols.Items[i];
         if ((IPProtocol.IPProtocolType)((DictionaryEntry)item).Key == ipProtocolType)
         {
             comboBoxIPProtocols.SelectedIndex = i;
             break;
         }
     }
 }
Ejemplo n.º 2
0
        public IPPacket(IPVersions ipVersion,
                        IPProtocol.IPProtocolType ipProtocolType,
                        IPAddress sourceAddress,
                        IPAddress destinationAddress,
                        EthernetPacket ethernetPacket,
                        byte[] ipPacketPayload)
            : base(EthernetFields_Fields.ETH_HEADER_LEN, null)
        {
            // determine how many bytes we need for this packet
            int ipHeaderLength  = ((ipVersion == IPVersions.IPv4) ? IPv4Fields_Fields.IP_HEADER_LEN : IPv6Fields_Fields.IPv6_HEADER_LEN);
            int ipPayloadLength = (ipPacketPayload != null) ? ipPacketPayload.Length : 0;

            int totalBytesRequired = 0;

            totalBytesRequired += EthernetFields_Fields.ETH_HEADER_LEN;
            totalBytesRequired += ipHeaderLength;
            totalBytesRequired += ipPayloadLength;

            // copy the ethernet packet header into the byte array
            byte[] bytes = new Byte[totalBytesRequired];
            Array.Copy(ethernetPacket.EthernetHeader, bytes, ethernetPacket.EthernetHeader.Length);

            // set the packet bytes to our new, correct length
            // buffer
            //
            // NOTE: we cannot say: Bytes = bytes; because
            //       the Bytes set property results in a call to
            //       InitIPPacket with a parameter of IPVersion which
            //       would result in the version being retrieved from
            //       an offset into the byte array but we haven't
            //       set the version in the byte array yet by setting
            //       this.IPVersion to a value
            base.Bytes = bytes;

            // call InitIPPacket to instantiate a packet of the proper type
            InitIPPacket(ipVersion);

            // set the header length to the default value for our ip version
            IPHeaderLength = ipHeaderLength;

            // set the EthernetPacket type to the proper ip version
            base.EthernetProtocol = (ipVersion == IPVersions.IPv4) ? EthernetPacketType.IPv4 : EthernetPacketType.IPv6;

            // set the ip protocol type
            this.IPProtocol = ipProtocolType;

            // set the current instance to the proper ip version
            this.IPVersion = ipVersion;

            // update the source and destination addresses
            this.SourceAddress      = sourceAddress;
            this.DestinationAddress = destinationAddress;

            // and set the payload to the payload that was passed in
            if (ipPacketPayload != null)
            {
                Array.Copy(ipPacketPayload, 0, Bytes, _ipPayloadOffset, ipPacketPayload.Length);
                IPPayloadLength = ipPacketPayload.Length;
            }
            else
            {
                IPPayloadLength = 0;
            }
        }