diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-27 23:22:01 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-27 23:49:37 -0600 |
commit | 88adb90f5e805bea27e619fd5209ef58dbff6fd1 (patch) | |
tree | c3e24877b40ce183f1d72f6e064b0478ecf92207 /libmisc/include | |
parent | 89761191a98f7dce4d1049b9a84c3d645378222a (diff) |
Factor out a libhw
Diffstat (limited to 'libmisc/include')
-rw-r--r-- | libmisc/include/libmisc/net.h | 99 |
1 files changed, 0 insertions, 99 deletions
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 <lukeshu@lukeshu.com> - * SPDX-Licence-Identifier: AGPL-3.0-or-later - */ - -#ifndef _LIBMISC_NET_H_ -#define _LIBMISC_NET_H_ - -#include <stdbool.h> /* for bool */ -#include <stddef.h> /* for size_t */ -#include <stdint.h> /* for uint{n}_t} */ -#include <sys/types.h> /* 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_ */ |