Changeset 1166

Show
Ignore:
Timestamp:
11/20/08 15:37:28 (2 months ago)
Author:
isbyun
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Provider_Common_Library/trunk/Common.cpp

    r1122 r1166  
    3030 
    3131#include "Common.h" 
     32#include "net_dev.h" 
     33#include <netdb.h> 
     34#include <sys/utsname.h> 
    3235 
    3336using namespace std; 
     
    253256// If '/bin/hostname -f' fails, it tries to execute '/bin/hostname' without options. 
    254257int CF_getSystemName(string& sysName, string& errorMessage) { 
    255        string value, errout; 
     258/*     vi t/string value, errout; 
    256259        if (CF_runCommand("/bin/hostname -f", sysName, errout, errorMessage)!=OK) { 
    257260                CF_assert( CF_runCommand("/bin/hostname", sysName, errout, errorMessage)); 
    258261        } 
    259262        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 
    261284} 
    262285 
     
    264287// Modified by Frederic Desmons (2007/07/10) 
    265288int 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; 
    267299        return OK; 
    268300} 
    269301 
    270302// Added by Ilsoo Byun (2007/05/09) 
     303//Deprecated 
    271304int CF_getEthernetPortNames(vector<string>& result, string& errorMessage) { 
    272305        string value, stderr; 
     
    305338        // Modified by Frederic Desmons (2007/11/12) 
    306339        // Get only the first line of the std output 
    307         string value; 
     340        /*string value; 
    308341        CF_assert( CF_runCommandFL("/sbin/ifconfig "+ethName+" | gawk '/HWaddr/{} /inet addr/{print $2}'", value, errorMessage) ); 
    309342        ip = CF_trimText(value); 
    310343        if ( CF_startsWithNoCase(ip, "addr:") ) 
    311344                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); 
    312355        return OK; 
    313356} 
     
    316359int CF_getMachineIP(string& ip, string& errorMessage) { 
    317360 
    318         string _ip; 
     361        //string _ip; 
    319362        // Modified by Frederic Desmons (2007/11/12) 
    320363        // Ignore loopback and empty results as well (case there is more than one interface) 
    321       vector<string> result; 
     364/*    vector<string> result; 
    322365        CF_assert(CF_getEthernetPortNames(result, errorMessage)); 
    323366        for (unsigned int i=0; i < result.size(); i++) { 
     
    327370                        return OK; 
    328371                } 
    329         } 
     372        }*/ 
    330373        // 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; 
    333376        /* 
    334377        int rc = OK; 
     
    350393        return rc; 
    351394        */ 
     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 { 
     406cout << 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 
    352417} 
    353418 
  • Provider_Common_Library/trunk/Common.h

    r1119 r1166  
    142142 
    143143//Get the list of ethernet port 
     144//Deprecated 
    144145int CF_getEthernetPortNames(vector<string>& result, string& errorMessage); 
    145146 
    146147//Get IP by the ethernet port name 
     148//Deprecated 
    147149int CF_getIP(const string& ethName, string& ip, string& errorMessage); 
    148150 
  • Provider_Common_Library/trunk/EmbeddedInstance.h

    r1089 r1166  
    1717 
    1818#endif 
     19 
  • Provider_Common_Library/trunk/Makefile.am

    r967 r1166  
    3636commonlib_LTLIBRARIES = libOpenDRIMCommon.la 
    3737 
    38 libOpenDRIMCommon_la_SOURCES = Association.cpp CMPIBroking.cpp Common.cpp Datastore.cpp Indication.cpp Instance.cpp Objectpath.cpp Transtype.cpp EmbeddedInstance.cpp 
     38libOpenDRIMCommon_la_SOURCES = Association.cpp CMPIBroking.cpp Common.cpp Datastore.cpp Indication.cpp Instance.cpp Objectpath.cpp Transtype.cpp EmbeddedInstance.cpp net_dev.cpp 
    3939 
    4040libOpenDRIMCommon_la_LDFLAGS = -lpthread -avoid-version -Wl,--rpath -Wl,$(COMMONLIBDIR) -lxml2 
     
    4646install-providerdir: 
    4747        $(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) 
    4949        $(INSTALL) -m 644 cmpi/* $(OPENDRIMCOMMONINCLUDE)/cmpi/ 
    5050