[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: RFS: jabbin



On Fri, 25 Aug 2006 01:03:52 +0200, Francesco Pedrini <f_pedrini@tiscali.it> said:

> On Thursday 24 August 2006 09:45, Andrew Donnellan wrote:
>> I've found the relevant piece of code:
>> [...]
>> Does anyone know what the appropriate code for PowerPC would be?

> The attached patch should fix the compilation on *all* non linux-x86
> archs, without breaking the supported archs.

,----
| --- /tmp/jabbin-2.0beta2a/voip/stun.cpp	2006-08-10 12:09:57.000000000 +0200
| +++ jabbin-2.0beta2a/voip/stun.cpp	2006-08-25 00:58:44.000000000 +0200
| @@ -669,17 +669,13 @@
|        tick = hightick;
|        tick <<= 32;
|        tick |= lowtick;
| -#elif defined(__GNUC__) && ( defined(__i686__) || defined(__i386__) )
| -      asm("rdtsc" : "=A" (tick));
|  #elif defined (__SUNPRO_CC) || defined( __sparc__ )	
|        tick = gethrtime();
| -#elif defined(__MACH__) 
| +#elif defined( __MACH__ )|| defined( __GNUC__ ) 
|        int fd=open("/dev/random",O_RDONLY);
|        read(fd,&tick,sizeof(tick));
|        closesocket(fd);

Err, I don't think that __GNUC__ actually guarantees the presence of
/dev/random.  So this patch does not seem to be correct.

(Although /dev/random, if you have it, is probably a better source of
randomness than rdtsc, or gethrtime.)

| -#else
| -#     error Need some way to seed the random number generator 
| -#endif 
| +#endif

If it really does need a proper random seed, then you should not be
getting rid of the compilation error.  It may compile correctly, but it
will not work as intended.

|        int seed = int(tick);
|  #ifdef WIN32
|        srand(seed);
`----


-- 
Hubert Chan - email & Jabber: hubert@uhoreg.ca - http://www.uhoreg.ca/
PGP/GnuPG key: 1024D/124B61FA   (Key available at wwwkeys.pgp.net)
Fingerprint: 96C5 012F 5F74 A5F7 1FF7  5291 AF29 C719 124B 61FA



Reply to: