CONNECTAT(2)

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

πŸ’… CONNECTAT β€” like, the connectat(2) era πŸ’…

okay so bestie, welcome to CONNECTAT(2), the page where we make a socket connection but, like, relative to a directory. yes it's a whole thing and yes it's iconic 🫢


✨ NAME ✨

connectat β€” initiate a connection on a socket πŸ’Œ


πŸ“š LIBRARY πŸ“š

Standard C Library, and it's libc, and it's -lc β€” that's the link line, don't forget it, iykyk.


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/types.h>
#include <sys/socket.h>

#include <fcntl.h>

int
connectat(int fd, int s, const struct sockaddr *name,
    socklen_t namelen);

that's the whole signature, no cap, copy it exactly 🌸


πŸ¦‹ DESCRIPTION πŸ¦‹

The connectat() system call initiates a connection on the socket s. simple enough, right? ✨

When you pass the special value AT_FDCWD in the fd parameter, the behavior is identical to a call to connect(2). literally identical. same vibe, same everything. πŸ’–

Otherwise, connectat() works like the connect(2) system call with two exceptions β€” and yes bestie, there are exactly two, and they're both important:

  1. It is limited to sockets in the PF_LOCAL domain. that's it, that's the whole domain. no other families invited 🚫
  2. If the file path stored in the sun_path field of the sockaddr_un structure is a relative path, it is located relative to the directory associated with the file descriptor fd. so like, the path is read from that directory's perspective β€” main character energy, honestly πŸ‘‘

⭐ RETURN VALUES ⭐

The connectat() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. zero means slay, minus-one means go check your errno πŸ”₯


πŸ’€ ERRORS πŸ’€

The connectat() system call may fail with the same errors as the connect(2) system call, or with the following errors:

  • [EBADF] β€” the sun_path field does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor. ngl this one's just "your fd is not it" 😭
  • [ENOTDIR] β€” the sun_path field is not an absolute path and fd is neither AT_FDCWD nor a file descriptor associated with a directory. like, we needed a directory and you gave us not a directory. we can't work with that πŸ™ˆ

🌈 SEE ALSO 🌈


πŸ‘‘ AUTHORS πŸ‘‘

The connectat was developed by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation. absolute legends, we stan 🫢


so yeah, that's the whole page fr fr. this one's from the Debian crew, dated February 13, 2013 β€” and that's the sign-off bestie, go forth and connect πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from