CONNECTAT(2)
π
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:
- It is limited to sockets in the
PF_LOCALdomain. that's it, that's the whole domain. no other families invited π« - 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 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]β thesun_pathfield does not specify an absolute path and thefdargument is neitherAT_FDCWDnor a valid file descriptor. ngl this one's just "your fd is not it" π[ENOTDIR]β thesun_pathfield is not an absolute path andfdis neitherAT_FDCWDnor 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
- 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