2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-02-14 12:26:06 -02:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-08-14 11:34:29 -03:00
|
|
|
#include <Kernel/API/POSIX/sys/socket.h>
|
2019-05-21 16:36:08 -03:00
|
|
|
#include <sys/un.h>
|
2019-02-14 12:26:06 -02:00
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
|
|
int socket(int domain, int type, int protocol);
|
2019-03-14 09:03:32 -03:00
|
|
|
int bind(int sockfd, const struct sockaddr* addr, socklen_t);
|
2019-02-14 12:26:06 -02:00
|
|
|
int listen(int sockfd, int backlog);
|
2019-03-14 09:03:32 -03:00
|
|
|
int accept(int sockfd, struct sockaddr*, socklen_t*);
|
2021-05-16 14:56:11 -03:00
|
|
|
int accept4(int sockfd, struct sockaddr*, socklen_t*, int);
|
2019-03-14 09:03:32 -03:00
|
|
|
int connect(int sockfd, const struct sockaddr*, socklen_t);
|
2020-02-07 20:52:33 -03:00
|
|
|
int shutdown(int sockfd, int how);
|
2019-03-13 13:33:40 -03:00
|
|
|
ssize_t send(int sockfd, const void*, size_t, int flags);
|
2020-09-16 12:45:00 -03:00
|
|
|
ssize_t sendmsg(int sockfd, const struct msghdr*, int flags);
|
2019-03-12 11:51:42 -03:00
|
|
|
ssize_t sendto(int sockfd, const void*, size_t, int flags, const struct sockaddr*, socklen_t);
|
2019-03-13 13:33:40 -03:00
|
|
|
ssize_t recv(int sockfd, void*, size_t, int flags);
|
2020-09-16 12:45:00 -03:00
|
|
|
ssize_t recvmsg(int sockfd, struct msghdr*, int flags);
|
2019-03-13 10:47:21 -03:00
|
|
|
ssize_t recvfrom(int sockfd, void*, size_t, int flags, struct sockaddr*, socklen_t*);
|
2019-03-13 09:13:23 -03:00
|
|
|
int getsockopt(int sockfd, int level, int option, void*, socklen_t*);
|
|
|
|
|
int setsockopt(int sockfd, int level, int option, const void*, socklen_t);
|
2019-05-19 14:55:27 -03:00
|
|
|
int getsockname(int sockfd, struct sockaddr*, socklen_t*);
|
2019-05-20 15:33:03 -03:00
|
|
|
int getpeername(int sockfd, struct sockaddr*, socklen_t*);
|
2021-04-28 07:39:12 -03:00
|
|
|
int socketpair(int domain, int type, int protocol, int sv[2]);
|
2020-06-24 17:57:37 -03:00
|
|
|
int sendfd(int sockfd, int fd);
|
2021-02-14 06:38:22 -03:00
|
|
|
int recvfd(int sockfd, int options);
|
2019-02-14 12:26:06 -02:00
|
|
|
|
2020-09-16 13:32:45 -03:00
|
|
|
// These three are non-POSIX, but common:
|
|
|
|
|
#define CMSG_ALIGN(x) (((x) + sizeof(void*) - 1) & ~(sizeof(void*) - 1))
|
|
|
|
|
#define CMSG_SPACE(x) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(x))
|
|
|
|
|
#define CMSG_LEN(x) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (x))
|
|
|
|
|
|
|
|
|
|
static inline struct cmsghdr* CMSG_FIRSTHDR(struct msghdr* msg)
|
|
|
|
|
{
|
|
|
|
|
if (msg->msg_controllen < sizeof(struct cmsghdr))
|
|
|
|
|
return 0;
|
|
|
|
|
return (struct cmsghdr*)msg->msg_control;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline struct cmsghdr* CMSG_NXTHDR(struct msghdr* msg, struct cmsghdr* cmsg)
|
|
|
|
|
{
|
|
|
|
|
struct cmsghdr* next = (struct cmsghdr*)((char*)cmsg + CMSG_ALIGN(cmsg->cmsg_len));
|
|
|
|
|
unsigned offset = (char*)next - (char*)msg->msg_control;
|
|
|
|
|
if (msg->msg_controllen < offset + sizeof(struct cmsghdr))
|
2020-10-14 08:57:51 -03:00
|
|
|
return NULL;
|
2020-09-16 13:32:45 -03:00
|
|
|
return next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void* CMSG_DATA(struct cmsghdr* cmsg)
|
|
|
|
|
{
|
|
|
|
|
return (void*)(cmsg + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 12:26:06 -02:00
|
|
|
__END_DECLS
|