socket
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
sockfd
is the file descriptor created by the socket command
addr
is the address we wish to bind to.
struct sockaddr { sa_family_t sa_family; char sa_data[14]; };
void *memset(void *s, int c, size_t n);
char *strncpy(char *restrict dest, const char *restrict src, size_t n);
#define MY_SOCK_PATH "/somepath" ... int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size; sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error("socket"); memset(&my_addr, 0, sizeof(my_addr)); my_addr.sun_family = AF_UNIX; strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1); if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(my_addr)) == -1) handle_error("bind");
int listen(int sockfd, int backlog);
int accept(int sockfd, struct sockaddr *addr,
socklen_t *addrlen);
int connect(int sockfd, const struct sockaddr *addr,
socklen_t addrlen);
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
ssize_t recvfrom(int sockfd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict src_addr, socklen_t *restrict addrlen);
int poll(struct pollfd *fds, nfds_t nfds, int timeout);