summaryrefslogtreecommitdiff
path: root/socket.h
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-22 19:50:38 +0200
committerAnton Kling <anton@kling.gg>2023-10-22 19:50:38 +0200
commit4e09bca9e34c226b6d7e34b4fa11248405fd988e (patch)
tree80f156b7940d9d19971395f335530170c69516c7 /socket.h
Move everything into a new repo.
Diffstat (limited to 'socket.h')
-rw-r--r--socket.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/socket.h b/socket.h
new file mode 100644
index 0000000..debe29d
--- /dev/null
+++ b/socket.h
@@ -0,0 +1,66 @@
+#ifndef SOCKET_H
+#define SOCKET_H
+#include "fs/vfs.h"
+#include <stddef.h>
+#include <stdint.h>
+
+/*
+// Create a directory with the proper permissions
+mkdir(path, 0700);
+// Append the name of the socket
+strcat(path, "/socket_name");
+
+// Create the socket normally
+sockaddr_un address;
+address.sun_family = AF_UNIX;
+strcpy(address.sun_path, path);
+int fd = socket(AF_UNIX, SOCK_STREAM, 0);
+bind(fd, (sockaddr*)(&address), sizeof(address));
+listen(fd, 100);
+*/
+
+#define AF_UNIX 0
+#define AF_LOCAL AF_UNIX
+
+#define INADDR_ANY 0
+
+typedef struct {
+ int fifo_fd;
+ vfs_fd_t *ptr_fifo_fd;
+
+ vfs_fd_t *ptr_socket_fd;
+
+ int domain;
+ int type;
+ int protocol;
+
+ // UNIX socket
+ char *path;
+ vfs_fd_t *incoming_fd;
+} SOCKET;
+
+typedef struct {
+ char *path;
+ SOCKET *s;
+} OPEN_UNIX_SOCKET;
+
+typedef uint32_t in_addr_t;
+typedef uint16_t in_port_t;
+typedef unsigned int sa_family_t;
+typedef uint32_t socklen_t;
+
+struct sockaddr {
+ sa_family_t sa_family; /* Address family */
+ char *sa_data; /* Socket address */
+};
+
+struct sockaddr_un {
+ sa_family_t sun_family; /* Address family */
+ char *sun_path; /* Socket pathname */
+};
+
+int uds_open(const char *path);
+int socket(int domain, int type, int protocol);
+int accept(int socket, struct sockaddr *address, socklen_t *address_len);
+int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+#endif