[Freeswitch-dev] switch_stun_random_string returns identical strings on two calls randomly
Hi, I tried to replace the following function which I copied somewhere in msrp.c with switch_stun_random_string (http://docs.freeswitch.org/group__stun1.html#geb124530a232d65edc508afd1b9dd6...) but I found sometimes switch_stun_random_string (http://docs.freeswitch.org/group__stun1.html#geb124530a232d65edc508afd1b9dd6...) returns identical strings on two sequential calls, with the following function I never found, so I still use it. By looking the code I understand srand seed is time based so it's possible to return duplicate random string, but I found switch_stun_random_string (http://docs.freeswitch.org/group__stun1.html#geb124530a232d65edc508afd1b9dd6...) used in some places other than stun, just curious would it cause problems? void random_string(char *buf, switch_size_t size) { long val[4]; int x; for (x = 0; x < 4; x++) val[x] = random(); snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); *(buf+size) = '\0'; } Thanks. -- About: http://about.me/dujinfang Blog: http://www.dujinfang.com Proj: http://www.freeswitch.org.cn Sent with Sparrow (http://www.sparrowmailapp.com)
ya, you're right. Fixed in tree.... On Tue, Jan 31, 2012 at 3:51 AM, Seven Du <dujinfang@gmail.com> wrote:
Hi,
I tried to replace the following function which I copied somewhere in msrp.c with switch_stun_random_string but I found sometimes switch_stun_random_string returns identical strings on two sequential calls, with the following function I never found, so I still use it.
By looking the code I understand srand seed is time based so it's possible to return duplicate random string, but I found switch_stun_random_string used in some places other than stun, just curious would it cause problems?
void random_string(char *buf, switch_size_t size) { long val[4]; int x;
for (x = 0; x < 4; x++) val[x] = random(); snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); *(buf+size) = '\0'; }
Thanks.
-- About: http://about.me/dujinfang Blog: http://www.dujinfang.com Proj: http://www.freeswitch.org.cn
Sent with Sparrow
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-dev mailing list FreeSWITCH-dev@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ Twitter: http://twitter.com/FreeSWITCH_wire AIM: anthm MSN:anthony_minessale@hotmail.com GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org googletalk:conf+888@conference.freeswitch.org pstn:+19193869900
cool, I used it and no problem been found till now. On Wednesday, February 1, 2012 at 12:03 AM, Anthony Minessale wrote:
ya, you're right. Fixed in tree....
On Tue, Jan 31, 2012 at 3:51 AM, Seven Du <dujinfang@gmail.com (mailto:dujinfang@gmail.com)> wrote:
Hi,
I tried to replace the following function which I copied somewhere in msrp.c with switch_stun_random_string but I found sometimes switch_stun_random_string returns identical strings on two sequential calls, with the following function I never found, so I still use it.
By looking the code I understand srand seed is time based so it's possible to return duplicate random string, but I found switch_stun_random_string used in some places other than stun, just curious would it cause problems?
void random_string(char *buf, switch_size_t size) { long val[4]; int x;
for (x = 0; x < 4; x++) val[x] = random(); snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); *(buf+size) = '\0'; }
Thanks.
-- About: http://about.me/dujinfang Blog: http://www.dujinfang.com Proj: http://www.freeswitch.org.cn
Sent with Sparrow
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org (mailto:consulting@freeswitch.org) http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-dev mailing list FreeSWITCH-dev@lists.freeswitch.org (mailto:FreeSWITCH-dev@lists.freeswitch.org) http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II
FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ Twitter: http://twitter.com/FreeSWITCH_wire
AIM: anthm MSN:anthony_minessale@hotmail.com (mailto:anthony_minessale@hotmail.com) GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com (mailto:anthony.minessale@gmail.com) IRC: irc.freenode.net (http://irc.freenode.net) #freeswitch
FreeSWITCH Developer Conference sip:888@conference.freeswitch.org (mailto:888@conference.freeswitch.org) googletalk:conf+888@conference.freeswitch.org (mailto:conf+888@conference.freeswitch.org) pstn:+19193869900
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org (mailto:consulting@freeswitch.org) http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-dev mailing list FreeSWITCH-dev@lists.freeswitch.org (mailto:FreeSWITCH-dev@lists.freeswitch.org) http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
participants (2)
-
Anthony Minessale
-
Seven Du