/// <summary>
        /// Pushes this frame to the output queue and adds the ethernet component of this frame according to the given destination address and interface properties.<br />
        /// If fFrame contains an Ethernet component, the Ethernet component is removed.
        /// </summary>
        /// <param name="fFrame">The frame to send. This frame must contain an IPv4 or IPv6 frame.</param>
        /// <param name="ipaDestination">The next hop's IP address of the given frame</param>
        public override void Send(Frame fFrame, IPAddress ipaDestination)
        {
            IPFrame ipFrame = GetIPFrame(fFrame);

            if (ipFrame == null)
            {
                throw new ArgumentException("Cannot send a non IP frame, because the ether-type cannot be guessed. Please use the Send(Frame, IPAddress, EtherType) method instead.");
            }

            foreach (IPFrame fFragment in IPFragmenter.Fragment(ipFrame, MTU))
            {
                if (ipFrame.Version == 4)
                {
                    Send(fFragment, ipaDestination, EtherType.IPv4);
                }
                else if (ipFrame.Version == 6)
                {
                    Send(fFragment, ipaDestination, EtherType.IPv6);
                }
                else
                {
                    throw new ArgumentException("The given IP frame has an invalid IP version specified.");
                }
            }
        }
示例#2
0
        /// <summary>
        /// Encapsulates the given IP frame according to the binding of this socket and invokes the FrameEncapsulated event when finished.
        /// <remarks>This method also handles IP fragmentation</remarks>
        /// </summary>
        /// <param name="fFrame">The frame to process</param>
        /// <param name="bPush">A bool indicating whether the frame is delivered with a push flag</param>
        public override void PushDown(Frame fFrame, bool bPush)
        {
            if (iIPVersion == 4)
            {
                IPv4Frame ipv4Frame = new IPv4Frame();

                ipv4Frame.DestinationAddress = RemoteBinding;
                ipv4Frame.SourceAddress      = LocalBinding;

                ipv4Frame.Protocol       = ProtocolBinding;
                ipv4Frame.Identification = (uint)rRandom.Next(Int32.MaxValue);

                ipv4Frame.EncapsulatedFrame = fFrame;

                foreach (IPFrame fFragment in IPFragmenter.FragmentV4(ipv4Frame, MaximumTransmissionUnit))
                {
                    InvokeFrameEncapsulated(fFragment, bPush);
                }
            }
            else if (iIPVersion == 6)
            {
                IPv6Frame ipv6Frame = new IPv6Frame();

                ipv6Frame.DestinationAddress = RemoteBinding;
                ipv6Frame.SourceAddress      = LocalBinding;

                ipv6Frame.Protocol = ProtocolBinding;

                ipv6Frame.EncapsulatedFrame = fFrame;

                foreach (IPFrame fFragment in IPFragmenter.FragmentV6(ipv6Frame, MaximumTransmissionUnit))
                {
                    InvokeFrameEncapsulated(fFragment, bPush);
                }
            }
            else
            {
                throw new ArgumentException("Only IPv4 and IPv6 addresses are supportet on the moment.");
            }
        }