/// <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)); }
public static XDR Create(PortmapMapping mapping, bool set) { XDR request = new XDR(); int procedure = set ? RpcProgramPortmap.PmapprocSet : RpcProgramPortmap.PmapprocUnset; RpcCall call = RpcCall.GetInstance(RpcUtil.GetNewXid(RpcProgramPortmap.Program.ToString ()), RpcProgramPortmap.Program, RpcProgramPortmap.Version, procedure, new CredentialsNone (), new VerifierNone()); call.Write(request); return(mapping.Serialize(request)); }
internal RpcProgramPortmap(ChannelGroup allChannels) { this.allChannels = allChannels; PortmapMapping m = new PortmapMapping(Program, Version, PortmapMapping.TransportTcp , RpcProgram.RpcbPort); PortmapMapping m1 = new PortmapMapping(Program, Version, PortmapMapping.TransportUdp , RpcProgram.RpcbPort); map[PortmapMapping.Key(m)] = m; map[PortmapMapping.Key(m1)] = m1; }
/// <summary> /// When a program becomes unavailable, it should unregister itself with the /// port mapper program on the same machine. /// </summary> /// <remarks> /// When a program becomes unavailable, it should unregister itself with the /// port mapper program on the same machine. The parameters and results have /// meanings identical to those of "PMAPPROC_SET". The protocol and port number /// fields of the argument are ignored. /// </remarks> private XDR Unset(int xid, XDR @in, XDR @out) { PortmapMapping mapping = PortmapRequest.Mapping(@in); string key = PortmapMapping.Key(mapping); if (Log.IsDebugEnabled()) { Log.Debug("Portmap remove key=" + key); } Collections.Remove(map, key); return(PortmapResponse.BooleanReply(@out, xid, true)); }
/// <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())); }
/// <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); }
public static PortmapMapping Mapping(XDR xdr) { return(PortmapMapping.Deserialize(xdr)); }