From: Mark Spencer Date: Thu, 8 Jul 2004 11:46:15 +0000 (+0000) Subject: Extend bindaddr to RTP connections on SIP (bug #1989 et al) X-Git-Tag: 1.0.0-rc1~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ebfe337a7e4383e5a21212415bb6fc9db29b490;p=thirdparty%2Fasterisk.git Extend bindaddr to RTP connections on SIP (bug #1989 et al) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3393 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index c8b578dee5..2eb483cd45 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2222,9 +2222,16 @@ static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useg #ifdef OSP_SUPPORT p->osphandle = -1; #endif - p->rtp = ast_rtp_new(sched, io, 1, 0); + if (sin) { + memcpy(&p->sa, sin, sizeof(p->sa)); + if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) + memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); + } else { + memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); + } + p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, p->ourip); if (videosupport) - p->vrtp = ast_rtp_new(sched, io, 1, 0); + p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, p->ourip); p->branch = rand(); p->tag = rand(); @@ -2248,13 +2255,6 @@ static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useg ast_rtp_setnat(p->vrtp, (p->nat == SIP_NAT_ALWAYS)); } - if (sin) { - memcpy(&p->sa, sin, sizeof(p->sa)); - if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) - memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); - } else { - memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); - } /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ if (p->nat != SIP_NAT_NEVER) snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x;rport", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); diff --git a/include/asterisk/rtp.h b/include/asterisk/rtp.h index 6f01e1e11d..3d6b0a7932 100755 --- a/include/asterisk/rtp.h +++ b/include/asterisk/rtp.h @@ -50,6 +50,8 @@ typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void * struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode); +struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in); + void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them); void ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them); diff --git a/rtp.c b/rtp.c index ad5d379665..9cfb118bdb 100755 --- a/rtp.c +++ b/rtp.c @@ -786,7 +786,7 @@ static struct ast_rtcp *ast_rtcp_new(void) return rtcp; } -struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode) +struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr addr) { struct ast_rtp *rtp; int x; @@ -817,6 +817,7 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, for (;;) { /* Must be an even port number by RTP spec */ rtp->us.sin_port = htons(x); + rtp->us.sin_addr = addr; if (rtp->rtcp) rtp->rtcp->us.sin_port = htons(x + 1); if (!(first = bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) && @@ -861,6 +862,13 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, return rtp; } +struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode) +{ + struct in_addr ia; + memset(&ia, 0, sizeof(ia)); + return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); +} + int ast_rtp_settos(struct ast_rtp *rtp, int tos) { int res;