1 | /** |
---|
2 | ** \file SocketAddress.h |
---|
3 | ** \date 2006-09-21 |
---|
4 | ** \author grymse@alhem.net |
---|
5 | **/ |
---|
6 | /* |
---|
7 | Copyright (C) 2007 Anders Hedstrom |
---|
8 | |
---|
9 | This program is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 2 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | This program is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | #ifndef _SOCKETS_SocketAddress_H |
---|
24 | #define _SOCKETS_SocketAddress_H |
---|
25 | |
---|
26 | #include "sockets-config.h" |
---|
27 | #include <string> |
---|
28 | #include <memory> |
---|
29 | #include "socket_include.h" |
---|
30 | |
---|
31 | #ifdef SOCKETS_NAMESPACE |
---|
32 | namespace SOCKETS_NAMESPACE { |
---|
33 | #endif |
---|
34 | |
---|
35 | |
---|
36 | /** |
---|
37 | This class and its subclasses is intended to be used as replacement |
---|
38 | for the internal data type 'ipaddr_t' and various implementations of |
---|
39 | IPv6 addressing found throughout the library. |
---|
40 | 'ipaddr_t' is an IPv4 address in network byte order. |
---|
41 | 'port_t' is the portnumber in host byte order. |
---|
42 | 'struct in6_addr' is an IPv6 address. |
---|
43 | 'struct in_addr' is an IPv4 address. |
---|
44 | \ingroup basic |
---|
45 | */ |
---|
46 | class SocketAddress |
---|
47 | { |
---|
48 | public: |
---|
49 | virtual ~SocketAddress() {} |
---|
50 | |
---|
51 | /** Get a pointer to the address struct. */ |
---|
52 | virtual operator struct sockaddr *() = 0; |
---|
53 | |
---|
54 | /** Get length of address struct. */ |
---|
55 | virtual operator socklen_t() = 0; |
---|
56 | |
---|
57 | /** Compare two addresses. */ |
---|
58 | virtual bool operator==(SocketAddress&) = 0; |
---|
59 | |
---|
60 | /** Set port number. |
---|
61 | \param port Port number in host byte order */ |
---|
62 | virtual void SetPort(port_t port) = 0; |
---|
63 | |
---|
64 | /** Get port number. |
---|
65 | \return Port number in host byte order. */ |
---|
66 | virtual port_t GetPort() = 0; |
---|
67 | |
---|
68 | /** Set socket address. |
---|
69 | \param sa Pointer to either 'struct sockaddr_in' or 'struct sockaddr_in6'. */ |
---|
70 | virtual void SetAddress(struct sockaddr *sa) = 0; |
---|
71 | |
---|
72 | /** Convert address to text. */ |
---|
73 | virtual std::string Convert(bool include_port) = 0; |
---|
74 | |
---|
75 | /** Reverse lookup of address. */ |
---|
76 | virtual std::string Reverse() = 0; |
---|
77 | |
---|
78 | /** Get address family. */ |
---|
79 | virtual int GetFamily() = 0; |
---|
80 | |
---|
81 | /** Address structure is valid. */ |
---|
82 | virtual bool IsValid() = 0; |
---|
83 | |
---|
84 | /** Get a copy of this SocketAddress object. */ |
---|
85 | virtual std::auto_ptr<SocketAddress> GetCopy() = 0; |
---|
86 | }; |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | #ifdef SOCKETS_NAMESPACE |
---|
92 | } // namespace SOCKETS_NAMESPACE { |
---|
93 | #endif |
---|
94 | #endif // _SOCKETS_SocketAddress_H |
---|
95 | |
---|