---
name: "socket_wrapper"
section: "1"
platform: "linux"
package: "libsocket-wrapper"
version: "1.4.4-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/socket_wrapper"
---

# socket\_wrapper(1)

A library passing all socket communications through unix sockets.

## NAME

socket\_wrapper - 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.

• Redirects all network communication to happen over Unix sockets.

• Support for IPv4 and IPv6 socket and addressing emulation.

• Ability to capture network traffic in pcap format.

• Passing IP sockets (up to 6) via SCM\_RIGHTS is supported, but pcap support only works reliable if the socket is used by a single process at a time.

## 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 the "127.0.0.x" 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. But note within "10.0.0.0/8" only "10.53.57.\<ID\>" can be used, but the broadcast address is "10.255.255.255". The following two value 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 recomment to do that as the default size of 1500 byte 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 if you built it with debug symbols.

• 0 = ERROR

• 1 = WARNING

• 2 = DEBUG

• 3 = TRACE

**SOCKET\_WRAPPER\_DISABLE\_DEEPBIND**

This allows you to disable deep binding in socket\_wrapper. This is useful for running valgrind tools or sanitizers like (address, undefined, thread).

**SOCKET\_WRAPPER\_DIR\_ALLOW\_ORIG**

SOCKET\_WRAPPER\_DIR is resolved by socket\_wrapper using [realpath(3)](/realpath/3.md). Given that Unix sockets are constructed relative to this directory, the resulting path can sometimes be too long to allow valid socket paths to be constructed due to length restrictions.  Setting this variable (to any value) allows socket\_wrapper to fall back to the original value of SOCKET\_WRAPPER\_DIR if [realpath(3)](/realpath/3.md) makes it too long to be usable.

## 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 link use these functions.

By default it’s 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);

• This returns true when socket wrapper is actively in use.

void socket\_wrapper\_indicate\_no\_inet\_fd(int fd);

• This allows socket\_wrapper aware applications to indicate that the given fd does not belong to an inet socket.

• socket\_wrapper may not be able to intercept the \_\_close\_nocancel() syscall made from within libc.so. As result it’s possible that the in memory meta date of socket\_wrapper references stale file descriptors, which are already reused for unrelated kernel objects, e.g. files, directories, ...

• Socket wrapper already intercepts a lot of unrelated functions like eventfd(), timerfd\_create(), ... in order to remove stale meta data for the returned fd, but it will never be able to handle all possible syscalls.

• socket\_wrapper\_indicate\_no\_inet\_fd() gives applications a way to do the same, explicitly without waiting for new syscalls to be added to libsocket\_wrapper.so.

• This is a no-op if socket\_wrapper is not in use or if the there is no in memory meta data for the given fd.

## RESOURCES

**Project web site:**  \<https://cwrap.org\>

## AUTHOR

Samba Team
