Changeset 1596


Ignore:
Timestamp:
Nov 23, 2007 3:54:49 AM (16 years ago)
Author:
bennylp
Message:

Fixed ticket #425: pjstun_get_mapped_addr() failed when receiving incoming SIP request (thanks Lafras Henning)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/stun_simple_client.c

    r1410 r1596  
    1919#include <pjlib-util/stun_simple.h> 
    2020#include <pjlib-util/errno.h> 
     21#include <pj/log.h> 
    2122#include <pj/os.h> 
    2223#include <pj/pool.h> 
     
    2627 
    2728 
    28 enum { MAX_REQUEST = 3 }; 
    29 static int stun_timer[] = {1600, 1600, 1600 }; 
     29enum { MAX_REQUEST = 4 }; 
     30static int stun_timer[] = {1000, 1000, 1000, 1000 }; 
    3031 
    3132#define THIS_FILE       "stun_client.c" 
     
    131132 
    132133        for (pj_gettimeofday(&now), select_rc=1;  
    133              status==PJ_SUCCESS && select_rc==1 && wait_resp>0  
     134             status==PJ_SUCCESS && select_rc>=1 && wait_resp>0  
    134135               && PJ_TIME_VAL_LT(now, next_tx);  
    135136             pj_gettimeofday(&now))  
     
    166167                                           &addrlen); 
    167168 
    168                 --wait_resp; 
    169  
    170                 if (status != PJ_SUCCESS) 
    171                     continue; 
     169                if (status != PJ_SUCCESS) { 
     170                    char errmsg[PJ_ERR_MSG_SIZE]; 
     171 
     172                    PJ_LOG(4,(THIS_FILE, "recvfrom() error ignored: %s", 
     173                              pj_strerror(status, errmsg,sizeof(errmsg)).ptr)); 
     174 
     175                    /* Ignore non-PJ_SUCCESS status. 
     176                     * It possible that other SIP entity is currently  
     177                     * sending SIP request to us, and because SIP message 
     178                     * is larger than STUN, we could get EMSGSIZE when 
     179                     * we call recvfrom(). 
     180                     */ 
     181                    status = PJ_SUCCESS; 
     182                    continue; 
     183                } 
    172184 
    173185                status = pjstun_parse_msg(recv_buf, len, &msg); 
    174186                if (status != PJ_SUCCESS) { 
    175                     continue; 
    176                 } 
    177  
     187                    char errmsg[PJ_ERR_MSG_SIZE]; 
     188 
     189                    PJ_LOG(4,(THIS_FILE, "STUN parsing error ignored: %s", 
     190                              pj_strerror(status, errmsg,sizeof(errmsg)).ptr)); 
     191 
     192                    /* Also ignore non-successful parsing. This may not 
     193                     * be STUN response at all. See the comment above. 
     194                     */ 
     195                    status = PJ_SUCCESS; 
     196                    continue; 
     197                } 
    178198 
    179199                sock_idx = pj_ntohl(msg.hdr->tsx[2]); 
     
    189209                    continue; 
    190210                } 
     211 
     212                /* From this part, we consider the packet as a valid STUN 
     213                 * response for our request. 
     214                 */ 
     215                --wait_resp; 
    191216 
    192217                if (pjstun_msg_find_attr(&msg, PJSTUN_ATTR_ERROR_CODE) != NULL) { 
Note: See TracChangeset for help on using the changeset viewer.