DOKK / manpages / debian 11 / libvdeslirp0 / vdeslirp_add_fwd.3.en
LIBVDESLIRPFWD(3) Library Functions Manual LIBVDESLIRPFWD(3)

vdeslirp_add_fwd, vdeslirp_remove_fwd, vdeslirp_add_unixfwd, vdeslirp_remove_unixfwd, vdeslirp_add_cmdexec - simple API for slirp, port forwarding

#include <libvdeslirp.h>

int vdeslirp_add_fwd(struct vdeslirp *slirp, int is_udp, struct in_addr host_addr, int host_port, struct in_addr guest_addr, int guest_port);

int vdeslirp_remove_fwd(struct vdeslirp *slirp, int is_udp, struct in_addr host_addr, int host_port);

int vdeslirp_add_unixfwd(struct vdeslirp *slirp, char *path, struct in_addr guest_addr, int guest_port);

int vdeslirp_remove_unixfwd(struct vdeslirp *slirp, struct in_addr guest_addr, int guest_port);

int vdeslirp_add_cmdexec(struct vdeslirp *slirp, const char *cmdline, struct in_addr *guest_addr, int guest_port);

int vdeslirp_remove_cmdexec(struct vdeslirp *slirp, struct in_addr guest_addr, int guest_port);

Slirp, see libvdelirp(3), is a TCP/IP emulator. Slirp generates a virtual network using standard user privileges (no need for root access of CAP_NET_ADMIN). These functions manage port forwarding services.

vdeslirp_add_fwd and vdeslirp_remove_fwd respectively add and remove udp or tcp port forwarding services (depending upon the value of is_udp). host_addr and host_port are the IP address and port number bound for the service in the host system. All the connections or datagrams to host_addr and host_port will be diverted to guest_addr and guest_port in the slirp virtual network.

vdeslirp_add_unixfwd and vdeslirp_remove_unixfwd respectively add and remove a forwarding service towards a PF_UNIX stream socket on the hosting system. All the connections from a node of the virtual network to guest_addr and guest_port will be diverted to the PF_UNIX bound to the pathname path. This feature is commonly used to run X-window clients in the virtual network (e.g. the value of path could be /tmp/.X11-unix/X0).

If libslirp does not support slirp_add_unix, vdeslirp_add_unixfwd is implemented by a workaround based on nc(1).

vdeslirp_cmd_fwd adds a forwarding service to a command. A TCP connection to guest_addr and guest_port activates the command cmdline. Data exchanged on the TCP connection is forwarded as stdin/stdout to the command.

vdeslirp_remove_cmdexec removes a command forwarding service.

All these functions return 0 in case of success, -1 otherwise (and errno is set consequently). vdeslirp_remove_cmdexec and vdeslirp_remove_unixfwd return -1 and set errno to ENOSYS if libslirp does not support slirp_remove_guestfwd.

libvdeslirp(3), libvdeslirpcfg(3)

Bug reports should be addressed to <info@virtualsquare.org>

VirtualSquare. Project leader: Renzo Davoli.

January 2020 VirtualSquare