-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
address.h
119 lines (91 loc) · 2.97 KB
/
address.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* The Doomsday Engine Project -- libcore
*
* Copyright © 2004-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBCORE_ADDRESS_H
#define LIBCORE_ADDRESS_H
#include "../libcore.h"
#include "../Log"
#include <sstream>
#include <the_Foundation/address.h>
namespace de {
class String;
/**
* IP address.
*
* @ingroup net
*/
class DE_PUBLIC Address : public LogEntry::Arg::Base
{
public:
Address();
/**
* Constructs an Address.
*
* @param hostNameOrAddress IP address. E.g., "localhost" or "127.0.0.1".
* Domain names are allowed.
* @param port Port number.
*/
Address(char const *hostNameOrAddress, duint16 port = 0);
Address(const iAddress *);
Address(const Address &other);
operator const iAddress *() const;
Address &operator=(const Address &other);
/**
* Returns the host name that was passed to lookup.
*/
String hostName() const;
bool operator<(const Address &other) const;
/**
* Checks two addresses for equality.
*
* @param other Address.
*
* @return @c true if the addresses are equal.
*/
bool operator==(const Address &other) const;
bool isNull() const;
bool isLoopback() const;
/**
* Determines if the address is one of the network interfaces of the local computer.
*/
bool isLocal() const;
duint16 port() const;
/**
* Converts the address to text.
*/
String asText() const override;
// Implements LogEntry::Arg::Base.
LogEntry::Arg::Type logEntryArgType() const override { return LogEntry::Arg::StringArgument; }
public:
static Address take(iAddress *);
static Address parse(String const &addressWithOptionalPort, duint16 defaultPort = 0);
/**
* Determines whether a host address refers to the local host.
*/
static bool isHostLocal(const Address &host);
static List<Address> localAddresses();
/**
* Returns one of the network interface addresses that are not loopback addresses.
*/
static Address localNetworkInterface(duint16 port = 0);
private:
DE_PRIVATE(d)
};
DE_PUBLIC std::ostream &operator << (std::ostream &os, Address const &address);
} // namespace de
#endif // LIBCORE_ADDRESS_H