0022945: AIS_InteractiveObject: Initialization bug
[occt.git] / src / Standard / Standard_Geteth.cxx
CommitLineData
7fd59977 1
2/*
3 Cree par JPT pour la protection SOK sur base CSF1.
4 A ce jour on reconnait comme machine:
5 - SUN/SOLARIS
6 - ALPHA/OSF
7 - SGI/IRIX
8 Pour SUN et SGI on recupere le numero unique du host (hostid).
9 Pour ALPHA on recupere l'adresse ethernet de la machine (ce qui est
10 tout de meme beaucoup plus sur).
11
12*/
13#ifdef HAVE_CONFIG_H
14# include <config.h>
15#endif
16
17#ifdef HAVE_UNISTD_H
18# include <unistd.h>
19#endif
20
21#ifdef HAVE_SYS_SOCKET_H
22# include <sys/socket.h>
23#endif
24
25#ifdef HAVE_SYS_SYSTEMINFO_H
26# include <sys/systeminfo.h>
27#endif
28
29#ifdef HAVE_SYS_IOCTL_H
30# include <sys/ioctl.h>
31#endif
32
33#ifdef HAVE_NET_IF_H
34# include <net/if.h>
35#endif
36
37#include <Standard_Stream.hxx>
38
39#ifdef HAVE_SYS_UTSNAME_H
40# include <sys/utsname.h>
41#endif
42
43#include <errno.h>
44#include <stdio.h>
45
46
47
48#if defined(__sun) || defined(SOLARIS)
49extern "C" { int sysinfo (int command , char *name, long namelen);}
50 int atoi (char *);
51#elif defined(__sgi) || defined(IRIX)
52extern "C" {int sysid (unsigned char *);}
53extern "C" {int atoi (const char *str);}
54#elif defined(__osf__) || defined(DECOSF1)
55// generic interface stuctures
56#include <string.h>
57char *ether_devices[] = {
58 "qe0",
59 "se0",
60 "ln0",
61 "de0",
62 "ni0",
63 "tu0",
64 NULL
65 };
66#endif
67
68// --------------------------------------------------------------------------
69void Geteth(int tab[])
70// --------------------------------------------------------------------------
71{
72#if defined(__sun) || defined(SOLARIS)
73 /* Returns a SOLARIS host identification in 2 words */
74 unsigned int i;
75 char provider[16];
76 char serial[16];
77
78 i = (unsigned int ) sysinfo(SI_HW_PROVIDER,provider,16);
79
80 i = (unsigned int ) sysinfo(SI_HW_SERIAL,serial,16);
81
82
83 /*printf("\nProvider : %s Serial : %s\n",provider,serial);*/
84
85 sscanf(serial,"%d",&i);
86
87 tab[0] = 0;
88 tab[1] = 0;
89
90 tab[1] = tab[1] | (i >> 24);
91 tab[1] = tab[1] | ( (i >> 8 ) & 0x0000ff00);
92 tab[1] = tab[1] | ( (i << 8 ) & 0x00ff0000);
93 tab[1] = tab[1] | ( (i << 24) & 0xff000000);
94
95 tab[1] = -tab[1];
96
97
98// unsigned int stat;
99// char name[100];
100// long len = 100;
101// stat = sysinfo (SI_HW_SERIAL,name,len);
102// if (stat != -1){ // It is correct.....
103// int i = atoi (name);
104// tab[0] = 0;
105// tab[1] = 0;
106// tab[1] = tab[1] | (i >> 24);
107// tab[1] = tab[1] | ( (i >> 8) & 0x0000ff00);
108// tab[1] = tab[1] | ( (i << 8) & 0x00ff0000);
109// tab[1] = tab[1] | ( (i << 24) & 0xff000000);
110// tab[1] = -tab[1];
111// }
112// else { // It is nor normal : exit !
113// printf("SOK_Utility-Internal_Error_1:Unable to get hardware-specific serial number, errno = %d.\n",errno);
114// exit(0);
115// }
116
117#elif defined(__sgi) || defined(IRIX)
118
119/* Creee par JPT le 29-Oct-1992
120
121 Renvoie l'identification d'un hostname SGI dans 2 mots.
122
123 Sur SGI l'appel a sysid renvois 16 caracteres qui identifie de
124 fa on unique une machine.
125
126 Sur SGI/xxxx avec xxxx autre que CRIMSON seuls les 8 premiers
127 caracteres sont significatifs. Les 8 autres sont nuls.
128
129 Pour tre homogene avec les autres plateformes on prend les 16
130 caracteres et on rend 12 chiffres hexadecimaux.
131
132
133*/
134
135unsigned int i ;
136unsigned int tt [4] ;
137 char str[16] ;
138
139sysid ( (unsigned char* )str ) ;
140tt[0] = tt[1] = tt[2] = tt[3] = 0 ;
141tt[0] = atoi (str) ;
142tab[0] = 0 ;
143tab[1] = 0 ;
144i = tt[2] ^ tt[3] ;
145i = i ^ tt [0] ;
146tab[1] = tab[1] | (i >> 24) ;
147tab[1] = tab[1] | ( (i >> 8 ) & 0x0000ff00) ;
148tab[1] = tab[1] | ( (i << 8 ) & 0x00ff0000) ;
149tab[1] = tab[1] | ( (i << 24) & 0xff000000) ;
150tab[1] = -tab[1] ;
151
152i = tt[1] >> 16 ;
153i = i ^ ( tt[1] & 0x0000ffff ) ;
154tab[0] = i ;
155tab[0] = -tab[0] ;
156
157
158#elif defined(__osf__) || defined(DECOSF1)
159
160 struct ifdevea devea;
161
162 int ss, i;
163
164 char id[8];
165 int *pid;
166
167 ss = socket (AF_INET, SOCK_DGRAM, 0);
168 if (ss < 0)
169 return;
170 else {
171 for (i = 0; ether_devices[i] != NULL; i++) {
172 strcpy (&devea.ifr_name[0], ether_devices[i]);
173 if (ioctl (ss, SIOCRPHYSADDR, &devea) < 0) {
174 if (errno == ENXIO) // doesn't exist, try next device
175 continue;
176 else
177 return;
178 }
179 else
180 break; // found one, break out
181 }
182 }
183
184 close (ss);
185
186 if (ether_devices[i] == NULL)
187 return;
188
189 id[3] = 0 ;
190 id[2] = 0 ;
191 id[4] = devea.default_pa[0];
192 id[5] = devea.default_pa[1];
193
194 id[6] = devea.default_pa[2];
195 id[7] = devea.default_pa[3];
196 id[0] = devea.default_pa[4];
197 id[1] = devea.default_pa[5];
198
199
200 pid = (int *)&id ;
201 tab[0] = pid[0] ;
202 tab[1] = pid[1] ;
203 tab[0] = - tab[0] ;
204 tab[1] = - tab[1] ;
205
206
207#elif defined(__hpux) || defined(HPUX)
208long i;
209struct utsname un;
210
211tab[0] = 0;
212tab[1] = 0;
213if (uname(&un) != -1)
214 {sscanf(un.idnumber,"%d",&i);
215 tab[1] = int( tab[1] | (i >> 24) ) ;
216 tab[1] = int( tab[1] | ( (i >> 8 ) & 0x0000ff00) ) ;
217 tab[1] = int( tab[1] | ( (i << 8 ) & 0x00ff0000) ) ;
218 tab[1] = int( tab[1] | ( (i << 24) & 0xff000000) ) ;
219
220 tab[1] = -tab[1];};
221
222//return ((long) tab);
223
224#endif
225
226}
227
228
229
230
231
232
233
234
235