aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-07-08 11:46:15 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-07-08 11:46:15 +0000
commite6ec107095e052276e613f40ff60bb593146531f (patch)
tree21665bd9dea4199212e2bb584d97784842e9914f
parentcce8f951b1cc6ba649775083c117bd6911a74895 (diff)
Extend bindaddr to RTP connections on SIP (bug #1989 et al)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3393 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xchannels/chan_sip.c18
-rwxr-xr-xinclude/asterisk/rtp.h2
-rwxr-xr-xrtp.c10
3 files changed, 20 insertions, 10 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index c8b578dee..2eb483cd4 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 6f01e1e11..3d6b0a793 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 ad5d37966..9cfb118bd 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;