comparison mcabber/src/main.c @ 1497:35020a2ed115

Do not use srand()/rand() if better alternatives exist (mirabilos) arc4random(3) is a self-seeding PRNG available on a lot of OSes (all BSDs, Darwin / Mac OSX, Interix / Microsoft® Services for Unix, Windows® 2003SR1, Windows® Vista, Debian with the new libbsd package installed, ???) and much better than srand(3)/rand(3). Thanks to GNU autoconf, this can be made portable. http://www.mirbsd.org/man/arc4random.3 //mirabilos
author Mikael Berthe <mikael@lilotux.net>
date Mon, 30 Jun 2008 23:13:50 +0200
parents 6b98dc22946d
children 0803c0bd8b76
comparison
equal deleted inserted replaced
1496:b9f8c1fddb23 1497:35020a2ed115
138 cw_set_ssl_options(sslverify, cafile_xp, capath_xp, ciphers, servername); 138 cw_set_ssl_options(sslverify, cafile_xp, capath_xp, ciphers, servername);
139 // We can't free the ca*_xp variables now, because they're not duplicated 139 // We can't free the ca*_xp variables now, because they're not duplicated
140 // in cw_set_ssl_options(). 140 // in cw_set_ssl_options().
141 141
142 if (!resource) { 142 if (!resource) {
143 #if HAVE_ARC4RANDOM
144 dynresource = g_strdup_printf("%s.%08x", PACKAGE_NAME, arc4random());
145 #else
143 unsigned int tab[2]; 146 unsigned int tab[2];
144 srand(time(NULL)); 147 srand(time(NULL));
145 tab[0] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0))); 148 tab[0] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0)));
146 tab[1] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0))); 149 tab[1] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0)));
147 dynresource = g_strdup_printf("%s.%04x%04x", PACKAGE_NAME, 150 dynresource = g_strdup_printf("%s.%04x%04x", PACKAGE_NAME,
148 tab[0], tab[1]); 151 tab[0], tab[1]);
152 #endif
149 resource = dynresource; 153 resource = dynresource;
150 } 154 }
151 155
152 /* Connect to server */ 156 /* Connect to server */
153 scr_LogPrint(LPRINT_NORMAL|LPRINT_DEBUG, "Connecting to server: %s", 157 scr_LogPrint(LPRINT_NORMAL|LPRINT_DEBUG, "Connecting to server: %s",