Exemple #1
0
        static public HostAddress LookupExternalHost(string lookupName)
        {
            Log.Write(LogType.Verbose, LogComponent.MiscServices, "Name lookup external for '{0}'", lookupName);

            IPHostEntry hostEntry = Dns.GetHostEntry(lookupName);

            try
            {
                hostEntry = Dns.GetHostEntry(lookupName);
                Log.Write(LogType.Verbose, LogComponent.MiscServices, "Got {0} hostEntry '{1}' {2} {3} {4}", lookupName, hostEntry, hostEntry.AddressList, hostEntry.AddressList.Length, hostEntry.AddressList[0]);
                IPAddress address = hostEntry.AddressList[0];
                Log.Write(LogType.Verbose, LogComponent.MiscServices, "Got address '{0}'", address);


                IFS.HostAddress ifsAddr = new IFS.HostAddress((byte)(hostCounter >> 8) /* network */, (byte)(hostCounter & 0xff) /* host */);
                hostCounter += 1;
                Log.Write(LogType.Verbose, LogComponent.MiscServices, "Recording {0} {1}", ifsAddr, address);
                _externalHosts[ifsAddr] = address;
                return(ifsAddr);
            }
            catch (Exception e)
            {
                Log.Write(LogType.Verbose, LogComponent.MiscServices, "Name lookup exception {0} {1}", lookupName, e);
                return(null);
            }
        }
        public void ReceivePUP(PUP pup)
        {
            //
            // Filter out packets not destined for us.
            // Even though we use pcap in non-promiscuous mode, if
            // something else has set the interface to promiscuous mode, that
            // setting may be overridden.
            //
            Log.Write(LogType.Verbose, LogComponent.PUP, "PUP received.");

            IFS.HostAddress targetAddress = new IFS.HostAddress(DirectoryServices.Instance.LocalNetwork, pup.DestinationPort.Host);
            if (pup.DestinationPort.Host != 0 &&                                           // Not broadcast.
                pup.DestinationPort.Host != DirectoryServices.Instance.LocalHost &&        // Not our address.
                !ExternalHost.AcceptAddress(targetAddress))
            {
                // Do nothing with this PUP.
                Log.Write(LogType.Verbose, LogComponent.PUP, "PUP {0} is neither broadcast nor for us.  Discarding.", targetAddress);
                return;
            }

            //
            // Forward PUP on to registered endpoints.
            //
            if (_dispatchMap.ContainsKey(pup.DestinationPort.Socket))
            {
                PUPProtocolEntry entry = _dispatchMap[pup.DestinationPort.Socket];

                if (entry.ConnectionType == ConnectionType.Connectionless)
                {
                    Log.Write(LogType.Verbose, LogComponent.PUP, "Dispatching PUP (source {0}, dest {1}) to {2} handler.", pup.SourcePort, pup.DestinationPort, entry.FriendlyName);
                    // Connectionless; just pass the PUP directly to the protocol
                    entry.ProtocolImplementation.RecvData(pup);
                }
                else
                {
                    // RTP / BSP protocol.  Pass this to the BSP handler to set up a channel.
                    Log.Write(LogType.Verbose, LogComponent.PUP, "Dispatching PUP (source {0}, dest {1}) to BSP protocol for {0}.", pup.SourcePort, pup.DestinationPort, entry.FriendlyName);
                    BSPManager.EstablishRendezvous(pup, entry.WorkerType);
                }
            }
            else if (ExternalHost.AcceptAddress(new HostAddress(pup.DestinationPort)))
            {
                // RTP / BSP protocol.  Pass this to the BSP handler to set up a channel.
                Log.Write(LogType.Verbose, LogComponent.PUP, "Remote host: Dispatching PUP (source {0}, dest X) to BSP protocol for {0}.", pup.SourcePort, pup.DestinationPort);
                BSPManager.EstablishRendezvous(pup, typeof(ExternalHostWorker));
            }
            else if (BSPManager.ChannelExistsForSocket(pup))
            {
                // An established BSP channel, send data to it.
                Log.Write(LogType.Normal, LogComponent.PUP, "BSP PUP");

                BSPManager.RecvData(pup);
            }
            else if (EFTPManager.ChannelExistsForSocket(pup))
            {
                Log.Write(LogType.Normal, LogComponent.PUP, "EFTP PUP");

                EFTPManager.RecvData(pup);
            }
            else
            {
                // Not a protocol we handle; log it.
                Log.Write(LogType.Normal, LogComponent.PUP, "Unhandled PUP protocol, source  {0}, destination  {1}, type {2}, dropped packet.", pup.SourcePort, pup.DestinationPort, pup.Type);
            }
        }