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"
32 #ifdef SOCKETS_NAMESPACE
33 namespace SOCKETS_NAMESPACE
{
38 This class and its subclasses is intended to be used as replacement
39 for the internal data type 'ipaddr_t' and various implementations of
40 IPv6 addressing found throughout the library.
41 'ipaddr_t' is an IPv4 address in network byte order.
42 'port_t' is the portnumber in host byte order.
43 'struct in6_addr' is an IPv6 address.
44 'struct in_addr' is an IPv4 address.
50 virtual ~SocketAddress() {}
52 /** Get a pointer to the address struct. */
53 virtual operator struct sockaddr
*() = 0;
55 /** Get length of address struct. */
56 virtual operator socklen_t() = 0;
58 /** Compare two addresses. */
59 virtual bool operator==(SocketAddress
&) = 0;
62 \param port Port number in host byte order */
63 virtual void SetPort(port_t port
) = 0;
66 \return Port number in host byte order. */
67 virtual port_t
GetPort() = 0;
69 /** Set socket address.
70 \param sa Pointer to either 'struct sockaddr_in' or 'struct sockaddr_in6'. */
71 virtual void SetAddress(struct sockaddr
*sa
) = 0;
73 /** Convert address to text. */
74 virtual std::string
Convert(bool include_port
) = 0;
76 /** Reverse lookup of address. */
77 virtual std::string
Reverse() = 0;
79 /** Get address family. */
80 virtual int GetFamily() = 0;
82 /** Address structure is valid. */
83 virtual bool IsValid() = 0;
85 /** Get a copy of this SocketAddress object. */
86 virtual std::auto_ptr
<SocketAddress
> GetCopy() = 0;
92 #ifdef SOCKETS_NAMESPACE
93 } // namespace SOCKETS_NAMESPACE {
95 #endif // _SOCKETS_SocketAddress_H