--- asterisk/rtp.c 2003-11-25 21:15:28.000000000 +0000 +++ mydev-asterisk/rtp.c 2004-02-09 12:52:36.000000000 +0000 @@ -24,6 +24,7 @@ #include #include #include +#include //For use of gethostbyname #include #include @@ -48,47 +49,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 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 to store IP for binding struct ast_rtcp { int s; /* Socket */ @@ -677,6 +638,7 @@ if (!rtcp) return NULL; memset(rtcp, 0, sizeof(struct ast_rtcp)); + memcpy(&rtcp->us.sin_addr, &bindaddr, sizeof(bindaddr)); //Bind to our IP address rtcp->s = socket(AF_INET, SOCK_DGRAM, 0); rtcp->us.sin_family = AF_INET; if (rtcp->s < 0) { @@ -701,6 +663,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)); //Bind to our IP address rtp->s = socket(AF_INET, SOCK_DGRAM, 0); rtp->ssrc = rand(); rtp->seqno = rand() & 0xffff; @@ -1316,8 +1279,10 @@ { struct ast_config *cfg; char *s; + struct hostent *hp; rtpstart = 5000; rtpend = 31000; + memset(&bindaddr, 0, sizeof(bindaddr)); // Initialize bindaddr struct cfg = ast_load("rtp.conf"); if (cfg) { if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) { @@ -1333,6 +1298,14 @@ rtpend = 1024; if (rtpend > 65535) rtpend = 65535; + }// load bindaddr from cfg + 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_log(LOG_WARNING, "Going to use address: %s\n", s); } ast_destroy(cfg); } --- asterisk/include/asterisk/rtp.h 2003-11-15 00:52:49.000000000 +0000 +++ mydev-asterisk/include/asterisk/rtp.h 2004-02-09 12:52:26.000000000 +0000 @@ -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,49 @@ 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 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); --- asterisk/channels/chan_sip.c 2004-02-09 06:09:45.000000000 +0000 +++ mydev-asterisk/channels/chan_sip.c 2004-02-09 16:38:14.000000000 +0000 @@ -2632,7 +2630,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; }