2 ** \file SocketAddress.h
4 ** \author grymse@alhem.net
7 Copyright (C) 2007 Anders Hedstrom
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.
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.
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.
23 #ifndef _SOCKETS_SocketAddress_H
24 #define _SOCKETS_SocketAddress_H
26 #include "sockets-config.h"
29 #include "socket_include.h"
31 #ifdef SOCKETS_NAMESPACE
32 namespace SOCKETS_NAMESPACE
{
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.
49 virtual ~SocketAddress() {}
51 /** Get a pointer to the address struct. */
52 virtual operator struct sockaddr
*() = 0;
54 /** Get length of address struct. */
55 virtual operator socklen_t() = 0;
57 /** Compare two addresses. */
58 virtual bool operator==(SocketAddress
&) = 0;
61 \param port Port number in host byte order */
62 virtual void SetPort(port_t port
) = 0;
65 \return Port number in host byte order. */
66 virtual port_t
GetPort() = 0;
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;
72 /** Convert address to text. */
73 virtual std::string
Convert(bool include_port
) = 0;
75 /** Reverse lookup of address. */
76 virtual std::string
Reverse() = 0;
78 /** Get address family. */
79 virtual int GetFamily() = 0;
81 /** Address structure is valid. */
82 virtual bool IsValid() = 0;
84 /** Get a copy of this SocketAddress object. */
85 virtual std::auto_ptr
<SocketAddress
> GetCopy() = 0;
91 #ifdef SOCKETS_NAMESPACE
92 } // namespace SOCKETS_NAMESPACE {
94 #endif // _SOCKETS_SocketAddress_H