//string request = "GET /\r\n"; //Byte[] bytesSent = Encoding.ASCII.GetBytes(request); //Byte[] bytesReceived = new Byte[1000]; //s.Send(bytesSent, bytesSent.Length, 0); //int bytes = 0; //bytes = s.Receive(bytesReceived, bytesReceived.Length, 0); //string data = Encoding.ASCII.GetString(bytesReceived, 0, bytes); //Log.Write(LogType.Verbose, LogComponent.Exp, "Received {0}", data); private void SendNameLookupReply(PUP p) { // // For the request PUP: // A string consisting of an inter-network name expression. // NOTE: This is *not* a BCPL string, just the raw characters. // // Response: // One or more 6-byte blocks containing the address(es) corresponding to the // name expression. Each block is a Pup Port structure, with the network and host numbers in // the first two bytes and the socket number in the last four bytes. // // // For now, the assumption is that each name maps to at most one address. // string lookupName = Helpers.ArrayToString(p.Contents); Log.Write(LogType.Verbose, LogComponent.MiscServices, "Name lookup is for '{0}'", lookupName); HostAddress address = DirectoryServices.Instance.NameLookup(lookupName); if (address == null) { address = ExternalHost.LookupExternalHost(lookupName); } if (address != null) { // We found an address, pack the port into the response. PUPPort lookupPort = new PUPPort(address, 0); PUPPort localPort = new PUPPort(DirectoryServices.Instance.LocalHostAddress, p.DestinationPort.Socket); PUP lookupReply = new PUP(PupType.NameLookupResponse, p.ID, p.SourcePort, localPort, lookupPort.ToArray()); Router.Instance.SendPup(lookupReply); Log.Write(LogType.Verbose, LogComponent.MiscServices, "Address is '{0}'", address); } else { // Unknown host, send an error reply string errorString = "Unknown host."; PUPPort localPort = new PUPPort(DirectoryServices.Instance.LocalHostAddress, p.DestinationPort.Socket); PUP errorReply = new PUP(PupType.DirectoryLookupErrorReply, p.ID, p.SourcePort, localPort, Helpers.StringToArray(errorString)); Router.Instance.SendPup(errorReply); Log.Write(LogType.Verbose, LogComponent.MiscServices, "Host is unknown."); } }
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); } }