root/trunk/dep/include/sockets/SocketAddress.h @ 2

Revision 2, 2.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/**
2 **     \file SocketAddress.h
3 **     \date  2006-09-21
4 **     \author grymse@alhem.net
5**/
6/*
7Copyright (C) 2007  Anders Hedstrom
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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
32namespace 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*/
46class SocketAddress
47{
48public:
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
Note: See TracBrowser for help on using the browser.