E-MailRelay
gaddress6.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gaddress6.h
19 ///
20 /// This file is formatted for side-by-side comparison with gaddress4.h.
21 
22 #ifndef G_NET_ADDRESS6__H
23 #define G_NET_ADDRESS6__H
24 
25 #include "gdef.h"
26 #include "gaddress.h"
27 #include <string>
28 
29 namespace GNet
30 {
31  class Address6 ;
32 }
33 
34 /// \class GNet::Address6
35 /// A 'sockaddr' wrapper class for IPv6 addresses.
36 ///
38 {
39 public:
40  typedef sockaddr general_type ;
41  typedef sockaddr_in6 specific_type ;
42  typedef sockaddr_storage storage_type ;
43  union union_type /// Used by GNet::Address6 to cast between sockaddr and sockaddr_in6.
44  { specific_type specific ; general_type general ; storage_type storage ; } ;
45 
46  explicit Address6( unsigned int ) ;
47  explicit Address6( const std::string & ) ;
48  Address6( const std::string & , const std::string & ) ;
49  Address6( const std::string & , unsigned int ) ;
50  Address6( unsigned int port , int /*for overload resolution*/ ) ; // canonical loopback address
51  Address6( const sockaddr * addr , socklen_t len ) ;
52  Address6( const Address6 & other ) ;
53 
54  static int domain() ;
55  static unsigned short family() ;
56  const sockaddr * address() const ;
57  sockaddr * address() ;
58  static socklen_t length() ;
59  unsigned long scopeId() const ;
60  unsigned int port() const ;
61  void setPort( unsigned int port ) ;
62 
63  static bool validString( const std::string & , std::string * = nullptr ) ;
64  static bool validStrings( const std::string & , const std::string & , std::string * = nullptr ) ;
65  static bool validPort( unsigned int port ) ;
66  static bool validData( const sockaddr * addr , socklen_t len ) ;
67 
68  bool same( const Address6 & other ) const ;
69  bool sameHostPart( const Address6 & other ) const ;
70  bool isLoopback() const ;
71  bool isLocal( std::string & ) const ;
72 
73  std::string displayString() const ;
74  std::string hostPartString() const ;
75  G::StringArray wildcards() const ;
76 
77 
78 private:
79  void init() ;
80  static const char * setAddress( union_type & , const std::string & ) ;
81  static const char * setHostAddress( union_type & , const std::string & ) ;
82  static const char * setPort( union_type & , unsigned int ) ;
83  static const char * setPort( union_type & , const std::string & ) ;
84  static bool sameAddr( const ::in6_addr & a , const ::in6_addr & b ) ;
85  static void setZone( union_type & , unsigned int ) ;
86 
87 
88 private:
89  union_type m_inet ;
90 } ;
91 
92 #endif
Used by GNet::Address6 to cast between sockaddr and sockaddr_in6.
Definition: gaddress6.h:43
Network classes.
Definition: gaddress.h:29
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
A 'sockaddr' wrapper class for IPv6 addresses.
Definition: gaddress6.h:37