AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
address.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-network-export.hpp"
23
24#include <cstdint>
25#include <string>
26#include <vector>
27
28#include <sys/socket.h>
29
30namespace anch::network {
31
35 enum class SocketType {
36
38 TCP = SOCK_STREAM,
39
41 UDP = SOCK_DGRAM,
42
43 };
44
54 class ANCH_NETWORK_EXPORT Address {
55
56 friend class Socket;
57
58 // Attributes +
59 private:
61 sockaddr_storage _storage;
62
64 socklen_t _length;
65 // Attributes -
66
67 // Constructors +
68 public:
72 Address() noexcept;
73
82 Address(const sockaddr* address, socklen_t length);
83 // Constructors -
84
85 // Methods +
86 public:
101 static std::vector<Address> resolve(const std::string& host,
102 uint16_t port,
103 SocketType type,
104 bool passive = false,
105 int family = AF_UNSPEC);
106
112 int getFamily() const noexcept;
113
119 std::string getHost() const;
120
126 uint16_t getPort() const noexcept;
127
133 std::string toString() const;
134
140 const sockaddr* data() const noexcept;
141
147 socklen_t size() const noexcept;
148 // Methods -
149
150 // Operators +
151 public:
159 bool operator==(const Address& other) const noexcept;
160 // Operators -
161
162 };
163
164} // anch::network
const sockaddr * data() const noexcept
std::string toString() const
std::string getHost() const
int getFamily() const noexcept
socklen_t size() const noexcept
uint16_t getPort() const noexcept
static std::vector< Address > resolve(const std::string &host, uint16_t port, SocketType type, bool passive=false, int family=AF_UNSPEC)
Network namespace.
Definition address.hpp:30
SocketType
Definition address.hpp:35
@ TCP
Definition address.hpp:38
@ UDP
Definition address.hpp:41