Exemple #1
0
        /// <summary>
        /// Given a program number "prog", version number "vers", and transport
        /// protocol number "prot", this procedure returns the port number on which the
        /// program is awaiting call requests.
        /// </summary>
        /// <remarks>
        /// Given a program number "prog", version number "vers", and transport
        /// protocol number "prot", this procedure returns the port number on which the
        /// program is awaiting call requests. A port value of zeros means the program
        /// has not been registered. The "port" field of the argument is ignored.
        /// </remarks>
        private XDR Getport(int xid, XDR @in, XDR @out)
        {
            PortmapMapping mapping = PortmapRequest.Mapping(@in);
            string         key     = PortmapMapping.Key(mapping);

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Portmap GETPORT key=" + key + " " + mapping);
            }
            PortmapMapping value = map[key];
            int            res   = 0;

            if (value != null)
            {
                res = value.GetPort();
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Found mapping for key: " + key + " port:" + res);
                }
            }
            else
            {
                Log.Warn("Warning, no mapping for key: " + key);
            }
            return(PortmapResponse.IntReply(@out, xid, res));
        }
Exemple #2
0
        /// <summary>
        /// When a program first becomes available on a machine, it registers itself
        /// with the port mapper program on the same machine.
        /// </summary>
        /// <remarks>
        /// When a program first becomes available on a machine, it registers itself
        /// with the port mapper program on the same machine. The program passes its
        /// program number "prog", version number "vers", transport protocol number
        /// "prot", and the port "port" on which it awaits service request. The
        /// procedure returns a boolean reply whose value is "TRUE" if the procedure
        /// successfully established the mapping and "FALSE" otherwise. The procedure
        /// refuses to establish a mapping if one already exists for the tuple
        /// "(prog, vers, prot)".
        /// </remarks>
        private XDR Set(int xid, XDR @in, XDR @out)
        {
            PortmapMapping mapping = PortmapRequest.Mapping(@in);
            string         key     = PortmapMapping.Key(mapping);

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Portmap set key=" + key);
            }
            map[key] = mapping;
            return(PortmapResponse.IntReply(@out, xid, mapping.GetPort()));
        }
Exemple #3
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestRegistration()
        {
            XDR req = new XDR();

            RpcCall.GetInstance(++xid, RpcProgramPortmap.Program, RpcProgramPortmap.Version,
                                RpcProgramPortmap.PmapprocSet, new CredentialsNone(), new VerifierNone()).Write(
                req);
            PortmapMapping sent = new PortmapMapping(90000, 1, PortmapMapping.TransportTcp, 1234
                                                     );

            sent.Serialize(req);
            byte[]         reqBuf = req.GetBytes();
            DatagramSocket s      = new DatagramSocket();
            DatagramPacket p      = new DatagramPacket(reqBuf, reqBuf.Length, pm.GetUdpServerLoAddress
                                                           ());

            try
            {
                s.Send(p);
            }
            finally
            {
                s.Close();
            }
            // Give the server a chance to process the request
            Thread.Sleep(100);
            bool found = false;
            IDictionary <string, PortmapMapping> map = (IDictionary <string, PortmapMapping>)Whitebox
                                                       .GetInternalState(pm.GetHandler(), "map");

            foreach (PortmapMapping m in map.Values)
            {
                if (m.GetPort() == sent.GetPort() && PortmapMapping.Key(m).Equals(PortmapMapping.
                                                                                  Key(sent)))
                {
                    found = true;
                    break;
                }
            }
            Assert.True("Registration failed", found);
        }