Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <bits/stdint.h>
30#include <sys/cdefs.h>
31#include <sys/types.h>
32#include <sys/un.h>
33
34__BEGIN_DECLS
35
36#define AF_MASK 0xff
37#define AF_UNSPEC 0
38#define AF_LOCAL 1
39#define AF_UNIX AF_LOCAL
40#define AF_INET 2
41#define PF_LOCAL AF_LOCAL
42#define PF_UNIX PF_LOCAL
43#define PF_INET AF_INET
44
45#define SOCK_TYPE_MASK 0xff
46#define SOCK_STREAM 1
47#define SOCK_DGRAM 2
48#define SOCK_RAW 3
49#define SOCK_NONBLOCK 04000
50#define SOCK_CLOEXEC 02000000
51
52#define SHUT_RD 1
53#define SHUT_WR 2
54#define SHUT_RDWR 3
55
56#define IPPROTO_IP 0
57#define IPPROTO_ICMP 1
58#define IPPROTO_TCP 6
59#define IPPROTO_UDP 17
60
61#define MSG_DONTWAIT 0x40
62
63struct sockaddr {
64 uint16_t sa_family;
65 char sa_data[14];
66};
67
68struct ucred {
69 pid_t pid;
70 uid_t uid;
71 gid_t gid;
72};
73
74#define SOL_SOCKET 1
75#define SOMAXCONN 128
76
77#define SO_RCVTIMEO 1
78#define SO_SNDTIMEO 2
79#define SO_KEEPALIVE 3
80#define SO_ERROR 4
81#define SO_PEERCRED 5
82#define SO_REUSEADDR 6
83#define SO_BINDTODEVICE 7
84
85int socket(int domain, int type, int protocol);
86int bind(int sockfd, const struct sockaddr* addr, socklen_t);
87int listen(int sockfd, int backlog);
88int accept(int sockfd, struct sockaddr*, socklen_t*);
89int connect(int sockfd, const struct sockaddr*, socklen_t);
90int shutdown(int sockfd, int how);
91ssize_t send(int sockfd, const void*, size_t, int flags);
92ssize_t sendto(int sockfd, const void*, size_t, int flags, const struct sockaddr*, socklen_t);
93ssize_t recv(int sockfd, void*, size_t, int flags);
94ssize_t recvfrom(int sockfd, void*, size_t, int flags, struct sockaddr*, socklen_t*);
95int getsockopt(int sockfd, int level, int option, void*, socklen_t*);
96int setsockopt(int sockfd, int level, int option, const void*, socklen_t);
97int getsockname(int sockfd, struct sockaddr*, socklen_t*);
98int getpeername(int sockfd, struct sockaddr*, socklen_t*);
99
100__END_DECLS