function::tcpmib_local_port - Linux
Overview
function::tcpmib_local_port displays the local TCP port corresponding to the IP address and service port.
Syntax
function tcpmib_local_port(const Net::IP& ip, uint16_t service_port)
Options/Flags
None.
Examples
namespace nc = ::google::cloud::networkconnectivity;
[](nc::Policy policy) {
auto network = policy.network();
::google::cloud::optional<::google::cloud::networkconnectivity::TcpRoute>
tcp_route = policy.GetTcpRoute();
if (tcp_route) {
std::cout << "TCP route:\n Remote IP:" << tcp_route->remote_ip()
<< "\n Local port:"
<< nc::tcpmib_local_port(tcp_route->remote_ip(),
tcp_route->remote_port())
<< "\n Service port:" << tcp_route->remote_port() << "\n\n";
}
// ...
}
Common Issues
Check that you have set the network
field in the policy.
Integration
The tcpmib_local_port
function can be used in conjunction with other Network Connectivity library functions to obtain information about TCP routes. Consider using it with the GetTcpRoute()
member function of google::cloud::networkconnectivity::Policy
class to retrieve the TCP route for a given policy.