6 |
|
|
7 |
|
#include "Host.hpp" |
8 |
|
|
9 |
– |
#ifndef _WIN32 |
10 |
– |
|
11 |
– |
static char slash = '/'; |
12 |
– |
|
13 |
– |
#else |
14 |
– |
|
15 |
– |
static char slash = '\\'; |
16 |
– |
|
17 |
– |
#endif |
18 |
– |
|
9 |
|
Host::Host(const string& host, const string& name, const string& address, const |
10 |
|
string& platform) |
11 |
|
{ |
12 |
+ |
memset(&this->address, 0, sizeof(in_addr)); |
13 |
+ |
|
14 |
|
#ifdef _WIN32 |
15 |
|
if (count == 0) |
16 |
|
{ |
52 |
|
|
53 |
|
if (lookup) |
54 |
|
{ |
55 |
< |
struct hostent* ent = gethostbyname(this->name.c_str()); |
55 |
> |
struct hostent* ent(gethostbyname(this->name.c_str())); |
56 |
|
|
57 |
|
memcpy(&address, *(ent->h_addr_list), ent->h_length); |
58 |
|
} |
65 |
|
if (value == INADDR_NONE) |
66 |
|
{ |
67 |
|
cerr << "Host.setAddress(): INADDR_NONE\n"; |
76 |
– |
exit(1); |
68 |
|
} |
69 |
|
else |
70 |
|
{ |
73 |
|
|
74 |
|
if (lookup) |
75 |
|
{ |
76 |
< |
struct hostent* ent = gethostbyaddr((char*)(&this->address), |
77 |
< |
sizeof(in_addr), AF_INET); |
76 |
> |
struct hostent* ent(gethostbyaddr((char*)(&this->address), |
77 |
> |
sizeof(in_addr), AF_INET)); |
78 |
|
|
79 |
|
if (ent != NULL) name = ent->h_name; |
80 |
|
} |
108 |
|
|
109 |
|
Host Host::operator++() |
110 |
|
{ |
111 |
< |
string file = string("hosts") + slash + host; |
121 |
< |
|
111 |
> |
string file(string("hosts") + slash + host); |
112 |
|
ifstream fin(file.c_str()); |
113 |
|
|
114 |
|
if (fin.is_open()) |
116 |
|
getline(fin, name); |
117 |
|
|
118 |
|
string address; |
119 |
< |
|
119 |
> |
|
120 |
|
getline(fin, address); |
121 |
|
|
122 |
< |
in_addr_t value = inet_addr(address.c_str()); |
122 |
> |
in_addr_t value(inet_addr(address.c_str())); |
123 |
|
|
124 |
|
if (value == INADDR_NONE) |
125 |
|
{ |
126 |
|
cerr << "Host.operator++(): INADDR_NONE\n"; |
137 |
– |
exit(1); |
127 |
|
} |
128 |
|
else |
129 |
|
{ |
149 |
|
Host Host::operator--() |
150 |
|
{ |
151 |
|
string file = string("hosts") + slash + host; |
152 |
< |
|
152 |
> |
|
153 |
|
ofstream fout(file.c_str()); |
154 |
|
|
155 |
|
fout << name << '\n' |
172 |
|
|
173 |
|
#ifdef _WIN32 |
174 |
|
|
175 |
< |
unsigned Host::count = 0; |
175 |
> |
unsigned Host::count(0); |
176 |
|
WSADATA Host::data; |
177 |
|
|
178 |
|
#endif |