--- channels/chan_sip.c.orig 2008-05-27 07:45:10.000000000 -0500 +++ channels/chan_sip.c 2008-05-30 02:31:07.000000000 -0500 @@ -1832,7 +1832,7 @@ static int sip_queryoption(struct ast_ch static const char *sip_get_callid(struct ast_channel *chan); static int handle_request_do(struct sip_request *req, struct sockaddr_in *sin); -static int sip_standard_port(struct sip_socket s); +static int sip_standard_port(enum sip_transport type, int port); static int sip_prepare_socket(struct sip_pvt *p); /*--- Transmitting responses and requests */ @@ -8825,14 +8825,15 @@ static void extract_uri(struct sip_pvt * /*! \brief Build contact header - the contact header we send out */ static void build_contact(struct sip_pvt *p) { - /* Construct Contact: header */ + int ourport = ntohs(p->ourip.sin_port); + if (p->socket.type & SIP_TRANSPORT_UDP) { - if (!sip_standard_port(p->socket)) - ast_string_field_build(p, our_contact, "", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), ntohs(p->socket.port)); + if (!sip_standard_port(p->socket.type, ourport)) + ast_string_field_build(p, our_contact, "", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), ourport); else ast_string_field_build(p, our_contact, "", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr)); } else - ast_string_field_build(p, our_contact, "", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), ntohs(p->socket.port), get_transport(p->socket.type)); + ast_string_field_build(p, our_contact, "", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), ourport, get_transport(p->socket.type)); } /*! \brief Build the Remote Party-ID & From using callingpres options */ @@ -8925,6 +8926,7 @@ static void initreqprep(struct sip_reque const char *l = NULL; /* XXX what is this, exactly ? */ const char *n = NULL; /* XXX what is this, exactly ? */ const char *urioptions = ""; + int ourport; if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) { const char *s = p->username; /* being a string field, cannot be NULL */ @@ -8981,8 +8983,9 @@ static void initreqprep(struct sip_reque l = tmp_l; } - if (!sip_standard_port(p->socket) && ast_strlen_zero(p->fromdomain)) - snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, S_OR(p->fromdomain, ast_inet_ntoa(p->ourip.sin_addr)), ntohs(p->socket.port), p->tag); + ourport = ntohs(p->ourip.sin_port); + if (!sip_standard_port(p->socket.type, ourport) && ast_strlen_zero(p->fromdomain)) + snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, ast_inet_ntoa(p->ourip.sin_addr), ourport, p->tag); else snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, S_OR(p->fromdomain, ast_inet_ntoa(p->ourip.sin_addr)), p->tag); @@ -19306,12 +19309,12 @@ static int handle_request_do(struct sip_ } /*! \brief Returns the port to use for this socket */ -static int sip_standard_port(struct sip_socket s) +static int sip_standard_port(enum sip_transport type, int port) { - if (s.type & SIP_TRANSPORT_TLS) - return s.port == htons(STANDARD_TLS_PORT); + if (type & SIP_TRANSPORT_TLS) + return port == STANDARD_TLS_PORT; else - return s.port == htons(STANDARD_SIP_PORT); + return port == STANDARD_SIP_PORT; } /*! \todo document this function. */