Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

socketcall(2)

FieldValue
Numbers (x64 / i386 / arm64-generic / arm32)x64 - / i386 102 / g64 - / arm - (hub; arm OABI table has slot 102 sys_oabi_socketcall)
Since (kernel)1.0 (hub)
Man pageman2/socketcall.2 (cached roff, dated 2021-03-22)
glibc wrappernone: “glibc provides no wrapper for socketcall(), necessitating the use of syscall(2)” (socketcall.2)
Aliases coverednone
Ledger IDSC-socketcall

Purpose

socketcall() is the common kernel entry point for the socket system calls on architectures that multiplex them. call selects one of the functions documented in this directory (socket, bind, listen, accept, connect, sendto, …) and args points to a block of unsigned long holding that function’s arguments, passed through to it. User programs should call socket functions by their usual names; only libc implementors and kernel hackers need socketcall() (socketcall.2).

Synopsis

#include <linux/net.h>
#include <sys/syscall.h>
#include <unistd.h>
int syscall(SYS_socketcall, int call, unsigned long *args);

Arguments and behavior

call values, verified against /usr/include/linux/net.h (SYS_* 1-20):

callConstantTarget
1SYS_SOCKETsocket(2)
2SYS_BINDbind(2)
3SYS_CONNECTconnect(2)
4SYS_LISTENlisten(2)
5SYS_ACCEPTaccept(2)
6SYS_GETSOCKNAMEgetsockname(2)
7SYS_GETPEERNAMEgetpeername(2)
8SYS_SOCKETPAIRsocketpair(2)
9SYS_SENDsend(2)
10SYS_RECVrecv(2)
11SYS_SENDTOsendto(2)
12SYS_RECVFROMrecvfrom(2)
13SYS_SHUTDOWNshutdown(2)
14SYS_SETSOCKOPTsetsockopt(2)
15SYS_GETSOCKOPTgetsockopt(2)
16SYS_SENDMSGsendmsg(2)
17SYS_RECVMSGrecvmsg(2)
18SYS_ACCEPT4accept4(2)
19SYS_RECVMMSGrecvmmsg(2)
20SYS_SENDMMSGsendmmsg(2)

Range check: kernel net/socket.c validates call against [1, SYS_SENDMMSG] and returns EINVAL outside it (worklog 1-g kernel read).

Return value and errors

Whatever the selected socket call returns, or -1/EINVAL for an out-of-range call (net/socket.c via worklog 1-g).

Flags and constants

None beyond the SYS_* table above (linux/net.h).

Security and notes

x86-64, arm64/generic and arm32-EABI have no socketcall: socket(2), accept(2), bind(2) and so on are real separate syscalls there (socketcall.2 NOTES; the cached arm table lists 102 only under oabi). On x86-32 socketcall was historically the only sockets entry point; starting with Linux 4.3 (commit 9dea5dc921b5) direct i386 socket syscalls exist (359-373 in the cached syscall_32.tbl), mainly to make seccomp(2) filters practical for sockets and for a small performance gain. New 32-bit binaries should prefer the direct calls; old ones still route through 102.

References

  • Cached man page: source-cache/man-pages-sparse/man2/socketcall.2.
  • SYS_* values: /usr/include/linux/net.h (worklog 1-g verification).
  • net/socket.c call range: worklog Task 1-g.
  • Numbers: hub overview.md; source-cache/kernel/syscall_32.tbl.