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 19 by Douglas Thrift, 2003-11-10T19:46:19-08:00

# Line 22 | Line 22 | Host::Host(const string& host, const str
22          count++;
23   #endif
24  
25        this->address = new struct in_addr;
26
25          setHost(host);
26          if (name != "") setName(name, address == "");
27          if (address != "") setAddress(address, name == "");
# Line 32 | Line 30 | Host::Host(const string& host, const str
30  
31   Host::~Host()
32   {
35        delete address;
36
33   #ifdef _WIN32
34          count--;
35  
# Line 56 | Line 52 | void Host::setName(const string& name, b
52          {
53                  struct hostent* ent = gethostbyname(this->name.c_str());
54  
55 <                memcpy(address, *(ent->h_addr_list), ent->h_length);
55 >                memcpy(&address, *(ent->h_addr_list), ent->h_length);
56          }
57   }
58  
# Line 67 | Line 63 | void Host::setAddress(const string& addr
63          if (value == INADDR_NONE)
64          {
65                  cerr << "Host.setAddress(): INADDR_NONE\n";
70                exit(1);
66          }
67          else
68          {
69 <                memcpy(this->address, &value, sizeof(in_addr_t));
69 >                memcpy(&this->address, &value, sizeof(in_addr_t));
70          }
71  
72          if (lookup)
73          {
74 <                struct hostent* ent = gethostbyaddr((char*)(this->address),
74 >                struct hostent* ent = gethostbyaddr((char*)(&this->address),
75                          sizeof(in_addr), AF_INET);
76  
77                  if (ent != NULL) name = ent->h_name;
# Line 89 | Line 84 | bool Host::operator==(const Host& host)
84          {
85                  if (name == host.name)
86                  {
87 <                        if (address == host.address)
87 >                        if (string(inet_ntoa(address)) == inet_ntoa(host.address))
88                          {
89                                  return platform == host.platform;
90                          }
# Line 111 | Line 106 | bool Host::operator==(const Host& host)
106  
107   Host Host::operator++()
108   {
109 <        ifstream fin(host.c_str());
109 >        string file = string("hosts") + slash + host;
110 >
111 >        ifstream fin(file.c_str());
112  
113          if (fin.is_open())
114          {
115                  getline(fin, name);
116 <                fin.read((char*)(address), sizeof(in_addr));
116 >
117 >                string address;
118 >
119 >                getline(fin, address);
120 >
121 >                in_addr_t value = inet_addr(address.c_str());
122 >
123 >                if (value == INADDR_NONE)
124 >                {
125 >                        cerr << "Host.operator++(): INADDR_NONE\n";
126 >                }
127 >                else
128 >                {
129 >                        memcpy(&this->address, &value, sizeof(in_addr_t));
130 >                }
131 >
132                  getline(fin, platform);
133                  fin.close();
134          }
# Line 135 | Line 147 | Host Host::operator++(int)
147  
148   Host Host::operator--()
149   {
150 <        ofstream fout(host.c_str());
139 <
140 <        fout << name << '\n';
150 >        string file = string("hosts") + slash + host;
151  
152 <        fout.write((char*)(address), sizeof(in_addr));
152 >        ofstream fout(file.c_str());
153  
154 <        fout << platform;
154 >        fout << name << '\n'
155 >                << inet_ntoa(address) << '\n'
156 >                << platform << '\n';
157  
158          fout.close();
159  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines