E-MailRelay
glocal.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 glocal.h
19///
20
21#ifndef G_NET_LOCAL_H
22#define G_NET_LOCAL_H
23
24#include "gdef.h"
25#include "gaddress.h"
26#include "glocation.h"
27#include "gexception.h"
28
29namespace GNet
30{
31 class Local ;
32}
33
34//| \class GNet::Local
35/// A static class for getting information about the local machine's network
36/// name and address.
37///
39{
40public:
41 static std::string hostname() ;
42 ///< Returns the local hostname. Returns "localhost" on error.
43
44 static std::string canonicalName() ;
45 ///< Returns the canonical network name assiciated with hostname().
46 ///< Defaults to "<hostname>.localnet" if DNS does not provide
47 ///< a canonical network name.
48
49 static void canonicalName( const std::string & override ) ;
50 ///< Sets the canonicalName() override.
51
52 static bool isLocal( const Address & , std::string & reason ) ;
53 ///< Returns true if the given address appears to be 'local',
54 ///< or a helpful error message if not.
55
56 static bool isLocal( const Address & ) ;
57 ///< Overload without an explanation.
58
59public:
60 Local() = delete ;
61
62private:
63 static std::string resolvedHostname() ;
64
65private:
66 static std::string m_name_override ;
67 static bool m_name_override_set ;
68} ;
69
70#endif
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:53
A static class for getting information about the local machine's network name and address.
Definition: glocal.h:39
static bool isLocal(const Address &, std::string &reason)
Returns true if the given address appears to be 'local', or a helpful error message if not.
Definition: glocal.cpp:64
static std::string canonicalName()
Returns the canonical network name assiciated with hostname().
Definition: glocal.cpp:53
static std::string hostname()
Returns the local hostname. Returns "localhost" on error.
Definition: glocal.cpp:31
Network classes.
Definition: gdef.h:1115