protected override void OnPacketReceived(byte[] bytes, IPEndPoint receivedFrom) { var datagram = new DatagramPacket(bytes, bytes.Length, receivedFrom); var packet = new NfsPacket(datagram); var e = new UdpPacketReceivedEventArgs(packet, receivedFrom); //Console.WriteLine("\nPacket Received : EndPoint: " + _listener.Client.Client.LocalEndPoint.ToString()); uint xId = packet.XID = packet.GetUInt(); uint type = packet.GetUInt(); if (type == (int)RpcSignalType.Call) { Call(ref packet, xId); } else if (type == (int)RpcSignalType.Reply) { Reply(ref packet, xId); } //RaisePacketReceived(e); if (packet.ProgramID == this.ProgramID) { //Console.WriteLine("Found program: " + packet.ProgramID); Process(packet, receivedFrom); } }
private void Set(NfsPacket sourcePacket, IPEndPoint receivedFrom) { // skip past the authentication records sourcePacket.ReadAuthentication(); sourcePacket.ReadAuthentication(); // Collect the arguments to the procedure uint programId = sourcePacket.GetUInt(); uint version = sourcePacket.GetUInt(); uint protocol = sourcePacket.GetUInt(); uint port = sourcePacket.GetUInt(); NfsPacket packet = new NfsPacket(128); packet.AddReplyHeader(sourcePacket.XID); packet.SetUInt(PORTMAP_TRUE); // portmapMapping toadd = new portmapMapping(prog, vers, prot); // toadd.SetPort(port); // XDRPacket result = new XDRPacket(128); // result.AddReplyHeader(xid); // // look for the chain of versions for this program // long? pl = new long?(prog); // portmapMapping chain = (portmapMapping)mappings[pl]; // if (chain == null) { // mappings.Add(pl, toadd); // result.AddLong(Portmap.PM_TRUE); // } // else { // // See if this version is already registered in the chain // while (chain != null) { // if (chain.Version() == vers && chain.Protocol() == prot) { // result.AddLong(Portmap.PM_FALSE); // break; // } // else if (chain.Next() == null) { // chain.SetNext(toadd); // result.AddLong(Portmap.PM_TRUE); // break; // } // chain = chain.Next(); // } // } Send(packet, receivedFrom); }
protected virtual void Call(ref NfsPacket packet, uint xId) { uint rpcVersion = packet.RpcVersion = packet.GetUInt(); uint programId = packet.ProgramID = packet.GetUInt(); uint version = packet.NfsVersion = packet.GetUInt(); uint procedure = packet.ProcedureID = packet.GetUInt(); IPHostEntry entry = Dns.GetHostEntry(packet.Source); String[] parts = entry.HostName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length >= 0) { packet.RemoteHost = parts[0]; } //if (programId == this.ProgramID) { // Console.WriteLine("\nCall: rpcVersion = " + rpcVersion + " programId = " + programId + " version = " + version + " procedure = " + procedure); //} }
private void GetPort(NfsPacket sourcePacket, IPEndPoint receivedFrom) { // skip past the authentication records sourcePacket.ReadAuthentication(); sourcePacket.ReadAuthentication(); // Collect the arguments to the procedure uint programId = sourcePacket.GetUInt(); uint version = sourcePacket.GetUInt(); uint protocol = sourcePacket.GetUInt(); // Put together an XDR reply packet NfsPacket packet = new NfsPacket(128); packet.SetUInt(sourcePacket.XID); packet.SetUInt((uint)RpcSignalType.Reply); packet.SetUInt((uint)RpcMessageResult.Accepted); packet.AddNullAuthentication(); if (!NfsHandlerManager.IsProgramRegistered((int)programId)) { packet.SetUInt((uint)RpcProcedure.ProgramUnavailable); } else { // TODO: add version checking. we're only doing v2 right now. // version mismatch gets the ProgMismatch value. // result.AddLong(RPCConsts.RPCProgMismatch); // result.AddLong(versmin); // result.AddLong(versmax); int port = NfsHandlerManager.GetPort((int)programId); if (port == 0) { packet.SetUInt((uint)RpcProcedure.ProgramMismatch); } else { packet.SetUInt((uint)RpcProcedure.Success); packet.SetUInt((uint)port); } } Send(packet, receivedFrom); }
protected virtual void Call(ref NfsPacket packet, uint xId) { uint rpcVersion = packet.RpcVersion = packet.GetUInt(); uint programId = packet.ProgramID = packet.GetUInt(); uint version = packet.NfsVersion = packet.GetUInt(); uint procedure = packet.ProcedureID = packet.GetUInt(); IPHostEntry entry = Dns.GetHostEntry(packet.Source); String[] parts = entry.HostName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length >= 0) { packet.RemoteHost = parts[0]; } //if (programId == this.ProgramID) { // Console.WriteLine("\nCall: rpcVersion = " + rpcVersion + " programId = " + programId + " version = " + version + " procedure = " + procedure); //} }
protected override void OnPacketReceived(byte[] bytes, IPEndPoint receivedFrom) { var datagram = new DatagramPacket(bytes, bytes.Length, receivedFrom); var packet = new NfsPacket(datagram); var e = new UdpPacketReceivedEventArgs(packet, receivedFrom); //Console.WriteLine("\nPacket Received : EndPoint: " + _listener.Client.Client.LocalEndPoint.ToString()); uint xId = packet.XID = packet.GetUInt(); uint type = packet.GetUInt(); if (type == (int)RpcSignalType.Call) { Call(ref packet, xId); } else if (type == (int)RpcSignalType.Reply) { Reply(ref packet, xId); } //RaisePacketReceived(e); if (packet.ProgramID == this.ProgramID) { //Console.WriteLine("Found program: " + packet.ProgramID); Process(packet, receivedFrom); } }
internal virtual bool Read(NfsPacket packet) { _seconds = packet.GetUInt(); _milliseconds = packet.GetUInt(); return(true); }
private void GetPort(NfsPacket sourcePacket, IPEndPoint receivedFrom) { // skip past the authentication records sourcePacket.ReadAuthentication(); sourcePacket.ReadAuthentication(); // Collect the arguments to the procedure uint programId = sourcePacket.GetUInt(); uint version = sourcePacket.GetUInt(); uint protocol = sourcePacket.GetUInt(); // Put together an XDR reply packet NfsPacket packet = new NfsPacket(128); packet.SetUInt(sourcePacket.XID); packet.SetUInt((uint)RpcSignalType.Reply); packet.SetUInt((uint)RpcMessageResult.Accepted); packet.AddNullAuthentication(); if (!NfsHandlerManager.IsProgramRegistered((int)programId)) { packet.SetUInt((uint)RpcProcedure.ProgramUnavailable); } else { // TODO: add version checking. we're only doing v2 right now. // version mismatch gets the ProgMismatch value. // result.AddLong(RPCConsts.RPCProgMismatch); // result.AddLong(versmin); // result.AddLong(versmax); int port = NfsHandlerManager.GetPort((int)programId); if (port == 0) { packet.SetUInt((uint)RpcProcedure.ProgramMismatch); } else { packet.SetUInt((uint)RpcProcedure.Success); packet.SetUInt((uint)port); } } Send(packet, receivedFrom); }
private void Set(NfsPacket sourcePacket, IPEndPoint receivedFrom) { // skip past the authentication records sourcePacket.ReadAuthentication(); sourcePacket.ReadAuthentication(); // Collect the arguments to the procedure uint programId = sourcePacket.GetUInt(); uint version = sourcePacket.GetUInt(); uint protocol = sourcePacket.GetUInt(); uint port = sourcePacket.GetUInt(); NfsPacket packet = new NfsPacket(128); packet.AddReplyHeader(sourcePacket.XID); packet.SetUInt(PORTMAP_TRUE); // portmapMapping toadd = new portmapMapping(prog, vers, prot); // toadd.SetPort(port); // XDRPacket result = new XDRPacket(128); // result.AddReplyHeader(xid); // // look for the chain of versions for this program // long? pl = new long?(prog); // portmapMapping chain = (portmapMapping)mappings[pl]; // if (chain == null) { // mappings.Add(pl, toadd); // result.AddLong(Portmap.PM_TRUE); // } // else { // // See if this version is already registered in the chain // while (chain != null) { // if (chain.Version() == vers && chain.Protocol() == prot) { // result.AddLong(Portmap.PM_FALSE); // break; // } // else if (chain.Next() == null) { // chain.SetNext(toadd); // result.AddLong(Portmap.PM_TRUE); // break; // } // chain = chain.Next(); // } // } Send(packet, receivedFrom); }
internal virtual bool Read(NfsPacket packet) { _seconds = packet.GetUInt(); _milliseconds = packet.GetUInt(); return true; }