E-MailRelay
gaddress4.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 gaddress4.h
19///
20
21#ifndef G_NET_ADDRESS4_H
22#define G_NET_ADDRESS4_H
23
24#include "gdef.h"
25#include "gaddress.h"
26#include <string>
27
28namespace GNet
29{
30 class Address4 ;
31}
32
33//| \class GNet::Address4
34/// A 'sockaddr' wrapper class for IPv4 addresses.
35///
37{
38public:
39 using sockaddr_type = sockaddr_in ;
40
41 explicit Address4( unsigned int ) ;
42 explicit Address4( const std::string & ) ;
43 Address4( const std::string & , const std::string & ) ;
44 Address4( const std::string & , unsigned int ) ;
45 Address4( unsigned int port , int /*loopback_overload*/ ) ; // canonical loopback address
46 Address4( 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 Address4 & other , bool ipv6_compare_with_scope = false ) const ;
64 bool sameHostPart( const Address4 & other ) 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 static bool format( std::string ) ;
76
77private:
78 explicit Address4( std::nullptr_t ) ;
79 static const char * setAddress( sockaddr_type & , const std::string & ) ;
80 static const char * setHostAddress( sockaddr_type & , const std::string & ) ;
81 static const char * setPort( sockaddr_type & , unsigned int ) ;
82 static const char * setPort( sockaddr_type & , const std::string & ) ;
83 static bool sameAddr( const ::in_addr & a , const ::in_addr & b ) ;
84 static void add( G::StringArray & , const std::string & , unsigned int , const char * ) ;
85 static void add( G::StringArray & , const std::string & , const char * ) ;
86
87private:
88 sockaddr_type m_inet ;
89} ;
90
91#endif
A 'sockaddr' wrapper class for IPv4 addresses.
Definition: gaddress4.h:37
Network classes.
Definition: gdef.h:1115
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31