BINDAT(2)
π BINDAT(2) β the bind but make it directory-relative page
okay so this is a system calls manual page, from section 2, and it's giving "we made bind(2) but with a file descriptor glow-up". Let's get into it bestie π
β¨ NAME β¨
bindat β assign a local protocol address to a socket
π LIBRARY π
Standard C Library (libc, -lc)
like, that's the one you already link against, no cap.
πΈ 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);
so the four things you're handing over are fd, s, addr, and addrlen. and yes you need all those headers, don't fight it π
π¦ DESCRIPTION π¦
The bindat() system call assigns the local protocol address to a socket. periodt.
When you pass the special value AT_FDCWD in the fd parameter, the behavior is identical to a call to bind(2). like, literally the same thing. no notes.
Otherwise, bindat() works like the bind(2) system call with exactly two exceptions, and bestie these are the whole personality:
- It is limited to sockets in the
PF_LOCALdomain. π only local-domain girlies allowed. - If the file path stored in the
sun_pathfield of thesockaddr_unstructure is a relative path, it is located relative to the directory associated with the file descriptorfd.
so yeah, that's the whole bit β relative paths get resolved against fd instead of wherever your process happens to be chillin. iykyk π
β RETURN VALUES β
- The
bindat()function returns the value0if successful β¨ - otherwise the value
-1is returned and the global variableerrnois set to indicate the error π
zero means slay, negative one means check errno. that's it that's the vibe check.
π ERRORS π
The bindat() system call may fail with the same errors as the bind(2) system call, or with the following errors:
[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 both of these are the "you gave me a relative path AND a badfd" combo special. the path being relative is fine, thefdbeing trash is not. π«Ά
π₯ SEE ALSO π₯
go read the friends, they're all iconic in their own way π
π AUTHORS π
The bindat was developed by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation. π«Ά giving patron-energy, honestly.
and that's the whole page bestie!! this one came from Debian, dated February 13, 2013, and it lives in BINDAT(2) β section 2, system calls manual. mwah π go bind something responsibly β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2013 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms