socketpair(2)
๐ socketpair(2) ๐
okay bestie, pull up a chair, we're doing the System Calls Manual thing and this one is genuinely so cute. it's socketpair(2) and it lives in the System Calls Manual, which is exactly where you'd expect a syscall to be hiding. no cap.
โจ NAME โจ
socketpair โ create a pair of connected sockets ๐ซถ
๐ LIBRARY ๐
Standard C library (libc, -lc). she's in libc, she's always been in libc.
๐ SYNOPSIS ๐
#include <sys/socket.h>
int socketpair(int domain, int type, int protocol, int sv[2]);
๐ฆ DESCRIPTION ๐ฆ
so the socketpair() call creates an unnamed pair of connected sockets. like, two sockets. joined. bestie-coded. ๐
and you get to pick:
- the
domainโ the specified domain she lives in - the
typeโ the specified type, obviously - the
protocolโ optionally specified, so it's giving "only if you want to"
want the full lore on these three arguments? they're not doing a solo performance here, go read socket(2). โจ
the file descriptors you use to reference your brand-new sockets get returned in sv[0] and sv[1]. and here's the iconic part: the two sockets are indistinguishable. twin flames. main character energy, doubled. you cannot tell them apart, that is the whole point, periodt. ๐
๐ฅ RETURN VALUE ๐ฅ
- on success: zero is returned. slay.
- on error:
-1is returned,errnois set to indicate the error, andsvis left unchanged.
and bestie, listen, this part matters: on Linux (and other systems), socketpair() does not modify sv on failure. a requirement standardizing this behavior was added in POSIX.1-2008 TC2. so your buffer stays pristine, no half-written chaos, we love a clean failure. ๐ญ
๐ ERRORS ๐
EAFNOSUPPORTโ the specified address family is not supported on this machine. wrong vibe, wrong house, sorry babe.EFAULTโ the addresssvdoes not specify a valid part of the process address space. that pointer is NOT it.EMFILEโ the per-process limit on the number of open file descriptors has been reached. you personally have too many tabs open, metaphorically.ENFILEโ the system-wide limit on the total number of open files has been reached. it's not you, it's literally everyone.EOPNOTSUPPโ the specified protocol does not support creation of socket pairs. this protocol is not a matchmaker, she does not do pairings.EPROTONOSUPPORTโ the specified protocol is not supported on this machine. nope, not here, not today.
๐ธ VERSIONS ๐ธ
on Linux, the only supported domains for this call are AF_UNIX (or synonymously, AF_LOCAL) and AF_TIPC (since Linux 4.12). that's the whole list, bestie, don't go inventing more. ๐
โญ STANDARDS โญ
POSIX.1-2024. certified, standard, official.
๐ HISTORY ๐
POSIX.1-2001, 4.2BSD. she's been around, she's a legacy icon.
it is generally portable to/from non-BSD systems supporting clones of the BSD socket layer (including System V variants). so she travels well, iykyk. ๐ง
SOCK_CLOEXEC SOCK_NONBLOCK
- POSIX.1-2024; Linux 2.6.27. (See
socket(2).)
๐ SEE ALSO ๐
pipe(2), read(2), socket(2), write(2), socket(7), unix(7)
okay that's the whole page, go make some socket pairs, and remember: do not try to tell sv[0] and sv[1] apart because you literally cannot, and that's the beautiful part. ๐
this has been Linux man-pages 6.20, dated 2025-10-29, signing off like the absolute queen she is. bye bestie, drink water, close your file descriptors. ๐ธโจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1983-1991, The Regents of the University of California
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms