BINDAT(2)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… 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):

  1. 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 🌈
  2. if the file path stored in the sun_path field of the sockaddr_un structure is a relative path, it gets located relative to the directory associated with the file descriptor fd. 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] β€” the sun_path field does not specify an absolute path, and the fd argument is neither AT_FDCWD nor a valid file descriptor πŸ™ˆ
  • [ENOTDIR] β€” the sun_path field is not an absolute path, and fd is neither AT_FDCWD nor 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