--- rtp.c.old 2004-03-25 12:12:57.000000000 -0600 +++ rtp.c 2004-03-25 12:23:04.000000000 -0600 @@ -24,7 +24,7 @@ #include #include #include - +#include #include #include #include @@ -47,49 +47,7 @@ static int rtpstart = 0; static int rtpend = 0; - -// The value of each payload format mapping: -struct rtpPayloadType { - int isAstFormat; // whether the following code is an AST_FORMAT - int code; -}; - -#define MAX_RTP_PT 256 - -struct ast_rtp { - int s; - char resp; - struct ast_frame f; - unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET]; - unsigned int ssrc; - unsigned int lastts; - unsigned int lastrxts; - unsigned int lastividtimestamp; - unsigned int lastovidtimestamp; - int lasttxformat; - int lastrxformat; - int dtmfcount; - unsigned int dtmfduration; - int nat; - struct sockaddr_in us; - struct sockaddr_in them; - struct timeval rxcore; - struct timeval txcore; - struct timeval dtmfmute; - struct ast_smoother *smoother; - int *ioid; - unsigned short seqno; - struct sched_context *sched; - struct io_context *io; - void *data; - ast_rtp_callback callback; - struct rtpPayloadType current_RTP_PT[MAX_RTP_PT]; - // a cache for the result of rtp_lookup_code(): - int rtp_lookup_code_cache_isAstFormat; - int rtp_lookup_code_cache_code; - int rtp_lookup_code_cache_result; - struct ast_rtcp *rtcp; -}; +static struct in_addr bindaddr; struct ast_rtcp { int s; /* Socket */ @@ -733,6 +691,7 @@ if (!rtcp) return NULL; memset(rtcp, 0, sizeof(struct ast_rtcp)); + memcpy(&rtcp->us.sin_addr, &bindaddr, sizeof(bindaddr)); rtcp->s = socket(AF_INET, SOCK_DGRAM, 0); rtcp->us.sin_family = AF_INET; if (rtcp->s < 0) { @@ -757,6 +716,7 @@ memset(rtp, 0, sizeof(struct ast_rtp)); rtp->them.sin_family = AF_INET; rtp->us.sin_family = AF_INET; + memcpy(&rtp->us.sin_addr, &bindaddr, sizeof(bindaddr)); rtp->s = socket(AF_INET, SOCK_DGRAM, 0); rtp->ssrc = rand(); rtp->seqno = rand() & 0xffff; @@ -1412,8 +1372,10 @@ { struct ast_config *cfg; char *s; + struct hostent *hp; rtpstart = 5000; rtpend = 31000; + memset(&bindaddr, 0, sizeof(bindaddr)); cfg = ast_load("rtp.conf"); if (cfg) { if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) { @@ -1430,6 +1392,13 @@ if (rtpend > 65535) rtpend = 65535; } + if ((s = ast_variable_retrieve(cfg, "general", "bindaddr"))) { + if (!(hp = gethostbyname(s))) { + ast_log(LOG_WARNING, "Invalid address: %s\n", s); + } else { + memcpy(&bindaddr, hp->h_addr, sizeof(bindaddr)); + } + } ast_destroy(cfg); } if (rtpstart >= rtpend) { --- include/asterisk/rtp.h.old 2004-03-25 12:23:23.000000000 -0600 +++ include/asterisk/rtp.h 2004-03-25 12:32:24.000000000 -0600 @@ -35,6 +35,8 @@ /*! Maximum RTP-specific code */ #define AST_RTP_MAX AST_RTP_CISCO_DTMF +#define MAX_RTP_PT 256 + struct ast_rtp_protocol { struct ast_rtp *(*get_rtp_info)(struct ast_channel *chan); /* Get RTP struct, or NULL if unwilling to transfer */ struct ast_rtp *(*get_vrtp_info)(struct ast_channel *chan); /* Get RTP struct, or NULL if unwilling to transfer */ @@ -44,10 +46,50 @@ struct ast_rtp_protocol *next; }; -struct ast_rtp; - typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data); +// The value of each payload format mapping: +struct rtpPayloadType { + int isAstFormat; // whether the following code is an AST_FORMAT + int code; +}; + +struct ast_rtp { + int s; + char resp; + struct ast_frame f; + unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET]; + unsigned int ssrc; + unsigned int lastts; + unsigned int lastrxts; + unsigned int lastividtimestamp; + unsigned int lastovidtimestamp; + int lasttxformat; + int lastrxformat; + int dtmfcount; + unsigned int dtmfduration; + int nat; + struct sockaddr_in us; + struct sockaddr_in them; + struct timeval rxcore; + struct timeval txcore; + struct timeval dtmfmute; + struct ast_smoother *smoother; + int *ioid; + unsigned short seqno; + struct sched_context *sched; + struct io_context *io; + void *data; + ast_rtp_callback callback; + struct rtpPayloadType current_RTP_PT[MAX_RTP_PT]; + // a cache for the result of rtp_lookup_code(): + int rtp_lookup_code_cache_isAstFormat; + int rtp_lookup_code_cache_code; + int rtp_lookup_code_cache_result; + struct ast_rtcp *rtcp; +}; + + struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode); void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them); --- channels/chan_sip.c.old 2004-03-25 12:26:39.000000000 -0600 +++ channels/chan_sip.c 2004-03-25 12:27:47.000000000 -0600 @@ -2657,7 +2657,12 @@ dest.sin_addr = p->redirip.sin_addr; } else if (rtp) { ast_rtp_get_peer(rtp, &dest); - } else { + } else if (p->rtp->us.sin_addr.s_addr!=INADDR_ANY) { + //Let's use the bindaddr from rtp + dest.sin_addr = p->rtp->us.sin_addr; + dest.sin_port = sin.sin_port; + } + else { dest.sin_addr = p->ourip; dest.sin_port = sin.sin_port; }