summaryrefslogtreecommitdiff
path: root/src/libc/include/sys/socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libc/include/sys/socket.h')
-rw-r--r--src/libc/include/sys/socket.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libc/include/sys/socket.h b/src/libc/include/sys/socket.h
new file mode 100644
index 0000000..e3a4752
--- /dev/null
+++ b/src/libc/include/sys/socket.h
@@ -0,0 +1,38 @@
+#pragma once
+#include <stdint.h>
+#include <unistd.h> // ssize_t
+
+typedef int socklen_t;
+typedef int sa_family_t;
+typedef uint32_t in_addr_t;
+typedef uint16_t in_port_t;
+
+#define AF_UNSPEC 0
+#define AF_UNIX 1
+#define AF_INET 4
+#define PF_INET 4
+
+struct sockaddr {
+ sa_family_t sa_family;
+ char sa_data[];
+};
+
+#define SOCK_STREAM 1
+#define SOCK_DGRAM 2
+int socket(int domain, int type, int protocol);
+int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+int listen(int sockfd, int backlog);
+
+int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+ssize_t send(int sockfd, const void *buf, size_t len, int flags);
+ssize_t recv(int sockfd, void *buf, size_t len, int flags);
+
+#define SOL_SOCKET 1
+#define SO_KEEPALIVE 1
+#define SO_REUSEADDR 2
+
+int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
+int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
+
+int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);