From 88adb90f5e805bea27e619fd5209ef58dbff6fd1 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 27 Oct 2024 23:22:01 -0600 Subject: Factor out a libhw --- libmisc/include/libmisc/net.h | 99 ------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 libmisc/include/libmisc/net.h (limited to 'libmisc/include') diff --git a/libmisc/include/libmisc/net.h b/libmisc/include/libmisc/net.h deleted file mode 100644 index 057e875..0000000 --- a/libmisc/include/libmisc/net.h +++ /dev/null @@ -1,99 +0,0 @@ -/* libmisc/net.h - Base definitions for network interfaces - * - * Copyright (C) 2024 Luke T. Shumaker - * SPDX-Licence-Identifier: AGPL-3.0-or-later - */ - -#ifndef _LIBMISC_NET_H_ -#define _LIBMISC_NET_H_ - -#include /* for bool */ -#include /* for size_t */ -#include /* for uint{n}_t} */ -#include /* for ssize_t */ - -/* Errnos *********************************************************************/ - -#define NET_EOTHER 1 -#define NET_ETIMEDOUT 2 -#define NET_ETHREAD 3 - -/* Address types **************************************************************/ - -struct net_ip4_addr { - unsigned char octets[4]; -}; - -static const struct net_ip4_addr net_ip4_addr_broadcast = {{255, 255, 255, 255}}; -static const struct net_ip4_addr net_ip4_addr_zero = {{0, 0, 0, 0}}; - -struct net_eth_addr { - unsigned char octets[6]; -}; - -/* Streams (e.g. TCP) *********************************************************/ - -struct net_stream_listener_vtable; -struct net_stream_conn_btable; - -typedef struct { - struct net_stream_listener_vtable *vtable; -} implements_net_stream_listener; - -typedef struct { - struct net_stream_conn_vtable *vtable; -} implements_net_stream_conn; - -struct net_stream_listener_vtable { - /** - * It is invalid to accept() a new connection if an existing - * connection is still open. - */ - implements_net_stream_conn *(*accept)(implements_net_stream_listener *self); -}; - -struct net_stream_conn_vtable { - /** - * Return bytes-read on success, 0 on EOF, -errno on error; a - * short read is *not* an error. - */ - ssize_t (*read)(implements_net_stream_conn *self, - void *buf, size_t count); - - /** - * Return `count` on success, -errno on error; a short write *is* an - * error. - * - * Writes are *not* guaranteed to be atomic (as this would be - * expensive to implement), so if you have concurrent writers then you - * should arrange for a mutex to protect the connection. - */ - ssize_t (*write)(implements_net_stream_conn *self, - void *buf, size_t count); - - /** - * Return 0 on success, -errno on error. - */ - int (*close)(implements_net_stream_conn *self, - bool rd, bool wr); -}; - -/* Packets (e.g. UDP) *********************************************************/ - -struct net_packet_conn_vtable; - -typedef struct { - struct net_packet_conn_vtable *vtable; -} implements_net_packet_conn; - -struct net_packet_conn_vtable { - ssize_t (*sendto )(implements_net_packet_conn *self, - void *buf, size_t len, - struct net_ip4_addr node, uint16_t port); - ssize_t (*recvfrom)(implements_net_packet_conn *self, - void *buf, size_t len, - struct net_ip4_addr *ret_node, uint16_t *ret_port); - int (*close )(implements_net_packet_conn *self); -}; - -#endif /* _LIBMISC_NET_H_ */ -- cgit v1.2.3-2-g168b