1 karl 1.25 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.6 //
|
3 karl 1.23 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.19 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.23 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.25 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.6 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.11 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.6 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 karl 1.23 //
|
19 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.6 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.11 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.6 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
|
32 mike 1.7 // Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01
|
33 ramnath 1.9 // added nsk platform support
34 // Ramnath Ravindran (Ramnath.Ravindran@compaq.com) 03/21/2002
|
35 r.kieninger 1.21 // replaced instances of "| ios::binary" with
|
36 ramnath 1.9 // PEGASUS_OR_IOS_BINARY
|
37 r.kieninger 1.21 // Robert Kieninger, IBM (kieningr@de.ibm.com) for Bug#667
|
38 dave.sudlik 1.22 // Dave Sudlik, IBM (dsudlik@us.ibm.com) for Bug#1462
|
39 gs.keenan 1.26 // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
|
40 mike 1.6 //
41 //%/////////////////////////////////////////////////////////////////////////////
|
42 mike 1.8
|
43 sage 1.12 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
44 r.kieninger 1.21 #include <Pegasus/Common/Config.h>
45 #endif
|
46 sage 1.12
47
|
48 mike 1.8 #include <fstream>
|
49 kumpf 1.13 #include <cctype> // for tolower()
|
50 kumpf 1.14 #include <cstring>
|
51 mike 1.6 #include "System.h"
|
52 r.kieninger 1.21 #include "Socket.h"
53
54 #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
55 # include <windows.h>
56 #else
57 # include <arpa/inet.h>
58 #endif
|
59 mike 1.6
|
60 kumpf 1.10 #include <Pegasus/Common/PegasusVersion.h>
61
|
62 mike 1.6 #if defined(PEGASUS_OS_TYPE_WINDOWS)
63 # include "SystemWindows.cpp"
64 #elif defined(PEGASUS_OS_TYPE_UNIX)
65 # include "SystemUnix.cpp"
|
66 mike 1.7 #elif defined(PEGASUS_OS_TYPE_NSK)
67 # include "SystemNsk.cpp"
|
68 gs.keenan 1.26 #elif defined(PEGASUS_OS_VMS)
69 # include "SystemVms.cpp"
|
70 mike 1.6 #else
71 # error "Unsupported platform"
72 #endif
|
73 mike 1.8
|
74 david 1.16 #if defined(PEGASUS_OS_OS400)
75 # include "OS400ConvertChar.h"
76 #endif
77
|
78 mike 1.8 PEGASUS_USING_STD;
79
80 PEGASUS_NAMESPACE_BEGIN
81
|
82 kumpf 1.20 Boolean System::bindVerbose = false;
83
|
84 mike 1.8 Boolean System::copyFile(const char* fromPath, const char* toPath)
85 {
|
86 ramnath 1.9 ifstream is(fromPath PEGASUS_IOS_BINARY);
87 ofstream os(toPath PEGASUS_IOS_BINARY);
|
88 mike 1.8
89 char c;
90
91 while (is.get(c))
92 {
93 if (!os.put(c))
94 return false;
95 }
96
97 return true;
|
98 kumpf 1.13 }
99
100 // ATTN: Move to platform-specific System implementation files and call
101 // strcasecmp where it is available.
102 Sint32 System::strcasecmp(const char* s1, const char* s2)
103 {
104 while (*s1 && *s2)
105 {
106 int r = tolower(*s1++) - tolower(*s2++);
107
108 if (r)
109 return r;
110 }
111
112 if (*s2)
113 return -1;
114 else if (*s1)
115 return 1;
116
117 return 0;
|
118 mike 1.8 }
119
|
120 tony 1.15 // Return the just the file name from the path into basename
121 char *System::extract_file_name(const char *fullpath, char *basename)
122 {
123 char *p;
124 char buff[2048];
125 if (fullpath == NULL)
126 {
127 basename[0] = '\0';
128 return basename;
129 }
130 strcpy(buff, fullpath);
131 for(p = buff + strlen(buff); p >= buff; p--)
132 {
133 if (*p == '\\' || *p == '/')
134 {
135 strcpy(basename, p+1);
136 return basename;
137 }
138 }
139 strcpy(basename, fullpath);
140 return basename;
141 tony 1.15 }
142
143 // Return the just the path to the file name into dirname
144 char *System::extract_file_path(const char *fullpath, char *dirname)
145 {
146 char *p;
147 char buff[2048];
148 if (fullpath == NULL)
149 {
150 dirname[0] = '\0';
151 return dirname;
152 }
153 strcpy(buff, fullpath);
154 for(p = buff + strlen(buff); p >= buff; p--)
155 {
156 if (*p == '\\' || *p == '/')
157 {
158 strncpy(dirname, buff, p+1 - buff);
159 dirname[p+1 - buff] = '\0';
160 return dirname;
161 }
162 tony 1.15 }
163 strcpy(dirname, fullpath);
164 return dirname;
165 }
166
|
167 marek 1.24 String System::getHostIP(const String &hostName)
168 {
169 struct hostent * phostent;
170 struct in_addr inaddr;
171 String ipAddress = String::EMPTY;
172
173 if ((phostent = ::gethostbyname((const char *)hostName.getCString())) != NULL)
174 {
175 ::memcpy( &inaddr, phostent->h_addr,4);
176 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
177 char * gottenIPAdress = NULL;
178 gottenIPAdress = ::inet_ntoa( inaddr );
179 __etoa(gottenIPAdress);
180 if (gottenIPAdress != NULL)
181 {
182 ipAddress.assign(gottenIPAdress);
183 }
184 #else
185 ipAddress = ::inet_ntoa( inaddr );
186 #endif
187 }
188 marek 1.24 return ipAddress;
189 }
|
190 r.kieninger 1.21
191 // ------------------------------------------------------------------------
192 // Convert a hostname into a a single host unique integer representation
193 // ------------------------------------------------------------------------
194 Uint32 System::_acquireIP(const char* hostname)
195 {
196 Uint32 ip = 0xFFFFFFFF;
197 if (!hostname) return 0xFFFFFFFF;
198
199 #ifdef PEGASUS_OS_OS400
200 char ebcdicHost[PEGASUS_MAXHOSTNAMELEN];
201 if (strlen(hostname) < PEGASUS_MAXHOSTNAMELEN)
202 strcpy(ebcdicHost, hostname);
203 else
204 return 0xFFFFFFFF;
205 AtoE(ebcdicHost);
206 #endif
207
|
208 dave.sudlik 1.22 ////////////////////////////////////////////////////////////////////////////////
209 // This code used to check if the first character of "hostname" was alphabetic
210 // to indicate hostname instead of IP address. But RFC 1123, section 2.1, relaxed
211 // this requirement to alphabetic character *or* digit. So bug 1462 changed the
212 // flow here to call inet_addr first to check for a valid IP address in dotted
213 // decimal notation. If it's not a valid IP address, then try to validate
214 // it as a hostname.
215 // RFC 1123 states: The host SHOULD check the string syntactically for a
216 // dotted-decimal number before looking it up in the Domain Name System.
217 // Hence the call to inet_addr() first.
218 ////////////////////////////////////////////////////////////////////////////////
219
220 #ifdef PEGASUS_OS_OS400
221 Uint32 tmp_addr = inet_addr(ebcdicHost);
222 #elif defined(PEGASUS_OS_ZOS)
223 Uint32 tmp_addr = inet_addr_ebcdic((char *)hostname);
224 #else
225 Uint32 tmp_addr = inet_addr((char *) hostname);
226 #endif
227
|
228 r.kieninger 1.21 struct hostent *entry;
229
|
230 dave.sudlik 1.22 // Note: 0xFFFFFFFF is actually a valid IP address (255.255.255.255).
231 // A better solution would be to use inet_aton() or equivalent, as
232 // inet_addr() is now considered "obsolete".
233
234 if (tmp_addr == 0xFFFFFFFF) // if hostname is not an IP address
|
235 r.kieninger 1.21 {
236 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
237 #define HOSTENT_BUFF_SIZE 8192
238 char buf[HOSTENT_BUFF_SIZE];
239 int h_errorp;
240 struct hostent hp;
241
242 entry = gethostbyname_r((char *)hostname, &hp, buf,
243 HOSTENT_BUFF_SIZE, &h_errorp);
244 #elif defined(PEGASUS_OS_OS400)
245 entry = gethostbyname(ebcdicHost);
246 #elif defined(PEGASUS_OS_ZOS)
247 char hostName[ PEGASUS_MAXHOSTNAMELEN ];
248 if (String::equalNoCase("localhost",String(hostname)))
249 {
250 gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );
251 entry = gethostbyname(hostName);
252 } else
253 {
254 entry = gethostbyname((char *)hostname);
255 }
256 r.kieninger 1.21 #else
257 entry = gethostbyname((char *)hostname);
258 #endif
259 if (!entry)
260 {
261 return 0xFFFFFFFF;
262 }
263 unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
264
265 ip_part1 = entry->h_addr[0];
266 ip_part2 = entry->h_addr[1];
267 ip_part3 = entry->h_addr[2];
268 ip_part4 = entry->h_addr[3];
269 ip = ip_part1;
270 ip = (ip << 8) + ip_part2;
271 ip = (ip << 8) + ip_part3;
272 ip = (ip << 8) + ip_part4;
|
273 dave.sudlik 1.22 }
274 else // else hostname *is* a dotted-decimal IP address
|
275 r.kieninger 1.21 {
276 // resolve hostaddr to a real host entry
277 // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms
278 entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
279
280 if (entry == 0)
281 {
282 // error, couldn't resolve the ip
283 return 0xFFFFFFFF;
284 } else
285 {
286
287 unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
288
289 ip_part1 = entry->h_addr[0];
290 ip_part2 = entry->h_addr[1];
291 ip_part3 = entry->h_addr[2];
292 ip_part4 = entry->h_addr[3];
293 ip = ip_part1;
294 ip = (ip << 8) + ip_part2;
295 ip = (ip << 8) + ip_part3;
296 r.kieninger 1.21 ip = (ip << 8) + ip_part4;
297 }
298 }
299
300 return ip;
301 }
302
|
303 tony 1.17 // System ID constants for Logger::put and Logger::trace
304 const String System::CIMLISTENER = "cimlistener"; // Listener systme ID
305
|
306 mike 1.8 PEGASUS_NAMESPACE_END
|