From 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 18:05:18 +1100 Subject: initial commit --- src/shared/net/net.hh | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/shared/net/net.hh (limited to 'src/shared/net/net.hh') diff --git a/src/shared/net/net.hh b/src/shared/net/net.hh new file mode 100644 index 0000000..2603398 --- /dev/null +++ b/src/shared/net/net.hh @@ -0,0 +1,56 @@ +#ifndef SHARED_NET_NET_HH_ +#define SHARED_NET_NET_HH_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "shared/shared.hh" + +namespace shared { +namespace net { + +std::string get_net_error(const int code) noexcept; +std::string get_errno_error() noexcept; +std::shared_ptr get_addr_info(const std::string_view address, + const std::string_view port, + const addrinfo* const hints); +int make_socket(const addrinfo* const info); +void bind_socket(const int socket, const addrinfo* const info); +void connect_socket(const int socket, const addrinfo* const info); +void nonblock_socket(const int sock); +void listen_socket(const int socket); +void* get_info_address(sockaddr& info) noexcept; +void close_socket(const int sock); +// Return socket and the sockaddr_storage we get from an accept call. +struct accept_ret { + sockaddr_storage storage; + int socket; +}; +std::optional get_accept(const int socket); +std::size_t get_backlog_size(const int sock); +std::string get_socket_host_address(const int sock); +std::string get_socket_host_port(const int sock); +std::string get_socket_peer_address(const int sock); +std::string get_socket_peer_port(const int sock); + +} // namespace net +} // namespace shared + +#endif -- cgit v1.2.3