ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdate/Host.cpp
(Generate patch)

Comparing HostUpdate/Host.cpp (file contents):
Revision 13 by Douglas Thrift, 2003-11-07T12:17:57-08:00 vs.
Revision 15 by Douglas Thrift, 2003-11-09T16:51:42-08:00

# Line 6 | Line 6
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 +
19   Host::Host(const string& host, const string& name, const string& address, const
20          string& platform)
21   {
# Line 22 | Line 32 | Host::Host(const string& host, const str
32          count++;
33   #endif
34  
25        this->address = new struct in_addr;
26
35          setHost(host);
36          if (name != "") setName(name, address == "");
37          if (address != "") setAddress(address, name == "");
# Line 32 | Line 40 | Host::Host(const string& host, const str
40  
41   Host::~Host()
42   {
35        delete address;
36
43   #ifdef _WIN32
44          count--;
45  
# Line 56 | Line 62 | void Host::setName(const string& name, b
62          {
63                  struct hostent* ent = gethostbyname(this->name.c_str());
64  
65 <                memcpy(address, *(ent->h_addr_list), ent->h_length);
65 >                memcpy(&address, *(ent->h_addr_list), ent->h_length);
66          }
67   }
68  
# Line 71 | Line 77 | void Host::setAddress(const string& addr
77          }
78          else
79          {
80 <                memcpy(this->address, &value, sizeof(in_addr_t));
80 >                memcpy(&this->address, &value, sizeof(in_addr_t));
81          }
82  
83          if (lookup)
84          {
85 <                struct hostent* ent = gethostbyaddr((char*)(this->address),
85 >                struct hostent* ent = gethostbyaddr((char*)(&this->address),
86                          sizeof(in_addr), AF_INET);
87  
88                  if (ent != NULL) name = ent->h_name;
# Line 89 | Line 95 | bool Host::operator==(const Host& host)
95          {
96                  if (name == host.name)
97                  {
98 <                        if (address == host.address)
98 >                        if (string(inet_ntoa(address)) == inet_ntoa(host.address))
99                          {
100                                  return platform == host.platform;
101                          }
# Line 111 | Line 117 | bool Host::operator==(const Host& host)
117  
118   Host Host::operator++()
119   {
120 <        ifstream fin(host.c_str());
120 >        string file = string("hosts") + slash + host;
121 >
122 >        ifstream fin(file.c_str());
123  
124          if (fin.is_open())
125          {
126                  getline(fin, name);
127 <                fin.read((char*)(address), sizeof(in_addr));
127 >
128 >                string address;
129 >                
130 >                getline(fin, address);
131 >
132 >                in_addr_t value = inet_addr(address.c_str());
133 >
134 >                if (value == INADDR_NONE)
135 >                {
136 >                        cerr << "Host.operator++(): INADDR_NONE\n";
137 >                        exit(1);
138 >                }
139 >                else
140 >                {
141 >                        memcpy(&this->address, &value, sizeof(in_addr_t));
142 >                }
143 >
144                  getline(fin, platform);
145                  fin.close();
146          }
# Line 135 | Line 159 | Host Host::operator++(int)
159  
160   Host Host::operator--()
161   {
162 <        ofstream fout(host.c_str());
163 <
164 <        fout << name << '\n';
165 <
166 <        fout.write((char*)(address), sizeof(in_addr));
167 <
168 <        fout << platform;
162 >        string file = string("hosts") + slash + host;
163 >        
164 >        ofstream fout(file.c_str());
165 >
166 >        fout << name << '\n'
167 >                << inet_ntoa(address) << '\n'
168 >                << platform << '\n';
169  
170          fout.close();
171  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines