コード例 #1
0
        public override void PushTraffic(Frame fInputFrame)
        {
            NATDescriptionFrame ndFrame = new NATDescriptionFrame(NATDescriptionFrame.NATFrameSource.Internal);

            ndFrame.EncapsulatedFrame = fInputFrame;
            base.PushTraffic(ndFrame);
        }
コード例 #2
0
        public void PushExternalTraffic(Frame fFrame)
        {
            NATDescriptionFrame ndFrame = new NATDescriptionFrame(NATDescriptionFrame.NATFrameSource.External);

            ndFrame.EncapsulatedFrame = fFrame;
            base.PushTraffic(ndFrame);
        }
コード例 #3
0
        /// <summary>
        /// Extracts a IP frame and does some NAT
        /// </summary>
        /// <param name="fInputFrame">The frame to handle</param>
        protected override void HandleTraffic(Frame fInputFrame)
        {
            int iSourcePort      = 0;
            int iDestinationPort = 0;

            if (fInputFrame.FrameType != NATDescriptionFrame.DefaultFrameType)
            {
                throw new Exception("A frame without a NATDescription was received by the NAT handler. This must not happen and indicates a serious internal error.");
            }

            NATDescriptionFrame ndDescription = (NATDescriptionFrame)fInputFrame;

            fInputFrame = ndDescription.EncapsulatedFrame;

            IP.IPFrame   ipFrame  = GetIPv4Frame(fInputFrame);
            TCP.TCPFrame tcpFrame = GetTCPFrame(fInputFrame);
            UDP.UDPFrame udpFrame = null;

            if (tcpFrame != null)
            {
                iSourcePort      = tcpFrame.SourcePort;
                iDestinationPort = tcpFrame.DestinationPort;
            }
            else
            {
                udpFrame = GetUDPFrame(fInputFrame);
                if (udpFrame != null)
                {
                    iSourcePort      = udpFrame.SourcePort;
                    iDestinationPort = udpFrame.DestinationPort;
                }
            }

            if (ipFrame != null)
            {
                if (ndDescription.Source == NATDescriptionFrame.NATFrameSource.Internal)
                {
                    //In to out
                    if (IsInternalRange(ipFrame.SourceAddress))
                    {
                        HandleFromInternal(fInputFrame, iSourcePort, iDestinationPort, ipFrame, tcpFrame, udpFrame);
                    }
                    else
                    {
                        NotifyNextExternal(fInputFrame);
                    }
                }
                else if (ndDescription.Source == NATDescriptionFrame.NATFrameSource.External)
                {
                    //Out to in
                    if (IsExternalRange(ipFrame.DestinationAddress))
                    {
                        HandleFromExternal(fInputFrame, iSourcePort, iDestinationPort, ipFrame, tcpFrame, udpFrame);
                    }
                    else
                    {
                        NotifyNextInternal(fInputFrame);
                    }
                }
            }
        }