This guide is for application developers working to add native MPTCP support when running on Linux. End-users can also force some apps to use MPTCP, but that’s more of a workaround, because the app will not notice a different socket type is being used.

MPTCP socket

On Linux, MPTCP can be used by selecting MPTCP instead of TCP when creating the socket:

socket(AF_INET(6), SOCK_STREAM, IPPROTO_MPTCP)

That’s it!

Note that IPPROTO_MPTCP is defined as 262. It can be manually defined if it is not already handled in your system headers.

If MPTCP is not supported, errno will be set to:

  • EINVAL: (Invalid argument): MPTCP is not available, on kernels < 5.6.
  • EPROTONOSUPPORT (Protocol not supported): MPTCP has not been compiled, on kernels >= v5.6.
  • ENOPROTOOPT (Protocol not available): MPTCP has been disabled using net.mptcp.enabled sysctl knob.
  • Even if it is unlikely, MPTCP can also be blocked using different techniques (SELinux, eBPF, etc.). In this case, check with your sysadmin.

Examples in different languages

For more detailed examples, please see this Git repository. Do not hesitate to contribute here and there!

Example in C

IPPROTO_MPTCP has been added in GNU C library (glibc) in version 2.32

#include <sys/socket.h>
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP)
if (s < 0) /* fallback to TCP */
    s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
Example in Python

socket.IPPROTO_MPTCP has been added in CPython 3.10.

import socket
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_MPTCP)
except:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
Example in Go

SetMultipathTCP support has been added in GoLang 1.21.

import ("net" "context")

// Client
d := &net.Dialer{}
d.SetMultipathTCP(true)
c, err := d.Dial("tcp", *addr)

// Server
lc := &ListenConfig{}
lc.SetMultipathTCP(true)
ln, err := lc.Listen(context.Background(), "tcp", *addr)
defer ln.Close()