Chapter 58. Connecting to applications

#include <x/fd.H>
#include <x/httportmap.H>
#include <unistd.H>

x::httportmap portmapper(x::httportmap::create());

x::fd socket=portmapper->connect("test.example.com", getuid());

This example creates a socket connection to an application socket named test.example.com running under the same userid. If there are more than one sockets registered under the same name and userid (if this application name is not exclusive), a connection gets established to one of them, at random.

x::fd socket=portmapper->connect_root("test.example.com");

connect_root() passes 0 for the userid parameter to connect(). Userid 0 is root, and this example expects a root process on the same server to have registered this application label, which is connected to.

x::fd socket=portmapper->connect_any("test.example.com");

connect_any() connects to an application socket created by a process with any userid.

Note

Applications are responsible for implementing their own appropriate security. Any application can connect to any port, and the portmapper service will not prevent applications from connecting to application services running as a different userid.

#include <x/fd.H>
#include <x/httportmap.H>
#include <unistd.H>

x::httportmap portmapper(x::httportmap::create("www.domain.com"));

x::fd socket=portmapper->connect("test.example.com", 0);

This example creates a connection to a portmapper running on a different server, www.domain.com, and connects to an instance of test.example.com running on that server as root, instead of the same server as this application.