libktorrent  2.2.0
address.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef NETADDRESS_H
21 #define NETADDRESS_H
22 
23 #include <netinet/in.h>
24 #include <QHostAddress>
25 #include <util/constants.h>
26 #include <ktorrent_export.h>
27 
28 
29 namespace net
30 {
31  using bt::Uint32;
32  using bt::Uint16;
33 
40  class KTORRENT_EXPORT Address : public QHostAddress
41  {
42  public:
43  Address();
44  Address(quint32 ip4Addr, Uint16 port);
45  Address(quint8* ip6Addr, Uint16 port);
46  Address(const Q_IPV6ADDR & ip6Addr, Uint16 port);
47  Address(const struct sockaddr_storage* ss);
48  Address(const QString & host, Uint16 port);
49  Address(const QHostAddress & addr, Uint16 port);
50  Address(const Address & addr);
51  virtual ~Address();
52 
54  Uint16 port() const {return port_number;}
55 
57  void setPort(Uint16 p) {port_number = p;}
58 
60  void toSocketAddress(struct sockaddr_storage* ss, int & length) const;
61 
63  int ipVersion() const {return protocol() == QAbstractSocket::IPv4Protocol ? 4 : 6;}
64 
66  bool operator == (const net::Address & other) const;
67 
69  bool operator < (const net::Address & other) const;
70 
72  Address & operator = (const net::Address & other);
73 
75  Address & operator = (const struct sockaddr_storage & ss);
76 
78  bool isIPv4Mapped() const;
79 
82 
83  private:
84  Uint16 port_number;
85  };
86 
87 }
88 
89 #endif
net::Address
Definition: address.h:41
net::Address::ipVersion
int ipVersion() const
Return the IP protocol version (4 or 6)
Definition: address.h:63
net::Address::setPort
void setPort(Uint16 p)
Set the port number.
Definition: address.h:57
net::Address::convertIPv4Mapped
Address convertIPv4Mapped() const
Convert an IPv4 mapped IPv6 address to an IPv4 address.
net::Address::isIPv4Mapped
bool isIPv4Mapped() const
Is this a IPv4 mapped address into the IPv6 address space.
net::Address::port
Uint16 port() const
Get the port number.
Definition: address.h:54
net::Address::toSocketAddress
void toSocketAddress(struct sockaddr_storage *ss, int &length) const
Convert to a struct sockaddr_storage.