]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
hack to fix udp sockets
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 15 Nov 2006 03:17:28 +0000 (03:17 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 15 Nov 2006 03:17:28 +0000 (03:17 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3377 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_apr.h
src/include/switch_utils.h
src/switch_rtp.c
src/switch_utils.c

index d7bd63d8960e23b428bd4342e2ac5b8b7efc8836..7dde426e385a69589da41fab54abf3cd16f58301 100644 (file)
@@ -649,7 +649,7 @@ DoxyDefine(apr_status_t switch_socket_sendto(switcj_socket_t *sock,
  * @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 @@ DoxyDefine(apr_status_t switch_socket_recvfrom(switch_sockaddr_t *from,
                                                                        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 
index 27d86cd80fc782498c44e4ecdaa562e7dbbb6784..ebf0aa366be9b0a9efb18fcbe440ce8de81ac15a 100644 (file)
@@ -54,6 +54,11 @@ SWITCH_BEGIN_EXTERN_C
 #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);
 
 
 /*!
index 3923bc3085177f1ea5ac8b2561921f34afeff5f8..5bd28138fd22997c24cc40987594438c9cbfa84a 100644 (file)
@@ -272,14 +272,18 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len)
                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 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
                                        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);
index 998c1854c5300ae20ef795630358b95e919fa7d6..6fee6cc832095f9465fb38c6844937632dc3c728 100644 (file)
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <stdlib.h>
 
+
 SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
 {
        switch(priority) { /*lol*/
@@ -50,6 +51,40 @@ SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
 
 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)
 {
        if (event > -1 && event < (int32_t) sizeof(RFC2833_CHARS)) {