Changeset 1166
- Timestamp:
- 11/20/08 15:37:28 (2 months ago)
- Files:
-
- Provider_Common_Library/trunk/Common.cpp (modified) (7 diffs)
- Provider_Common_Library/trunk/Common.h (modified) (1 diff)
- Provider_Common_Library/trunk/EmbeddedInstance.h (modified) (1 diff)
- Provider_Common_Library/trunk/Makefile.am (modified) (2 diffs)
- Provider_Common_Library/trunk/net_dev.cpp (added)
- Provider_Common_Library/trunk/net_dev.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Provider_Common_Library/trunk/Common.cpp
r1122 r1166 30 30 31 31 #include "Common.h" 32 #include "net_dev.h" 33 #include <netdb.h> 34 #include <sys/utsname.h> 32 35 33 36 using namespace std; … … 253 256 // If '/bin/hostname -f' fails, it tries to execute '/bin/hostname' without options. 254 257 int CF_getSystemName(string& sysName, string& errorMessage) { 255 string value, errout;258 /* vi t/string value, errout; 256 259 if (CF_runCommand("/bin/hostname -f", sysName, errout, errorMessage)!=OK) { 257 260 CF_assert( CF_runCommand("/bin/hostname", sysName, errout, errorMessage)); 258 261 } 259 262 sysName = CF_trimText(sysName); 260 return OK; 263 return OK;*/ 264 /*string ip; 265 CF_getMachineIP(ip, errorMessage); 266 struct hostent* host = gethostbyname(ip.c_str()); 267 if (host == NULL) 268 return FAILED; 269 270 sysName = host->h_name; 271 free(host); 272 return OK;*/ 273 274 // Modified by Ilsoo Byun(2008/10/02) 275 struct utsname uts; 276 if (uname(&uts) < 0) { 277 errorMessage = "failed to get system name: " + (string) strerror(errno); 278 return FAILED; 279 } 280 281 sysName = uts.nodename; 282 return OK; 283 261 284 } 262 285 … … 264 287 // Modified by Frederic Desmons (2007/07/10) 265 288 int CF_getOSName(string& OSName, string& errorMessage) { 266 CF_assert(CF_runCommandFL("/bin/uname -o", OSName, errorMessage)); 289 //CF_assert(CF_runCommandFL("/bin/uname -o", OSName, errorMessage)); 290 //return OK; 291 292 struct utsname uts; 293 if (uname(&uts) < 0) { 294 errorMessage = "failed to get os: " + (string) strerror(errno); 295 return FAILED; 296 } 297 298 OSName = uts.sysname; 267 299 return OK; 268 300 } 269 301 270 302 // Added by Ilsoo Byun (2007/05/09) 303 //Deprecated 271 304 int CF_getEthernetPortNames(vector<string>& result, string& errorMessage) { 272 305 string value, stderr; … … 305 338 // Modified by Frederic Desmons (2007/11/12) 306 339 // Get only the first line of the std output 307 string value;340 /*string value; 308 341 CF_assert( CF_runCommandFL("/sbin/ifconfig "+ethName+" | gawk '/HWaddr/{} /inet addr/{print $2}'", value, errorMessage) ); 309 342 ip = CF_trimText(value); 310 343 if ( CF_startsWithNoCase(ip, "addr:") ) 311 344 ip = ip.substr(5); 345 return OK;*/ 346 347 // Modified by Ilsoo Byun(2008/10/02) 348 const char* result = cf_get_ip(ethName.c_str()); 349 if (result == NULL) { 350 errorMessage = "CF_getIP failed"; 351 return FAILED; 352 } 353 ip = string(result); 354 free((void *) result); 312 355 return OK; 313 356 } … … 316 359 int CF_getMachineIP(string& ip, string& errorMessage) { 317 360 318 string _ip;361 //string _ip; 319 362 // Modified by Frederic Desmons (2007/11/12) 320 363 // Ignore loopback and empty results as well (case there is more than one interface) 321 vector<string> result;364 /* vector<string> result; 322 365 CF_assert(CF_getEthernetPortNames(result, errorMessage)); 323 366 for (unsigned int i=0; i < result.size(); i++) { … … 327 370 return OK; 328 371 } 329 } 372 }*/ 330 373 // Means the system has no configured interface... unlikely 331 ip = "127.0.0.1";332 return OK;374 //ip = "127.0.0.1"; 375 //return OK; 333 376 /* 334 377 int rc = OK; … … 350 393 return rc; 351 394 */ 395 396 struct net_proc* devices; 397 int count = cf_get_net_devices(&devices); 398 399 for (int i = 0; i < count; ++i) { 400 if (!CF_startsWith(devices[i].name, "eth")) continue; 401 const char* _ip = cf_get_ip(devices[i].name); 402 if (_ip == NULL || strcmp(_ip, "127.0.0.1") == 0) { 403 free((void *) _ip); 404 continue; 405 } else { 406 cout << devices[i].name << endl; 407 ip = _ip; 408 free((void *) _ip); 409 return OK; 410 } 411 } 412 cf_release_net_devices(&devices, count); 413 414 ip = "127.0.0.1"; 415 return OK; 416 352 417 } 353 418 Provider_Common_Library/trunk/Common.h
r1119 r1166 142 142 143 143 //Get the list of ethernet port 144 //Deprecated 144 145 int CF_getEthernetPortNames(vector<string>& result, string& errorMessage); 145 146 146 147 //Get IP by the ethernet port name 148 //Deprecated 147 149 int CF_getIP(const string& ethName, string& ip, string& errorMessage); 148 150 Provider_Common_Library/trunk/EmbeddedInstance.h
r1089 r1166 17 17 18 18 #endif 19 Provider_Common_Library/trunk/Makefile.am
r967 r1166 36 36 commonlib_LTLIBRARIES = libOpenDRIMCommon.la 37 37 38 libOpenDRIMCommon_la_SOURCES = Association.cpp CMPIBroking.cpp Common.cpp Datastore.cpp Indication.cpp Instance.cpp Objectpath.cpp Transtype.cpp EmbeddedInstance.cpp 38 libOpenDRIMCommon_la_SOURCES = Association.cpp CMPIBroking.cpp Common.cpp Datastore.cpp Indication.cpp Instance.cpp Objectpath.cpp Transtype.cpp EmbeddedInstance.cpp net_dev.cpp 39 39 40 40 libOpenDRIMCommon_la_LDFLAGS = -lpthread -avoid-version -Wl,--rpath -Wl,$(COMMONLIBDIR) -lxml2 … … 46 46 install-providerdir: 47 47 $(INSTALL) -d $(OPENDRIMCOMMONINCLUDE)/cmpi /var/local/OpenDRIM 48 $(INSTALL) -m 644 Association.h CMPIBroking.h Common.h Datastore.h Indication.h Instance.h Objectpath.h Transtype.h EmbeddedInstance.h $(OPENDRIMCOMMONINCLUDE)48 $(INSTALL) -m 644 Association.h CMPIBroking.h Common.h Datastore.h Indication.h Instance.h Objectpath.h Transtype.h EmbeddedInstance.h net_dev.h $(OPENDRIMCOMMONINCLUDE) 49 49 $(INSTALL) -m 644 cmpi/* $(OPENDRIMCOMMONINCLUDE)/cmpi/ 50 50
