18

For Local Communication, Prefer AF_UNIX

Don’t do TCP/UDP on localhost, instead use AF_UNIX.

#SecureCoding #C/C++

When applications need to communicate with custom system services, some choose to simply talk via TCP or UDP sockets within the same computer.

Instead, prefer using the Unix sockets via the AF_UNIX protocol. Unix sockets come in packet and stream variants that work just like the network counterparts, but they live on the filesystem. Who is allowed to connect to the socket can be controlled with standard filesystem permissions.

Unix sockets can also pass file descriptors. A privileged service can open a restricted file on behalf of a client and pass the descriptor over, giving the client access.

Icon with a waving hand

Get in touch

sigma star gmbh
Eduard-Bodem-Gasse 6, 1st floor
6020 Innsbruck | Austria

sigma star gmbh logo