glocal.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // ===
20 
21 #ifndef G_GNET_LOCAL_H
22 #define G_GNET_LOCAL_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gaddress.h"
27 #include "gexception.h"
28 
30 namespace GNet
31 {
32  class Local ;
33 }
34 
40 {
41 public:
42  G_EXCEPTION( Error , "local domainname/hostname error" ) ;
43 
44  static std::string hostname() ;
48 
49  static Address canonicalAddress() ;
51 
52  static std::string fqdn() ;
57 
58  static std::string domainname() ;
61 
62  static void fqdn( const std::string & fqdn_override ) ;
64 
65  static Address localhostAddress() ;
67 
68  static bool isLocal( const Address & ) ;
72 
73  static bool isLocal( const Address & , std::string & reason ) ;
76 
77 private:
78  static std::string m_fqdn ;
79  static std::string m_fqdn_override ;
80  static bool m_fqdn_override_set ;
81  static Address m_canonical_address ;
82  static std::string fqdnImp() ;
83  static Address canonicalAddressImp() ;
84  Local() ;
85 } ;
86 
87 #endif
88 
static Address localhostAddress()
A convenience function that returns the "127.0.0.1:0" address.
Definition: glocal.cpp:62
static std::string hostname()
Returns the hostname.
Definition: glocal.cpp:33
Network classes.
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
static bool isLocal(const Address &)
Returns true if the given address appears to be local.
Definition: glocal.cpp:82
static std::string fqdn()
Returns the fully-qualified-domain-name.
Definition: glocal.cpp:67
A static class for getting information about the local machine's network name and address...
Definition: glocal.h:39
static std::string domainname()
Returns the fqdn()'s domainname.
Definition: glocal.cpp:51
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
static Address canonicalAddress()
Returns the canonical address associated with hostname().
Definition: glocal.cpp:41