Author: anthm Date: Tue Nov 14 22:17:28 2006 New Revision: 3377 Modified: freeswitch/trunk/src/include/switch_apr.h freeswitch/trunk/src/include/switch_utils.h freeswitch/trunk/src/switch_rtp.c freeswitch/trunk/src/switch_utils.c Log: hack to fix udp sockets Modified: freeswitch/trunk/src/include/switch_apr.h ============================================================================== --- freeswitch/trunk/src/include/switch_apr.h (original) +++ freeswitch/trunk/src/include/switch_apr.h Tue Nov 14 22:17:28 2006 @@ -649,7 +649,7 @@ * @param flags The flags to use * @param buf The buffer to use * @param len The length of the available buffer - */ + * DoxyDefine(apr_status_t switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, @@ -657,6 +657,7 @@ char *buf, apr_size_t *len);) #define switch_socket_recvfrom apr_socket_recvfrom +*/ /** * Send a file from an open file descriptor to a socket, along with Modified: freeswitch/trunk/src/include/switch_utils.h ============================================================================== --- freeswitch/trunk/src/include/switch_utils.h (original) +++ freeswitch/trunk/src/include/switch_utils.h Tue Nov 14 22:17:28 2006 @@ -54,6 +54,11 @@ #define SWITCH_SMIN -32768 #define switch_normalize_to_16bit(n) if (n > SWITCH_SMAX) n = SWITCH_SMAX / 2; else if (n < SWITCH_SMIN) n = SWITCH_SMIN / 2; +SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in); + +SWITCH_DECLARE(apr_status_t) switch_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock, + apr_int32_t flags, char *buf, + apr_size_t *len); /*! Modified: freeswitch/trunk/src/switch_rtp.c ============================================================================== --- freeswitch/trunk/src/switch_rtp.c (original) +++ freeswitch/trunk/src/switch_rtp.c Tue Nov 14 22:17:28 2006 @@ -272,14 +272,18 @@ switch_stun_packet_t *rpacket; char *remote_ip; switch_size_t bytes; - + char ipbuf[25]; + memset(buf, 0, sizeof(buf)); rpacket = switch_stun_packet_build_header(SWITCH_STUN_BINDING_RESPONSE, packet->header.id, buf); switch_stun_packet_attribute_add_username(rpacket, username, 32); - switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr); + //switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr); + + remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr); + + switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, rtp_session->from_addr->port); bytes = switch_stun_packet_length(rpacket); - switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void*)rpacket, &bytes); } } @@ -866,9 +870,14 @@ char *tx_host; uint32_t old = rtp_session->remote_port; char *old_host; - - switch_sockaddr_ip_get(&tx_host, rtp_session->from_addr); - switch_sockaddr_ip_get(&old_host, rtp_session->remote_addr); + char bufa[30], bufb[30]; + + //switch_sockaddr_ip_get(&tx_host, rtp_session->from_addr); + //switch_sockaddr_ip_get(&old_host, rtp_session->remote_addr); + + tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr); + old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr); + if (!switch_strlen_zero(tx_host) && rtp_session->from_addr->port > 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host, rtp_session->from_addr->port); Modified: freeswitch/trunk/src/switch_utils.c ============================================================================== --- freeswitch/trunk/src/switch_utils.c (original) +++ freeswitch/trunk/src/switch_utils.c Tue Nov 14 22:17:28 2006 @@ -34,6 +34,7 @@ #include <string.h> #include <stdlib.h> + SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority) { switch(priority) { /*lol*/ @@ -49,6 +50,40 @@ } static char RFC2833_CHARS[] = "0123456789*#ABCDF"; + + + +SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in) +{ + uint8_t x, *i; + char *p = buf; + + + i = (uint8_t *) &in->sa.sin.sin_addr; + + memset(buf, 0, len); + for(x =0; x < 4; x++) { + sprintf(p, "%u%s", i[x], x == 3 ? "" : "."); + p = buf + strlen(buf); + } + return buf; +} + +SWITCH_DECLARE(apr_status_t) switch_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock, + apr_int32_t flags, char *buf, + apr_size_t *len) +{ + apr_status_t r; + + if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) { + from->port = ntohs(from->sa.sin.sin_port); + //from->ipaddr_ptr = &(from->sa.sin.sin_addr); + //from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr); + } + + return r; + +} SWITCH_DECLARE(char) switch_rfc2833_to_char(int event) {
participants (1)
-
Freeswitch SVN