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