E-MailRelay

gaddresslocal.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 gaddresslocal.h
19///
20
21#ifndef G_NET_ADDRESSLOCAL_H
22#define G_NET_ADDRESSLOCAL_H
23
24#include "gdef.h"
25#include "gaddress.h"
26#include "gstrings.h"
27#include <string>
28#if GCONFIG_HAVE_UDS
29#include <sys/types.h>
30#include <sys/un.h>
31#else
32#ifdef G_DOXYGEN
33 struct sockaddr_un ;
34#else
35 struct sockaddr_un {} ;
36#endif
37#endif
38
39 namespace GNet
40{
41 class AddressLocal ;
42}
43
44//| \class GNet::AddressLocal
45/// A 'sockaddr' wrapper class for local-domain addresses.
46///
47/// Use "netcat -U" or "socat" to connect to local-domain
48/// sockets, eg:
49/// \code
50/// $ nc -U -C /run/cmd.s
51/// $ socat -d tcp-listen:8080,fork unix:/run/cmd.s
52/// \endcode
53///
54 class GNet::AddressLocal
55{
56 public:
57 using sockaddr_type = sockaddr_un ;
58
59 explicit AddressLocal( unsigned int ) ;
60 explicit AddressLocal( const std::string & ) ;
61 AddressLocal( const std::string & , const std::string & ) ;
62 AddressLocal( const std::string & , unsigned int ) ;
63 AddressLocal( unsigned int port , int /*for overload resolution*/ ) ;
64 AddressLocal( const sockaddr * addr , socklen_t len , bool ipv6_scope_id_fixup = false ) ;
65
66 static int domain() noexcept ;
67 static unsigned short af() noexcept ;
68 const sockaddr * address() const ;
69 sockaddr * address() ;
70 socklen_t length() const noexcept ;
71 unsigned long scopeId( unsigned long default_ = 0UL ) const ;
72 unsigned int port() const ;
73 void setPort( unsigned int port ) ;
74 bool setZone( const std::string & ipv6_zone_name_or_scope_id ) ;
75 void setScopeId( unsigned long ipv6_scope_id ) ;
76 static bool validString( const std::string & , std::string * = nullptr ) ;
77 static bool validStrings( const std::string & , const std::string & , std::string * = nullptr ) ;
78 static bool validPort( unsigned int port ) ;
79 static bool validData( const sockaddr * addr , socklen_t len ) ;
80
81 bool same( const AddressLocal & other , bool ipv6_compare_with_scope = false ) const ;
82 bool sameHostPart( const AddressLocal & other ) const ;
83 bool isLoopback() const ;
84 bool isLocal( std::string & ) const ;
85 bool isLinkLocal() const ;
86 bool isUniqueLocal() const ;
87 bool isAny() const ;
88 unsigned int bits() const ;
89 std::string displayString( bool ipv6_with_scope = false ) const ;
90 std::string hostPartString( bool raw = false ) const ;
91 std::string queryString() const ;
92 G::StringArray wildcards() const ;
93 static bool format( const std::string & ) ;
94
95 private:
96 explicit AddressLocal( std::nullptr_t ) ;
97 std::string path() const ;
98
99 private:
100 sockaddr_type m_local ;
101 std::size_t m_size ;
102} ;
103
104#endif
GNet::AddressLocal
A 'sockaddr' wrapper class for local-domain addresses.
Definition: gaddresslocal.h:55
gaddress.h
gstrings.h
GNet
Network classes.
Definition: gdef.h:1115
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31