Changeset 111:56ac6d8b1149 in rrlib_util


Ignore:
Timestamp:
07.04.2014 19:13:01 (6 years ago)
Author:
Jens Wettach <wettach@…>
Branch:
default
Children:
113:d271a42971c8, 116:83fa55e9e8ac
Phase:
public
Message:

cleaned GetHostName()

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sFileIOUtils.cpp

    r102 r111  
    5656//---------------------------------------------------------------------- 
    5757#include <cassert> 
     58#include <cstring> 
     59#include <cerrno> 
    5860 
    5961//---------------------------------------------------------------------- 
     
    338340 
    339341 
    340  
    341342//---------------------------------------------------------------------- 
    342343// class sFileIOUtils::GetHostName() 
    343344//---------------------------------------------------------------------- 
    344 std::string sFileIOUtils::GetHostName(bool fqdn) 
    345 { 
    346   //RRLIB_LOG_PRINTF(USER, "sFileIOUtils::GetHostName() >>> started\n"); 
    347   std::string cmd = fqdn ? "hostname -f" : "hostname"; 
    348   FILE * pipe = popen(cmd.c_str(), "r"); 
    349   char buf[ 1024 ]; 
    350   if (fgets(buf, sizeof(buf), pipe) == 0) 
    351   { 
    352     RRLIB_LOG_PRINTF(ERROR, "sFileIOUtils::GetHostName(bool fqdn) >> Error querying host name!\n"); 
     345std::string sFileIOUtils::GetHostName() 
     346{ 
     347  char name[1024]; 
     348  int result = gethostname(name, 1024); 
     349  if (result) 
     350  { 
     351    RRLIB_LOG_PRINTF(ERROR, "got error: <%s>\n", strerror(errno)); 
    353352    exit(EXIT_FAILURE); 
    354353  } 
    355   pclose(pipe); 
    356   std::string name(buf); 
    357   sStringUtils::TrimWhitespace(name); 
    358   //boost::trim(name); 
    359   //RRLIB_LOG_PRINTF(USER, "sFileIOUtils::GetHostName() >>> finished with name <%s>\n", name.c_str()); 
     354  RRLIB_LOG_PRINTF(DEBUG, "got hostname: <%s>\n", name); 
     355 
    360356  return name; 
    361357} // GetHostName() 
  • sFileIOUtils.h

    r102 r111  
    266266  /*! 
    267267   * Retrieves network host name via "hostname" and returns result. 
    268    * \param fqdn whether FQDN  (Fully  Qualified Domain Name) or short name shall be retrieved 
    269    */ 
    270   static std::string GetHostName(bool fqdn = true); 
    271  
     268   */ 
     269  static std::string GetHostName(); 
    272270 
    273271  /*! 
Note: See TracChangeset for help on using the changeset viewer.