2 //=============================================================================
3 // File : Utils_Identity.cxx
4 // Created : Mon Nov 5 17:02:37 CET 2001
5 // Author : Pascale NOYRET, EDF
7 // Copyright : EDF 2001
9 //=============================================================================
11 # include <iostream.h>
12 # include <arpa/inet.h>
13 # include <netinet/in.h>
14 # include <sys/types.h>
16 # include "utilities.h"
17 # include "Utils_Identity.hxx"
24 const char* duplicate( const char *const str ) ;
26 const struct utsname get_uname( void )
28 struct utsname hostid;
29 const int retour=uname(&hostid);
34 const char* get_adip( void )
36 struct utsname hostid;
37 const int retour=uname(&hostid);
40 const hostent* pour_adip=gethostbyname(hostid.nodename);
41 ASSERT(pour_adip!=NULL);
42 const in_addr ip_addr=*(struct in_addr*)(pour_adip->h_addr) ;
43 return duplicate(inet_ntoa(ip_addr));
45 const char* const get_pwname( void )
47 struct passwd *papa = getpwuid( getuid() ) ;
48 return papa->pw_name ;
51 Identity::Identity( const char *name ): _name(duplicate(name)),\
52 _hostid(get_uname()),\
55 _pwname(get_pwname()) ,\
56 _dir(getcwd(NULL,0)),\
59 _cstart(ctime(&_start))
65 Identity::~Identity(void)
67 delete [] (char*)_name ;
68 (char*&)_name = NULL ;
70 delete [] (char*)_dir ;
73 delete [] (char*)_adip ;
74 (char*&)_adip = NULL ;
81 const char* const Identity::name (void) const
85 const pid_t &Identity::pid(void) const
89 const struct utsname &Identity::hostid(void) const
93 const uid_t &Identity::uid(void) const
97 const time_t &Identity::start(void) const
101 const char* const Identity::rep (void) const
105 const char* const Identity::pwname (void) const
109 const char* const Identity::adip (void) const
114 /*------------------*/
116 /*------------------*/
118 const char* Identity::host_char( void ) const
120 return _hostid.nodename;
123 const char* Identity::start_char(void) const
125 return ctime(&_start) ;
128 ostream & operator<< ( ostream& os , const Identity& monid )
130 ASSERT(monid._name!=NULL) ;
131 os << "Identity :" << endl ;
132 os << '\t' << "Component name : " << monid._name << endl ;
133 os << '\t' << "Numero de PID : " << monid._pid << endl;
134 os << '\t' << "Uid utilisateur : " << monid._uid << endl;
135 os << '\t' << "nom utilisateur : " << monid._pwname << endl;
136 os << '\t' << "Nom de machine : " << (monid._hostid).nodename << endl;
137 os << '\t' << "Adresse IP : " << monid._adip << endl;
138 os << '\t' << "Heure de lancement : " << monid._cstart ; //ctime(&monid._start) ;
139 os << '\t' << "Dans le repertoire : " << monid._dir << endl;