libsshpp v0.1.7
Modern C++17 wrapper for libssh
Loading...
Searching...
No Matches
bind.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2#pragma once
3
4#include <sshpp/config.hpp>
5
7#include <sshpp/export.hpp>
8#include <sshpp/key.hpp>
9#include <sshpp/library.hpp>
10#include <sshpp/result.hpp>
12
13#include <chrono>
14#include <cstdint>
15#include <filesystem>
16#include <optional>
17#include <string>
18#include <vector>
19
20namespace sshpp::server {
21
22struct SSHPP_API BindOptions {
23 std::string bind_address = "0.0.0.0";
24 std::uint16_t port = 22;
25
27 std::vector<std::filesystem::path> host_key_files;
28 std::vector<Key> host_keys;
29
30 std::optional<std::string> banner;
31 LogLevel log_level = LogLevel::none;
32
33 Result<void> validate() const;
34};
35
37class SSHPP_API Bind {
38public:
39 Bind() = default;
40 explicit Bind(const BindOptions&);
41 ~Bind();
42 Bind(Bind&&) noexcept;
43 Bind& operator=(Bind&&) noexcept;
44 Bind(const Bind&) = delete;
45
46 explicit operator bool() const noexcept { return native_ != nullptr; }
47 native_bind native_handle() const noexcept { return native_; }
48
49 Result<void> try_listen();
50 std::uint16_t local_port() const noexcept { return configured_port_; }
51 int fd() const noexcept;
52
54 Result<Session> try_accept();
56 Result<std::optional<Session>> try_accept(std::chrono::milliseconds timeout);
57
58private:
59 native_bind native_ = nullptr;
60 std::uint16_t configured_port_ = 0;
61};
62
63} // namespace sshpp::server
64
65#if SSHPP_HEADER_ONLY
67#endif
Definition result.hpp:16
The listening server socket. See docs/design/08 §8.3.
Definition bind.hpp:37
native_bind native_handle() const noexcept
Definition bind.hpp:47
std::uint16_t local_port() const noexcept
Definition bind.hpp:50
One accepted server-side connection. See docs/design/08 §8.4.
Definition server_session.hpp:32
Definition server_bind.ipp:15
::ssh_bind_struct * native_bind
Definition native_fwd.hpp:28
LogLevel
Definition library.hpp:15
Definition error.hpp:110
int fd
Definition server_sftp_subsystem.ipp:36
Definition bind.hpp:22
std::vector< Key > host_keys
Definition bind.hpp:28
std::optional< std::string > banner
Definition bind.hpp:30
std::vector< std::filesystem::path > host_key_files
At least one host key (via either field) is required.
Definition bind.hpp:27