E-MailRelay
gaddress6.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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
21#ifndef G_NET_ADDRESS6_H
22#define G_NET_ADDRESS6_H
23
24#include "gdef.h"
25#include "gaddress.h"
26#include <string>
27
28namespace GNet
29{
30 class Address6 ;
31}
32
33//| \class GNet::Address6
34/// A 'sockaddr' wrapper class for IPv6 addresses.
35///
37{
38public:
39 using sockaddr_type = sockaddr_in6 ;
40
41 explicit Address6( unsigned int ) ;
42 explicit Address6( const std::string & ) ;
43 Address6( const std::string & , const std::string & ) ;
44 Address6( const std::string & , unsigned int ) ;
45 Address6( unsigned int port , int /*for overload resolution*/ ) ; // canonical loopback address
46 Address6( const sockaddr * addr , socklen_t len , bool ipv6_scope_id_fixup = false ) ;
47
48 static int domain() noexcept ;
49 static unsigned short af() noexcept ;
50 const sockaddr * address() const ;
51 sockaddr * address() ;
52 static socklen_t length() noexcept ;
53 unsigned long scopeId( unsigned long default_ = 0UL ) const ;
54 unsigned int port() const ;
55 void setPort( unsigned int port ) ;
56 bool setZone( const std::string & ipv6_zone_name_or_scope_id ) ;
57 void setScopeId( unsigned long ipv6_scope_id ) ;
58 static bool validString( const std::string & , std::string * = nullptr ) ;
59 static bool validStrings( const std::string & , const std::string & , std::string * = nullptr ) ;
60 static bool validPort( unsigned int port ) ;
61 static bool validData( const sockaddr * addr , socklen_t len ) ;
62
63 bool same( const Address6 & other , bool ipv6_compare_with_scope = false ) const ;
64 bool sameHostPart( const Address6 & other , bool ipv6_compare_with_scope = false ) const ;
65 bool isLoopback() const ;
66 bool isLocal( std::string & ) const ;
67 bool isLinkLocal() const ;
68 bool isUniqueLocal() const ;
69 bool isAny() const ;
70 unsigned int bits() const ;
71 std::string displayString( bool ipv6_with_scope = false ) const ;
72 std::string hostPartString( bool raw = false ) const ;
73 std::string queryString() const ;
74 G::StringArray wildcards() const ;
75
76private:
77 explicit Address6( std::nullptr_t ) ;
78 static const char * setAddress( sockaddr_type & , const std::string & ) ;
79 static const char * setHostAddress( sockaddr_type & , const std::string & ) ;
80 static const char * setPort( sockaddr_type & , unsigned int ) ;
81 static const char * setPort( sockaddr_type & , const std::string & ) ;
82 static bool sameAddr( const ::in6_addr & a , const ::in6_addr & b ) ;
83 static bool setZone( sockaddr_type & , const std::string & ) ;
84
85private:
86 sockaddr_type m_inet ;
87} ;
88
89#endif
A 'sockaddr' wrapper class for IPv6 addresses.
Definition: gaddress6.h:37
bool isLoopback() const
Definition: gaddress6.cpp:456
Network classes.
Definition: gdef.h:1115
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31