Changeset 1168

Show
Ignore:
Timestamp:
11/20/08 16:06:53 (2 months ago)
Author:
tex
Message:

commit missing files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Provider_Common_Library/tags/1.0.2

    • Property svn:ignore changed from
      autom4te.cache
      aclocal.m4
      config.h.in
      configure
      Makefile.in
      to
      autom4te.cache
      aclocal.m4
      config.h.in
      configure
      Makefile.in
      .project
  • Provider_Common_Library/tags/1.0.2/Common.cpp

    r1137 r1168  
    3131#include "Common.h" 
    3232#include "net_dev.h" 
     33#include <netdb.h> 
     34#include <sys/utsname.h> 
    3335 
    3436using namespace std; 
     
    254256// If '/bin/hostname -f' fails, it tries to execute '/bin/hostname' without options. 
    255257int CF_getSystemName(string& sysName, string& errorMessage) { 
    256       string value, errout; 
     258/*    string value, errout; 
    257259        if (CF_runCommand("/bin/hostname -f", sysName, errout, errorMessage)!=OK) { 
    258260                CF_assert( CF_runCommand("/bin/hostname", sysName, errout, errorMessage)); 
    259261        } 
    260262        sysName = CF_trimText(sysName); 
     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; 
    261282        return OK; 
    262283} 
     
    265286// Modified by Frederic Desmons (2007/07/10) 
    266287int CF_getOSName(string& OSName, string& errorMessage) { 
    267         CF_assert(CF_runCommandFL("/bin/uname -o", OSName, errorMessage)); 
     288        //CF_assert(CF_runCommandFL("/bin/uname -o", OSName, errorMessage)); 
     289        //return OK; 
     290 
     291        struct utsname uts; 
     292        if (uname(&uts) < 0) { 
     293                errorMessage = "failed to get os: " + (string) strerror(errno); 
     294                return FAILED; 
     295        } 
     296 
     297        OSName = uts.sysname; 
    268298        return OK; 
    269299} 
    270300 
    271301// Added by Ilsoo Byun (2007/05/09) 
     302//Deprecated 
    272303int CF_getEthernetPortNames(vector<string>& result, string& errorMessage) { 
    273304        string value, stderr; 
     
    306337        // Modified by Frederic Desmons (2007/11/12) 
    307338        // Get only the first line of the std output 
    308         string value; 
     339        /*string value; 
    309340        CF_assert( CF_runCommandFL("/sbin/ifconfig "+ethName+" | gawk '/HWaddr/{} /inet addr/{print $2}'", value, errorMessage) ); 
    310341        ip = CF_trimText(value); 
    311342        if ( CF_startsWithNoCase(ip, "addr:") ) 
    312343                ip = ip.substr(5); 
     344        return OK;*/ 
     345 
     346        // Modified by Ilsoo Byun(2008/10/02) 
     347        const char* result = cf_get_ip(ethName.c_str()); 
     348        if (result == NULL) { 
     349                errorMessage = "CF_getIP failed"; 
     350                return FAILED; 
     351        } 
     352        ip = string(result); 
     353        free((void *) result); 
    313354        return OK; 
    314355} 
     
    356397 
    357398        for (int i = 0; i < count; ++i) { 
     399                if (!CF_startsWith(devices[i].name, "eth")) continue; 
    358400                const char* _ip = cf_get_ip(devices[i].name); 
    359401                if (_ip == NULL || strcmp(_ip, "127.0.0.1") == 0) { 
     
    361403                        continue; 
    362404                } else { 
     405cout << devices[i].name << endl; 
    363406                        ip = _ip; 
    364407                        free((void *) _ip);