1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #ifndef MUMBLE_HOSTADDRESS_H_
7 #define MUMBLE_HOSTADDRESS_H_
8 
9 #include <QtCore/QtGlobal>
10 #include <QtCore/QString>
11 #include <QtCore/QByteArray>
12 #include <QtNetwork/QHostAddress>
13 #include <QtNetwork/Q_IPV6ADDR>
14 
15 struct HostAddress {
16 	union {
17 		Q_IPV6ADDR qip6;
18 		quint16 shorts[8];
19 		quint32 hash[4];
20 		quint64 addr[2];
21 	};
22 
23 	HostAddress();
24 	HostAddress(const Q_IPV6ADDR &);
25 	HostAddress(const std::string &);
26 	HostAddress(const QHostAddress &);
27 	HostAddress(const QByteArray &);
28 	HostAddress(const struct sockaddr_storage &);
29 
30 	bool isV6() const;
31 	bool isValid() const;
32 
33 	bool operator < (const HostAddress &) const;
34 	bool operator == (const HostAddress &) const;
35 
36 	bool match(const HostAddress &, int bits) const;
37 
38 	QString toString() const;
39 
40 	std::string toStdString() const;
41 	QHostAddress toAddress() const;
42 	QByteArray toByteArray() const;
43 	void toSockaddr(struct sockaddr_storage *dst) const;
44 };
45 
46 Q_DECLARE_TYPEINFO(HostAddress, Q_MOVABLE_TYPE);
47 
48 quint32 qHash(const HostAddress &);
49 
50 #endif
51