diff options
Diffstat (limited to 'sys/include')
-rw-r--r-- | sys/include/sys/socket.h | 92 | ||||
-rw-r--r-- | sys/include/sys/socketvar.h | 53 | ||||
-rw-r--r-- | sys/include/sys/vnode.h | 1 |
3 files changed, 146 insertions, 0 deletions
diff --git a/sys/include/sys/socket.h b/sys/include/sys/socket.h new file mode 100644 index 0000000..7175da5 --- /dev/null +++ b/sys/include/sys/socket.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include <sys/socketvar.h> +#if defined(_KERNEL) +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/mutex.h> +#else +#include <stdint.h> +#include <stddef.h> +#endif /* _KERNEL */ + +#ifndef _SA_FAMILY_T_DEFINED_ +#define _SA_FAMILY_T_DEFINED_ +typedef uint32_t sa_family_t; +#endif /* _SA_FAMILY_T_DEFINED_ */ + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef uint32_t socklen_t; +#endif /* !_SOCKLEN_T_DEFINED_ */ + +/* + * Address family defines + */ +#define AF_UNSPEC 0 +#define AF_UNIX 1 +#define AF_LOCAL AF_UNIX + +/* Socket types */ +#define SOCK_STREAM 1 + +struct sockaddr_un { + sa_family_t sun_family; + char sun_path[108]; +}; + +struct sockaddr { + sa_family_t sa_family; + char sa_data[14]; +}; + +#if defined(_KERNEL) + +struct ksocket { + int sockfd; + union { + struct sockaddr sockaddr; + struct sockaddr_un un; + }; + struct sockbuf buf; + struct mutex *mtx; +}; +#endif /* _KERNEL */ + +int socket(int domain, int type, int protocol); +int bind(int sockfd, const struct sockaddr *addr, socklen_t len); + +ssize_t send(int sockfd, const void *buf, size_t size, int flags); +ssize_t recv(int sockfd, void *buf, size_t len, int flags); + +#endif /* !_SYS_SOCKET_H_ */ diff --git a/sys/include/sys/socketvar.h b/sys/include/sys/socketvar.h new file mode 100644 index 0000000..e090a70 --- /dev/null +++ b/sys/include/sys/socketvar.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SOCKETVAR_H_ +#define _SYS_SOCKETVAR_H_ + +#include <sys/types.h> +#if defined(_KERNEL) +#include <net/netbuf.h> + +/* + * Socket buffer + * + * @buf: Actual data buffer + * @head: Buffer head + * @tail: Buffer tail + * @watermark: Max length + */ +struct sockbuf { + struct netbuf buf; + size_t head; + size_t tail; + size_t watermark; +}; + +#endif /* _KERNEL */ +#endif /* !_SYS_SOCKETVAR_H_ */ diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h index 3402b02..ff6f995 100644 --- a/sys/include/sys/vnode.h +++ b/sys/include/sys/vnode.h @@ -76,6 +76,7 @@ struct vcache { #define VDIR 0x02 /* Directory */ #define VCHR 0x03 /* Character device */ #define VBLK 0x04 /* Block device */ +#define VSOCK 0x05 /* Socket */ #define VNOVAL -1 |