1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
33 #include <sys/ioctl.h>
34 #include <sys/socket.h>
38 #include <sys/sockio.h>
45 /*****************************************************************************/
46 /* Static Module Functions */
47 /*****************************************************************************/
49 static int osl_getHWAddr(const char *ifname
, char* hard_addr
);
50 static int osl_checkAddr(const char* addr
);
53 /*****************************************************************************/
54 /* osl_getEthernetAddress */
55 /*****************************************************************************/
57 sal_Bool SAL_CALL
osl_getEthernetAddress( sal_uInt8
* pAddr
)
67 /** algorithm doesn't work on solaris */
78 * All we need is ... a network file descriptor.
79 * Normally, this is a very socket.
82 so
= socket(AF_INET
, SOCK_DGRAM
, 0);
86 * The first thing we have to do, get the interface configuration.
87 * It is a list of attached/configured interfaces
90 ifc
.ifc_len
= sizeof(buff
);
92 if ( ioctl(so
, SIOCGIFCONF
, &ifc
) < 0 )
94 /* fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));*/
102 * For each of the interfaces in the interface list,
103 * try to get the hardware address
107 for ( i
= ifc
.ifc_len
/ sizeof(struct ifreq
) ; --i
>= 0 ; ifr
++ )
110 nRet
= osl_getHWAddr(ifr
->ifr_name
,hard_addr
);
113 memcpy( pAddr
, hard_addr
, 6 );
123 /*****************************************************************************/
125 /*****************************************************************************/
127 static int osl_getHWAddr(const char *ifname
, char* hard_addr
)
131 int so
= socket(AF_INET
, SOCK_DGRAM
, 0);
133 strcpy(ifr
.ifr_name
, ifname
);
136 * First, get the Interface-FLAGS
139 ret
=ioctl(so
, SIOCGIFFLAGS
, &ifr
) ;
143 /* fprintf(stderr, "SIOCGIFFLAGS: %s\n", strerror(errno)); */
150 * If it is the loopback device, do not consider it any further
153 if (ifr
.ifr_flags
& IFF_LOOPBACK
)
155 /* fprintf(stderr, "SIOCGIFFLAGS : is LOOPBACK : %s\n", strerror(errno));*/
162 * And now, the real thing: the get address
166 ret
=ioctl(so
, SIOCGIFHWADDR
, &ifr
);
168 ret
=ioctl(so
, SIOCGIFADDR
, &ifr
);
172 /* fprintf(stderr, "SIOCGIFADDR: %s\n", strerror(errno));*/
173 memset(hard_addr
, 0, 32);
181 memcpy(hard_addr
,ifr
.ifr_hwaddr
.sa_data
,8);
183 memcpy(hard_addr
,ifr
.ifr_ifru
.ifru_addr
.sa_data
,8);
188 * Check, if no real, i.e. 00:00:00:00:00:00, address was retrieved.
189 * The Linux dummy device has this kind of behaviour
192 ret
=osl_checkAddr(hard_addr
);
195 /* fprintf(stderr, "SIOCGIFADDR got '00:00:00:00:00:00'\n"); */
199 /* fprintf(stderr,"interface : %s -- ",ifname);*/
200 /* fprintf(stderr,"HWaddr : %s\n", print_ether(hard_addr));*/
206 /*****************************************************************************/
208 /*****************************************************************************/
210 static int osl_checkAddr(const char* addr
)
212 if (addr
[0]==0 && addr
[1]==0 &&
213 addr
[2]==0 && addr
[3]==0 &&
214 addr
[4]==0 && addr
[5]==0)
224 #if defined (SOLARIS) && !defined(__sparcv8plus) && !defined(__sparcv9)
225 #include <sys/types.h>
226 #include <sys/processor.h>
228 /*****************************************************************************/
229 /* osl_InitSparcV9 */
230 /*****************************************************************************/
232 void osl_InterlockedCountSetV9(sal_Bool bV9
);
235 * osl_InitSparcV9() should be executed as early as possible. We place it in the
236 * .init section of sal
238 #if defined ( __SUNPRO_C ) || defined ( __SUNPRO_CC )
239 void osl_InitSparcV9(void);
240 #pragma init (osl_InitSparcV9)
241 #elif defined ( __GNUC__ )
242 void osl_InitSparcV9(void) __attribute__((constructor
));
245 void osl_InitSparcV9(void)
247 /* processor_info() identifies SPARCV8 (ie sun4c machines) simply as "sparc"
248 * and SPARCV9 (ie ultra sparcs, sun4u) as "sparcv9". Since we know that we
249 * run at least on a SPARCV8 architecture or better, any processor type != "sparc"
250 * and != "i386" is considered to be SPARCV9 or better
252 * This way we are certain that this will still work if someone names SPARCV10
255 processor_info_t aInfo
;
258 rc
= processor_info(0, &aInfo
);
261 if ( !strcmp( "sparc", aInfo
.pi_processor_type
) /* SPARCV8 */
262 || !strcmp( "i386", aInfo
.pi_processor_type
) ) /* can't happen, but ... */
264 /* we are reasonably certain to be on sparcv9/sparcv8plus or better */
265 osl_InterlockedCountSetV9(sal_True
);
271 #if defined(NETBSD) && defined(GCC) && !defined(__sparcv9) && !defined(__sparc_v9__)
273 #include <sys/param.h>
274 #include <sys/sysctl.h>
275 void osl_InitSparcV9(void) __attribute__((constructor
));
276 void osl_InterlockedCountSetV9(sal_Bool bV9
);
278 /* Determine which processor we are running on (sparc v8 or v9)
279 * The approach is very similar to Solaris.
282 void osl_InitSparcV9(void)
284 int mib
[2]={CTL_HW
,HW_MACHINE
};
285 char processorname
[256];
288 /* get the machine name */
289 sysctl(mib
, 2, processorname
, &len
, NULL
, 0);
290 if (!strncmp("sparc64",processorname
, len
)) {
291 osl_InterlockedCountSetV9(sal_True
);
299 #if defined ( LINUX ) && defined ( SPARC )
300 #include <sys/utsname.h>
301 void osl_InitSparcV9(void) __attribute__((constructor
));
302 void osl_InterlockedCountSetV9(sal_Bool bV9
);
303 /* Determine which processor we are running on (sparc v8 or v9)
304 * The approach is very similar to Solaris.
306 void osl_InitSparcV9(void)
312 if ( !strcmp( "sparc", name
.machine
))
314 osl_InterlockedCountSetV9(sal_True
);
319 #if ( defined(__GNUC__) && (defined(X86) || defined(X86_64)) )\
320 || ( defined(SOLARIS) && defined (__SUNPRO_C) && defined(__i386) )
323 int osl_isSingleCPU
= 0;
325 /* Determine if we are on a multiprocessor/multicore/HT x86/x64 system
327 * The lock prefix for atomic operations in osl_[inc|de]crementInterlockedCount()
328 * comes with a cost and is especially expensive on pre HT x86 single processor
329 * systems, where it isn't needed at all.
331 * This should be run as early as possible, thus it's placed in the init section
333 #if defined(_SC_NPROCESSORS_CONF) /* i.e. MACOSX for Intel doesn't have this */
334 #if defined(__GNUC__)
335 void osl_interlockedCountCheckForSingleCPU(void) __attribute__((constructor
));
336 #elif defined(__SUNPRO_C)
337 void osl_interlockedCountCheckForSingleCPU(void);
338 #pragma init (osl_interlockedCountCheckForSingleCPU)
341 void osl_interlockedCountCheckForSingleCPU(void)
343 /* In case sysconfig fails be on the safe side,
344 * consider it a multiprocessor/multicore/HT system */
345 if ( sysconf(_SC_NPROCESSORS_CONF
) == 1 ) {
349 #endif /* defined(_SC_NPROCESSORS_CONF) */