summaryrefslogtreecommitdiff
path: root/src/Standard/Standard_Geteth.cxx
blob: 3de27d34232f7e96547e8e0ca10d9e5b0405f78e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

/*
  Cree par JPT pour la protection SOK sur base CSF1.
  A ce jour on reconnait comme machine:
	- SUN/SOLARIS
	- ALPHA/OSF
	- SGI/IRIX
  Pour SUN et SGI on recupere le numero unique du host (hostid).
  Pour ALPHA on recupere l'adresse ethernet de la machine (ce qui est
  tout de meme beaucoup plus sur).

*/
#ifdef HAVE_CONFIG_H
# include <oce-config.h>
#endif

#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif

#ifdef HAVE_SYS_SYSTEMINFO_H
# include <sys/systeminfo.h>
#endif

#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif

#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif

#include <Standard_Stream.hxx>

#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h>
#endif

#include <errno.h>
#include <stdio.h>



#if defined(__sun) || defined(SOLARIS)
extern "C" { int sysinfo (int command , char *name, long namelen);}
             int atoi (char *);
#elif defined(__sgi)  || defined(IRIX)
extern "C" {int sysid (unsigned char *);}
extern "C" {int atoi (const char *str);}
#elif defined(__osf__) || defined(DECOSF1)
// generic interface stuctures
#include <string.h>
char  *ether_devices[] = {
       "qe0",
       "se0",
       "ln0",
       "de0",
       "ni0",
       "tu0",
        NULL
       };
#endif

// --------------------------------------------------------------------------
void Geteth(int tab[])
// --------------------------------------------------------------------------
{
#if defined(__sun) || defined(SOLARIS)
  /* Returns a SOLARIS host identification in 2 words */
  unsigned int i;
  char provider[16];
  char serial[16];
  
  i = (unsigned int ) sysinfo(SI_HW_PROVIDER,provider,16);
  
  i = (unsigned int ) sysinfo(SI_HW_SERIAL,serial,16);
  
  
  /*printf("\nProvider : %s Serial : %s\n",provider,serial);*/
  
  sscanf(serial,"%d",&i);
  
  tab[0] = 0;
  tab[1] = 0;
  
  tab[1] = tab[1] | (i >> 24);
  tab[1] = tab[1] | ( (i >> 8 ) & 0x0000ff00);
  tab[1] = tab[1] | ( (i << 8 ) & 0x00ff0000);
  tab[1] = tab[1] | ( (i << 24) & 0xff000000);
  
  tab[1] = -tab[1];
  

// unsigned int   stat;
//  char  name[100];
//  long  len = 100;
//  stat = sysinfo (SI_HW_SERIAL,name,len);
//  if (stat != -1){   // It is correct.....
//    int  i = atoi (name);
//    tab[0] = 0;
//    tab[1] = 0;
//    tab[1] = tab[1] | (i >> 24);
//    tab[1] = tab[1] | ( (i >> 8)  & 0x0000ff00);
//    tab[1] = tab[1] | ( (i << 8)  & 0x00ff0000);
//    tab[1] = tab[1] | ( (i << 24) & 0xff000000);
//    tab[1] = -tab[1];
//  }
//  else {             // It is nor normal : exit !
//    printf("SOK_Utility-Internal_Error_1:Unable to get hardware-specific serial number, errno = %d.\n",errno);
//    exit(0);
//  }

#elif defined(__sgi) || defined(IRIX)

/* Creee par JPT le 29-Oct-1992

   Renvoie l'identification d'un hostname SGI  dans 2 mots.

   Sur SGI l'appel a sysid renvois 16 caracteres qui identifie de
   fa on unique une machine.

   Sur SGI/xxxx avec xxxx autre que CRIMSON seuls les 8 premiers
   caracteres sont significatifs. Les 8 autres sont nuls.
   
   Pour  tre homogene avec les autres plateformes on prend les 16
   caracteres et on rend 12 chiffres hexadecimaux.


*/

unsigned int i                   		;
unsigned int tt  [4]                            ;
         char str[16]                           ;

sysid ( (unsigned char* )str )	              	;
tt[0] = tt[1] = tt[2] = tt[3] = 0               ;
tt[0]  = atoi (str)                             ;
tab[0] = 0			                ;
tab[1] = 0			                ;
i      = tt[2] ^ tt[3]		            	;
i      = i ^ tt [0]                        	;
tab[1] = tab[1] | (i >> 24)			;
tab[1] = tab[1] | ( (i >> 8 ) & 0x0000ff00)	;
tab[1] = tab[1] | ( (i << 8 ) & 0x00ff0000)	;
tab[1] = tab[1] | ( (i << 24) & 0xff000000)	;
tab[1] = -tab[1]                                ;

i      = tt[1] >> 16				;
i      = i ^ ( tt[1] & 0x0000ffff )		;
tab[0] = i					;
tab[0] = -tab[0]				;


#elif defined(__osf__) || defined(DECOSF1)

   struct ifdevea devea;

   int ss, i;

   char id[8];
   int *pid;

   ss = socket (AF_INET, SOCK_DGRAM, 0);
   if (ss < 0)
     return;
   else {
      for (i = 0; ether_devices[i] != NULL; i++) {
          strcpy (&devea.ifr_name[0], ether_devices[i]);
          if (ioctl (ss, SIOCRPHYSADDR, &devea) < 0) {
             if (errno == ENXIO)  // doesn't exist, try next device
               continue;
             else
               return;
	   }
          else
            break;                // found one, break out
	}
    }

   close (ss);

   if (ether_devices[i] == NULL)
      return;

   id[3]  = 0                  ;
   id[2]  = 0                  ;
   id[4]  = devea.default_pa[0];
   id[5]  = devea.default_pa[1];
   
   id[6]  = devea.default_pa[2];
   id[7]  = devea.default_pa[3];
   id[0]  = devea.default_pa[4];
   id[1]  = devea.default_pa[5];


   pid    = (int *)&id         ;
   tab[0] = pid[0]             ;
   tab[1] = pid[1]             ;
   tab[0] = - tab[0]           ;
   tab[1] = - tab[1]           ;


#elif defined(__hpux) || defined(HPUX)
long i;
struct utsname un;

tab[0] = 0;
tab[1] = 0;
if (uname(&un) != -1)
  {sscanf(un.idnumber,"%d",&i);
   tab[1] = int( tab[1] | (i >> 24) ) ;
   tab[1] = int( tab[1] | ( (i >> 8 ) & 0x0000ff00) ) ;
   tab[1] = int( tab[1] | ( (i << 8 ) & 0x00ff0000) ) ;
   tab[1] = int( tab[1] | ( (i << 24) & 0xff000000) ) ;

   tab[1] = -tab[1];};

//return ((long) tab);

#endif

}