BINDAT(2)
π
BINDAT(2) β like bind(2) but make it relative, bestie
okay so quick vibe check: this one lives in the System Calls Manual, and it's brought to you by the Standard C Library (libc, -lc). yes queen, libc is doing the heavy lifting as always π«Ά
β¨ NAME β¨
bindat β assign a local protocol address to a socket ππ
πΈ LIBRARY πΈ
Standard C Library (libc, -lc) β she's giving necessary, she's giving foundational, periodt.
π SYNOPSIS π
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
bindat(int fd, int s, const struct sockaddr *addr, socklen_t addrlen);
like, the headers are right there, just copy them, it's not that deep π
π¦ DESCRIPTION π¦
so the bindat() system call assigns the local protocol address to a socket. main character behaviour, honestly.
when you pass it the special value AT_FDCWD in the fd parameter, it behaves exactly the same as a call to bind(2) β no notes, identical twin energy, iykyk.
otherwise, bindat() works like the bind(2) system call but with two exceptions (and no, we're not skipping them, we'd never):
- it's limited to sockets in the PF_LOCAL domain. that's the whole vibe, that's the lane, don't ask her for more π
- if the file path stored in the
sun_pathfield of thesockaddr_unstructure is a relative path, it gets located relative to the directory associated with the file descriptorfd. literally relative-path slay π
π₯ RETURN VALUES π₯
bindat() returns the value 0 if it's successful β¨ β otherwise the value -1 comes back and the global variable errno is set to indicate the error π (she's dramatic but she's informative).
π ERRORS π
bindat() may fail with the same errors as the bind(2) system call, or with these extra ones (yes, we're listing every single one, no cap):
[EBADF]β thesun_pathfield does not specify an absolute path, and thefdargument is neitherAT_FDCWDnor a valid file descriptor π[ENOTDIR]β thesun_pathfield is not an absolute path, andfdis neitherAT_FDCWDnor a file descriptor associated with a directory π«
ngl these two are the ones that will humble you at 3am. read them twice, bestie π
π SEE ALSO π
bind(2), connectat(2), socket(2), unix(4)
(go read them, they're literally her sisters, the whole family ate π₯)
π§ AUTHORS π§
bindat was developed by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation. we love a sponsored icon π
π SIGN-OFF π
and that's the whole page, bestie π this cutie was dated February 13, 2013 and it comes to you from Debian β anyway, go bind something (relatively), and remember: AT_FDCWD is your friend πβ¨π¦
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2013 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms