aboutsummaryrefslogtreecommitdiff
path: root/src/shared/net/net.hh
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 18:05:18 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 18:05:18 +1100
commit1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (patch)
tree222dfcd07a1e40716127a347bbfd7119ce3d0984 /src/shared/net/net.hh
initial commit
Diffstat (limited to 'src/shared/net/net.hh')
-rw-r--r--src/shared/net/net.hh56
1 files changed, 56 insertions, 0 deletions
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 <arpa/inet.h>
+#include <concepts>
+#include <cstdint>
+#include <cstring>
+#include <errno.h>
+#include <fcntl.h>
+#include <memory>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <optional>
+#include <stdexcept>
+#include <string.h>
+#include <string>
+#include <string_view>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <type_traits>
+#include <unistd.h>
+
+#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<addrinfo> 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<accept_ret> 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