Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
local_identity Struct Reference
Collaboration diagram for local_identity:

Public Member Functions

void initialize ()
 
bool contains (const string &name) const
 

Public Attributes

vector< fc::ip::addressaddrs
 
vector< string > names
 

Detailed Description

Definition at line 51 of file main.cpp.

Member Function Documentation

◆ contains()

bool local_identity::contains ( const string & name) const
inline

Definition at line 94 of file main.cpp.

94 {
95 try {
97 for (const auto &a : addrs) {
98 if (a == test)
99 return true;
100 }
101 }
102 catch (...) {
103 // not an ip address
104 for (const auto& n : names) {
105 if (n == name)
106 return true;
107 }
108 }
109 return false;
110 }
std::string name
@ test
Unit testing utility error code.
Definition error.hpp:96
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
vector< string > names
Definition main.cpp:53
vector< fc::ip::address > addrs
Definition main.cpp:52

◆ initialize()

void local_identity::initialize ( )
inline

Definition at line 55 of file main.cpp.

55 {
56 names.push_back ("localhost");
57 names.push_back ("127.0.0.1");
58
59 boost::system::error_code ec;
60 string hn = host_name (ec);
61 if (ec.value() != boost::system::errc::success) {
62 cerr << "unable to retrieve host name: " << ec.message() << endl;
63 }
64 else {
65 names.push_back (hn);
66 if (hn.find ('.') != string::npos) {
67 names.push_back (hn.substr (0,hn.find('.')));
68 }
69 }
70
71 ifaddrs *ifap = 0;
72 if (::getifaddrs (&ifap) == 0) {
73 for (ifaddrs *p_if = ifap; p_if != 0; p_if = p_if->ifa_next) {
74 if (p_if->ifa_addr != 0 &&
75 p_if->ifa_addr->sa_family == AF_INET &&
76 (p_if->ifa_flags & IFF_UP) == IFF_UP) {
77 sockaddr_in *ifaddr = reinterpret_cast<sockaddr_in *>(p_if->ifa_addr);
78 int32_t in_addr = ntohl(ifaddr->sin_addr.s_addr);
79
80 if (in_addr != 0) {
81 fc::ip::address ifa(in_addr);
82 addrs.push_back (ifa);
83 }
84 }
85 }
86 ::freeifaddrs (ifap);
87 }
88 else {
89 cerr << "unable to query local ip interfaces" << endl;
90 addrs.push_back (fc::ip::address("127.0.0.1"));
91 }
92 }
std::ostream & cerr()
signed int int32_t
Definition stdint.h:123

Member Data Documentation

◆ addrs

vector<fc::ip::address> local_identity::addrs

Definition at line 52 of file main.cpp.

◆ names

vector<string> local_identity::names

Definition at line 53 of file main.cpp.


The documentation for this struct was generated from the following file: