socket_wrapper - Man Page

A library passing all socket communications through unix sockets.

Synopsis

LD_PRELOAD=libsocket_wrapper.so SOCKET_WRAPPER_DIR=/tmp/tmp.bQRELqDrhM SOCKET_WRAPPER_DEFAULT_IFACE=10 ./myapplication

Description

socket_wrapper aims to help client/server software development teams willing to gain full functional test coverage. It makes possible to run several instances of the full software stack on the same machine and perform locally functional testing of complex network configurations.

Environment Variables

SOCKET_WRAPPER_DIR

The user defines a directory where to put all the unix sockets using the environment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir". When a server opens a port or a client wants to connect, socket_wrapper will translate IP addresses to a special socket_wrapper name and look for the relevant Unix socket in the SOCKET_WRAPPER_DIR.

SOCKET_WRAPPER_IPV4_NETWORK

By default the loopback IPv4 network "127.0.0.0/8" and "127.0.0.x" addresses can be used. In order to make more realistic testing possible it is possible to use the "10.0.0.0/8" IPv4 network instead. Note that within "10.0.0.0/8" only "10.53.57.<ID>" can be used, and the broadcast address is "10.255.255.255". The following two values are allowed: SOCKET_WRAPPER_IPV4_NETWORK="127.0.0.0" (the default) and SOCKET_WRAPPER_IPV4_NETWORK="10.53.57.0".

SOCKET_WRAPPER_DEFAULT_IFACE

Additionally, the default interface to be used by an application is defined with "SOCKET_WRAPPER_DEFAULT_IFACE=<ID>" where the valid range for <ID> starts with 1 (the default) and ends with 64. This is analogous to use the IPv4 addresses "127.0.0.<ID>"/"10.53.57.<ID>" or IPv6 addresses "fd00::5357:5f<IDx>" (where <IDx> is a hexadecimal presentation of <ID>). You should always set the default interface. If you listen on INADDR_ANY then it will use the default interface to listen on.

SOCKET_WRAPPER_PCAP_FILE

When debugging, it is often interesting to investigate the network traffic between the client and server within your application. If you define SOCKET_WRAPPER_PCAP_FILE=/path/to/file.pcap, socket_wrapper will dump all your network traffic to the specified file. After the test has been finished you’re able to open the file for example with Wireshark.

SOCKET_WRAPPER_MTU

With this variable you can change the MTU size. However we do not recommend doing that as the default size of 1500 bytes is best for formatting PCAP files.

The minimum value you can set is 512 and the maximum 32768.

SOCKET_WRAPPER_MAX_SOCKETS

This variable can be used to set the maximum number of sockets to be used by an application.

The default value is set to 65535 and the maximum 256000.

SOCKET_WRAPPER_DEBUGLEVEL

If you need to see what is going on in socket_wrapper itself or try to find a bug, you can enable logging support in socket_wrapper.

The debug level can be set using either numeric values or string values (case-insensitive):

Example

# Open a console and create a directory for the unix sockets.
$ mktemp -d
/tmp/tmp.bQRELqDrhM
# Then start nc to listen for network traffic using the temporary directory.
$ LD_PRELOAD=libsocket_wrapper.so \
  SOCKET_WRAPPER_DIR=/tmp/tmp.bQRELqDrhM \
  SOCKET_WRAPPER_DEFAULT_IFACE=10 nc -v -l 127.0.0.10 7
# (If nc, listens on 0.0.0.0 then listener will be open on 127.0.0.10 because
#  it is the default interface)
# Now open another console and start 'nc' as a client to connect to the server:
$ LD_PRELOAD=libsocket_wrapper.so \
  SOCKET_WRAPPER_DIR=/tmp/tmp.bQRELqDrhM \
  SOCKET_WRAPPER_DEFAULT_IFACE=100 nc -v 127.0.0.10 7
# (The client will use the address 127.0.0.100 when connecting to the server)
# Now you can type 'Hello!' which will be sent to the server and should appear
# in the console output of the server.

Public Functions

Socket wrapper advanced helpers.

Applications with the need to alter their behaviour when socket wrapper is active can use these functions.

By default it’s not required for applications to use any of these functions as libsocket_wrapper.so is injected at runtime via LD_PRELOAD.

Applications using these functions should link against libsocket_wrapper_noop.so by using -lsocket_wrapper_noop, or implement their own noop stubs.

#include <socket_wrapper.h>

bool socket_wrapper_enabled(void);

void socket_wrapper_indicate_no_inet_fd(int fd);

Resources

Project web site: https://cwrap.org

Author

Samba Team

Info

2025-12-08