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 mike 1.6 //
40 //%/////////////////////////////////////////////////////////////////////////////
|
41 mike 1.8
|
42 sage 1.12 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
43 r.kieninger 1.21 #include <Pegasus/Common/Config.h>
44 #endif
|
45 sage 1.12
46
|
47 mike 1.8 #include <fstream>
|
48 kumpf 1.13 #include <cctype> // for tolower()
|
49 kumpf 1.14 #include <cstring>
|
50 mike 1.6 #include "System.h"
|
51 r.kieninger 1.21 #include "Socket.h"
52
53 #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
54 # include <windows.h>
55 #else
56 # include <arpa/inet.h>
57 #endif
|
58 mike 1.6
|
59 kumpf 1.10 #include <Pegasus/Common/PegasusVersion.h>
60
|
61 mike 1.6 #if defined(PEGASUS_OS_TYPE_WINDOWS)
62 # include "SystemWindows.cpp"
63 #elif defined(PEGASUS_OS_TYPE_UNIX)
64 # include "SystemUnix.cpp"
|
65 mike 1.7 #elif defined(PEGASUS_OS_TYPE_NSK)
66 # include "SystemNsk.cpp"
|
67 mike 1.6 #else
68 # error "Unsupported platform"
69 #endif
|
70 mike 1.8
|
71 david 1.16 #if defined(PEGASUS_OS_OS400)
72 # include "OS400ConvertChar.h"
73 #endif
74
|
75 mike 1.8 PEGASUS_USING_STD;
76
77 PEGASUS_NAMESPACE_BEGIN
78
|
79 kumpf 1.20 Boolean System::bindVerbose = false;
80
|
81 mike 1.8 Boolean System::copyFile(const char* fromPath, const char* toPath)
82 {
|
83 ramnath 1.9 ifstream is(fromPath PEGASUS_IOS_BINARY);
84 ofstream os(toPath PEGASUS_IOS_BINARY);
|
85 mike 1.8
86 char c;
87
88 while (is.get(c))
89 {
90 if (!os.put(c))
91 return false;
92 }
93
94 return true;
|
95 kumpf 1.13 }
96
97 // ATTN: Move to platform-specific System implementation files and call
98 // strcasecmp where it is available.
99 Sint32 System::strcasecmp(const char* s1, const char* s2)
100 {
101 while (*s1 && *s2)
102 {
103 int r = tolower(*s1++) - tolower(*s2++);
104
105 if (r)
106 return r;
107 }
108
109 if (*s2)
110 return -1;
111 else if (*s1)
112 return 1;
113
114 return 0;
|
115 mike 1.8 }
116
|
117 tony 1.15 // Return the just the file name from the path into basename
118 char *System::extract_file_name(const char *fullpath, char *basename)
119 {
120 char *p;
121 char buff[2048];
122 if (fullpath == NULL)
123 {
124 basename[0] = '\0';
125 return basename;
126 }
127 strcpy(buff, fullpath);
128 for(p = buff + strlen(buff); p >= buff; p--)
129 {
130 if (*p == '\\' || *p == '/')
131 {
132 strcpy(basename, p+1);
133 return basename;
134 }
135 }
136 strcpy(basename, fullpath);
137 return basename;
138 tony 1.15 }
139
140 // Return the just the path to the file name into dirname
141 char *System::extract_file_path(const char *fullpath, char *dirname)
142 {
143 char *p;
144 char buff[2048];
145 if (fullpath == NULL)
146 {
147 dirname[0] = '\0';
148 return dirname;
149 }
150 strcpy(buff, fullpath);
151 for(p = buff + strlen(buff); p >= buff; p--)
152 {
153 if (*p == '\\' || *p == '/')
154 {
155 strncpy(dirname, buff, p+1 - buff);
156 dirname[p+1 - buff] = '\0';
157 return dirname;
158 }
159 tony 1.15 }
160 strcpy(dirname, fullpath);
161 return dirname;
162 }
163
|
164 marek 1.24 String System::getHostIP(const String &hostName)
165 {
166 struct hostent * phostent;
167 struct in_addr inaddr;
168 String ipAddress = String::EMPTY;
169
170 if ((phostent = ::gethostbyname((const char *)hostName.getCString())) != NULL)
171 {
172 ::memcpy( &inaddr, phostent->h_addr,4);
173 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
174 char * gottenIPAdress = NULL;
175 gottenIPAdress = ::inet_ntoa( inaddr );
176 __etoa(gottenIPAdress);
177 if (gottenIPAdress != NULL)
178 {
179 ipAddress.assign(gottenIPAdress);
180 }
181 #else
182 ipAddress = ::inet_ntoa( inaddr );
183 #endif
184 }
185 marek 1.24 return ipAddress;
186 }
|
187 r.kieninger 1.21
188 // ------------------------------------------------------------------------
189 // Convert a hostname into a a single host unique integer representation
190 // ------------------------------------------------------------------------
191 Uint32 System::_acquireIP(const char* hostname)
192 {
193 Uint32 ip = 0xFFFFFFFF;
194 if (!hostname) return 0xFFFFFFFF;
195
196 #ifdef PEGASUS_OS_OS400
197 char ebcdicHost[PEGASUS_MAXHOSTNAMELEN];
198 if (strlen(hostname) < PEGASUS_MAXHOSTNAMELEN)
199 strcpy(ebcdicHost, hostname);
200 else
201 return 0xFFFFFFFF;
202 AtoE(ebcdicHost);
203 #endif
204
|
205 dave.sudlik 1.22 ////////////////////////////////////////////////////////////////////////////////
206 // This code used to check if the first character of "hostname" was alphabetic
207 // to indicate hostname instead of IP address. But RFC 1123, section 2.1, relaxed
208 // this requirement to alphabetic character *or* digit. So bug 1462 changed the
209 // flow here to call inet_addr first to check for a valid IP address in dotted
210 // decimal notation. If it's not a valid IP address, then try to validate
211 // it as a hostname.
212 // RFC 1123 states: The host SHOULD check the string syntactically for a
213 // dotted-decimal number before looking it up in the Domain Name System.
214 // Hence the call to inet_addr() first.
215 ////////////////////////////////////////////////////////////////////////////////
216
217 #ifdef PEGASUS_OS_OS400
218 Uint32 tmp_addr = inet_addr(ebcdicHost);
219 #elif defined(PEGASUS_OS_ZOS)
220 Uint32 tmp_addr = inet_addr_ebcdic((char *)hostname);
221 #else
222 Uint32 tmp_addr = inet_addr((char *) hostname);
223 #endif
224
|
225 r.kieninger 1.21 struct hostent *entry;
226
|
227 dave.sudlik 1.22 // Note: 0xFFFFFFFF is actually a valid IP address (255.255.255.255).
228 // A better solution would be to use inet_aton() or equivalent, as
229 // inet_addr() is now considered "obsolete".
230
231 if (tmp_addr == 0xFFFFFFFF) // if hostname is not an IP address
|
232 r.kieninger 1.21 {
233 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
234 #define HOSTENT_BUFF_SIZE 8192
235 char buf[HOSTENT_BUFF_SIZE];
236 int h_errorp;
237 struct hostent hp;
238
239 entry = gethostbyname_r((char *)hostname, &hp, buf,
240 HOSTENT_BUFF_SIZE, &h_errorp);
241 #elif defined(PEGASUS_OS_OS400)
242 entry = gethostbyname(ebcdicHost);
243 #elif defined(PEGASUS_OS_ZOS)
244 char hostName[ PEGASUS_MAXHOSTNAMELEN ];
245 if (String::equalNoCase("localhost",String(hostname)))
246 {
247 gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );
248 entry = gethostbyname(hostName);
249 } else
250 {
251 entry = gethostbyname((char *)hostname);
252 }
253 r.kieninger 1.21 #else
254 entry = gethostbyname((char *)hostname);
255 #endif
256 if (!entry)
257 {
258 return 0xFFFFFFFF;
259 }
260 unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
261
262 ip_part1 = entry->h_addr[0];
263 ip_part2 = entry->h_addr[1];
264 ip_part3 = entry->h_addr[2];
265 ip_part4 = entry->h_addr[3];
266 ip = ip_part1;
267 ip = (ip << 8) + ip_part2;
268 ip = (ip << 8) + ip_part3;
269 ip = (ip << 8) + ip_part4;
|
270 dave.sudlik 1.22 }
271 else // else hostname *is* a dotted-decimal IP address
|
272 r.kieninger 1.21 {
273 // resolve hostaddr to a real host entry
274 // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms
275 entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
276
277 if (entry == 0)
278 {
279 // error, couldn't resolve the ip
280 return 0xFFFFFFFF;
281 } else
282 {
283
284 unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
285
286 ip_part1 = entry->h_addr[0];
287 ip_part2 = entry->h_addr[1];
288 ip_part3 = entry->h_addr[2];
289 ip_part4 = entry->h_addr[3];
290 ip = ip_part1;
291 ip = (ip << 8) + ip_part2;
292 ip = (ip << 8) + ip_part3;
293 r.kieninger 1.21 ip = (ip << 8) + ip_part4;
294 }
295 }
296
297 return ip;
298 }
299
|
300 tony 1.17 // System ID constants for Logger::put and Logger::trace
301 const String System::CIMLISTENER = "cimlistener"; // Listener systme ID
302
|
303 mike 1.8 PEGASUS_NAMESPACE_END
|