1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Implementation of the `GETPORT` procedure (procedure 3) for port mapper protocol
//! as defined in RFC 1057 A.2 section.
//! <https://datatracker.ietf.org/doc/rfc1057/>.
use ;
use crate;
use crateContext;
use crate;
/// Handles `PMAPPROC_GETPORT` procedure.
///
/// `GETPORT` maps an RPC program and version to a TCP/UDP port.
/// Takes a mapping request with program number, version, protocol and port.
/// Returns the port number where the requested service can be reached.
///
/// TODO: Function always returns the same host port and ignores the
/// requested version and protocol (always TCP). In the future, proper program
/// to port mapping should be implemented.
///
/// # Arguments
/// * `xid` - Transaction ID for RPC message correlation
/// * `read` - Input stream to read the lookup request from
/// * `output` - Output stream to write the response to
/// * `context` - Shared RPC context containing the portmap table (read-only)
///
/// # Returns
/// `Result<(), anyhow::Error>` indicating:
/// - `Ok(())` on successful operation
/// - `Err` if deserialization or serialization fails
///
/// # Behavior
/// 1. Deserializes the mapping request from input stream
/// 2. Creates a PortmapKey from the request parameters
/// 3. Looks up the port in the portmap table:
/// - Returns 0 if no mapping exists
/// - Returns the port number if mapping exists
/// 4. Sends RPC success reply with the result