minor changes
[anytun.git] / Sockets / Ipv6Address.h
bloba0711417956523e00e3eef9920ea19b741b0b4d8
1 /**
2 ** \file Ipv6Address.h
3 ** \date 2006-09-21
4 ** \author grymse@alhem.net
5 **/
6 /*
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_Ipv6Address_H
24 #define _SOCKETS_Ipv6Address_H
25 #include "sockets-config.h"
26 #ifdef ENABLE_IPV6
28 #include "SocketAddress.h"
29 #ifdef IPPROTO_IPV6
30 #if defined( _WIN32) && !defined(__CYGWIN__)
31 typedef unsigned __int32 uint32_t;
32 #endif
34 #ifdef SOCKETS_NAMESPACE
35 namespace SOCKETS_NAMESPACE {
36 #endif
39 /** Ipv6 address implementation.
40 \ingroup basic */
41 class Ipv6Address : public SocketAddress
43 public:
44 /** Create empty Ipv6 address structure.
45 \param port Port number */
46 Ipv6Address(port_t port = 0);
47 /** Create Ipv6 address structure.
48 \param a Socket address in network byte order
49 \param port Port number in host byte order */
50 Ipv6Address(struct in6_addr& a,port_t port);
51 /** Create Ipv6 address structure.
52 \param host Hostname to be resolved
53 \param port Port number in host byte order */
54 Ipv6Address(const std::string& host,port_t port);
55 Ipv6Address(struct sockaddr_in6&);
56 ~Ipv6Address();
58 // SocketAddress implementation
60 operator struct sockaddr *();
61 operator socklen_t();
62 bool operator==(SocketAddress&);
64 void SetPort(port_t port);
65 port_t GetPort();
67 void SetAddress(struct sockaddr *sa);
68 int GetFamily();
70 bool IsValid();
71 std::auto_ptr<SocketAddress> GetCopy();
73 /** Convert address struct to text. */
74 std::string Convert(bool include_port = false);
75 std::string Reverse();
77 /** Resolve hostname. */
78 static bool Resolve(const std::string& hostname,struct in6_addr& a);
79 /** Reverse resolve (IP to hostname). */
80 static bool Reverse(struct in6_addr& a,std::string& name);
81 /** Convert address struct to text. */
82 static std::string Convert(struct in6_addr& a,bool mixed = false);
84 void SetFlowinfo(uint32_t);
85 uint32_t GetFlowinfo();
86 #ifndef _WIN32
87 void SetScopeId(uint32_t);
88 uint32_t GetScopeId();
89 #endif
91 private:
92 Ipv6Address(const Ipv6Address& ) {} // copy constructor
93 Ipv6Address& operator=(const Ipv6Address& ) { return *this; } // assignment operator
94 struct sockaddr_in6 m_addr;
95 bool m_valid;
101 #ifdef SOCKETS_NAMESPACE
102 } // namespace SOCKETS_NAMESPACE {
103 #endif
104 #endif // IPPROTO_IPV6
105 #endif // ENABLE_IPV6
106 #endif // _SOCKETS_Ipv6Address_H