1 // SALOME Utils : general SALOME's definitions and tools
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Utils_Identity.cxx
25 // Author : Pascale NOYRET, EDF
30 # include <arpa/inet.h>
31 # include <netinet/in.h>
32 # include <sys/types.h>
34 # include "utilities.h"
35 # include "Utils_Identity.hxx"
43 const char* duplicate( const char *const str ) ;
45 const struct utsname get_uname( void )
47 struct utsname hostid;
48 const int retour=uname(&hostid);
53 const char* get_adip( void )
55 struct utsname hostid;
56 const int retour=uname(&hostid);
59 const hostent* pour_adip=gethostbyname(hostid.nodename);
60 ASSERT(pour_adip!=NULL);
61 const in_addr ip_addr=*(struct in_addr*)(pour_adip->h_addr) ;
62 return duplicate(inet_ntoa(ip_addr));
64 const char* const get_pwname( void )
66 struct passwd *papa = getpwuid( getuid() ) ;
67 return papa->pw_name ;
70 Identity::Identity( const char *name ): _name(duplicate(name)),\
71 _hostid(get_uname()),\
74 _pwname(get_pwname()) ,\
75 _dir(getcwd(NULL,0)),\
78 _cstart(ctime(&_start))
84 Identity::~Identity(void)
86 delete [] (char*)_name ;
87 (char*&)_name = NULL ;
89 //delete [] (char*)_dir ;
90 //(char*&)_dir = NULL ;
93 delete [] (char*)_adip ;
94 (char*&)_adip = NULL ;
101 const char* const Identity::name (void) const
105 const pid_t &Identity::pid(void) const
109 const struct utsname &Identity::hostid(void) const
113 const uid_t &Identity::uid(void) const
117 const time_t &Identity::start(void) const
121 const char* const Identity::rep (void) const
125 const char* const Identity::pwname (void) const
129 const char* const Identity::adip (void) const
134 /*------------------*/
136 /*------------------*/
138 const char* Identity::host_char( void ) const
140 return _hostid.nodename;
143 const char* Identity::start_char(void) const
145 return ctime(&_start) ;
148 ostream & operator<< ( ostream& os , const Identity& monid )
150 ASSERT(monid._name!=NULL) ;
151 os << "Identity :" << endl ;
152 os << '\t' << "Component name : " << monid._name << endl ;
153 os << '\t' << "Numero de PID : " << monid._pid << endl;
154 os << '\t' << "Uid utilisateur : " << monid._uid << endl;
155 os << '\t' << "nom utilisateur : " << monid._pwname << endl;
156 os << '\t' << "Nom de machine : " << (monid._hostid).nodename << endl;
157 os << '\t' << "Adresse IP : " << monid._adip << endl;
158 os << '\t' << "Heure de lancement : " << monid._cstart ; //ctime(&monid._start) ;
159 os << '\t' << "Dans le repertoire : " << monid._dir << endl;