Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.907 diff -u -r1.907 chan_sip.c --- channels/chan_sip.c 8 Nov 2005 01:55:30 -0000 1.907 +++ channels/chan_sip.c 10 Nov 2005 23:51:25 -0000 @@ -117,6 +117,7 @@ static int max_expiry = DEFAULT_MAX_EXPIRY; static int default_expiry = DEFAULT_DEFAULT_EXPIRY; +static char random_state[256]; #ifndef MAX #define MAX(a,b) ((a) > (b) ? (a) : (b)) @@ -2721,7 +2722,7 @@ fmt = ast_best_codec(tmp->nativeformats); if (title) - snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%04x", title, rand() & 0xffff); + snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%04x", title, (unsigned int)random() & 0xffff); else if (strchr(i->fromdomain,':')) snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%08x", strchr(i->fromdomain,':')+1, (int)(long)(i)); else @@ -2974,7 +2975,7 @@ int x; char iabuf[INET_ADDRSTRLEN]; for (x=0; x<4; x++) { - val = rand(); + val = (unsigned int)random(); res = snprintf(callid, len, "%08x", val); len -= res; callid += res; @@ -2988,7 +2989,7 @@ static void make_our_tag(char *tagbuf, size_t len) { - snprintf(tagbuf, len, "as%08x", rand()); + snprintf(tagbuf, len, "as%08x", (unsigned int)random()); } /*! \brief sip_alloc: Allocate SIP_PVT structure and set defaults ---*/ @@ -3021,7 +3022,7 @@ memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); } - p->branch = rand(); + p->branch = (unsigned int)random(); make_our_tag(p->tag, sizeof(p->tag)); /* Start with 101 instead of 1 */ p->ocseq = 101; @@ -4009,7 +4010,7 @@ } if (newbranch) { - p->branch ^= rand(); + p->branch ^= (unsigned int)random(); build_via(p, p->via, sizeof(p->via)); } @@ -4826,7 +4827,7 @@ req.method = sipmethod; if (init) { /* Bump branch even on initial requests */ - p->branch ^= rand(); + p->branch ^= (unsigned int)random(); build_via(p, p->via, sizeof(p->via)); if (init > 1) initreqprep(&req, p, sipmethod); @@ -5402,7 +5403,7 @@ snprintf(addr, sizeof(addr), "sip:%s", r->hostname); ast_copy_string(p->uri, addr, sizeof(p->uri)); - p->branch ^= rand(); + p->branch ^= (unsigned int)random(); memset(&req, 0, sizeof(req)); init_req(&req, sipmethod, addr); @@ -5672,7 +5673,7 @@ /* SIP isn't up yet, so schedule a poke only, pretty soon */ if (peer->pokeexpire > -1) ast_sched_del(sched, peer->pokeexpire); - peer->pokeexpire = ast_sched_add(sched, rand() % 5000 + 1, sip_poke_peer_s, peer); + peer->pokeexpire = ast_sched_add(sched, (unsigned int)random() % 5000 + 1, sip_poke_peer_s, peer); } else sip_poke_peer(peer); if (peer->expire > -1) @@ -6133,7 +6134,7 @@ res = 1; } } else if (ast_strlen_zero(randdata) || ast_strlen_zero(authtoken)) { - snprintf(randdata, randlen, "%08x", rand()); + snprintf(randdata, randlen, "%08x", (unsigned int)random()); transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 0); /* Schedule auto destroy in 15 seconds */ sip_scheddestroy(p, 15000); @@ -6249,7 +6250,7 @@ if (wrongnonce) { - snprintf(randdata, randlen, "%08x", rand()); + snprintf(randdata, randlen, "%08x", (unsigned int)random()); if (ua_hash && !strncasecmp(ua_hash, resp_hash, strlen(resp_hash))) { if (sipdebug) ast_log(LOG_NOTICE, "stale nonce received from '%s'\n", get_header(req, "To")); @@ -8964,7 +8965,7 @@ else snprintf(uri, sizeof(uri), "sip:%s@%s",p->username, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr)); - snprintf(cnonce, sizeof(cnonce), "%08x", rand()); + snprintf(cnonce, sizeof(cnonce), "%08x", (unsigned int)random()); /* Check if we have separate auth credentials */ if ((auth = find_realm_authentication(authl, p->realm))) { @@ -13011,6 +13012,9 @@ ASTOBJ_CONTAINER_INIT(&peerl); /* Peer object list */ ASTOBJ_CONTAINER_INIT(®l); /* Registry object list */ + /* Initialize our random number generator */ + initstate((getppid() * 65535 + getpid()) % RAND_MAX, random_state, sizeof(random_state)); + sched = sched_context_create(); if (!sched) { ast_log(LOG_WARNING, "Unable to create schedule context\n");