Ignore:
Timestamp:
Jan 4, 2010 4:54:50 PM (14 years ago)
Author:
nanang
Message:

Ticket #1010:

  • Fixed bug in some APIs of address resolver and IP helper to reset sin_len member of sockaddr.
  • Added purity test of sin_len member checking in pjlib test.
  • Fixed bug in pj_getaddrinfo() when address family param set to PJ_AF_UNSPEC (assertion raised as it called pj_sockaddr_get_addr() with PJ_AF_UNSPEC too).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pjlib-test/sock.c

    r3016 r3044  
    7272static char bigdata[BIG_DATA_LEN]; 
    7373static char bigbuffer[BIG_DATA_LEN]; 
     74 
     75/* Macro for checking the value of "sin_len" member of sockaddr 
     76 * (it must always be zero). 
     77 */ 
     78#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 
     79#   define CHECK_SA_ZERO_LEN(addr, ret) \ 
     80        if (((pj_addr_hdr*)(addr))->sa_zero_len != 0) \ 
     81            return ret 
     82#else 
     83#   define CHECK_SA_ZERO_LEN(addr, ret) 
     84#endif 
     85 
    7486 
    7587static int format_test(void) 
     
    285297        } 
    286298 
     299        /* Check "sin_len" member of parse result */ 
     300        CHECK_SA_ZERO_LEN(&addr, -20); 
     301 
    287302        /* Build the correct result */ 
    288303        status = pj_sockaddr_init(valid_tests[i].result_af, 
     
    312327            return -50; 
    313328        } 
     329 
     330        /* Check "sin_len" member of parse result */ 
     331        CHECK_SA_ZERO_LEN(&addr, -55); 
    314332 
    315333        /* Compare the result again */ 
     
    348366        } 
    349367    } 
     368 
     369    return 0; 
     370} 
     371 
     372static int purity_test(void) 
     373{ 
     374    PJ_LOG(3,("test", "...purity_test()")); 
     375 
     376#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 
     377    /* Check on "sin_len" member of sockaddr */ 
     378    { 
     379        const pj_str_t str_ip = {"1.1.1.1", 7}; 
     380        pj_sockaddr addr[16]; 
     381        pj_addrinfo ai[16]; 
     382        unsigned cnt; 
     383        pj_status_t rc; 
     384 
     385        /* pj_enum_ip_interface() */ 
     386        cnt = PJ_ARRAY_SIZE(addr); 
     387        rc = pj_enum_ip_interface(pj_AF_UNSPEC(), &cnt, addr); 
     388        if (rc == PJ_SUCCESS) { 
     389            while (cnt--) 
     390                CHECK_SA_ZERO_LEN(&addr[cnt], -10); 
     391        } 
     392 
     393        /* pj_gethostip() on IPv4 */ 
     394        rc = pj_gethostip(pj_AF_INET(), &addr[0]); 
     395        if (rc == PJ_SUCCESS) 
     396            CHECK_SA_ZERO_LEN(&addr[0], -20); 
     397 
     398        /* pj_gethostip() on IPv6 */ 
     399        rc = pj_gethostip(pj_AF_INET6(), &addr[0]); 
     400        if (rc == PJ_SUCCESS) 
     401            CHECK_SA_ZERO_LEN(&addr[0], -30); 
     402 
     403        /* pj_getdefaultipinterface() on IPv4 */ 
     404        rc = pj_getdefaultipinterface(pj_AF_INET(), &addr[0]); 
     405        if (rc == PJ_SUCCESS) 
     406            CHECK_SA_ZERO_LEN(&addr[0], -40); 
     407 
     408        /* pj_getdefaultipinterface() on IPv6 */ 
     409        rc = pj_getdefaultipinterface(pj_AF_INET6(), &addr[0]); 
     410        if (rc == PJ_SUCCESS) 
     411            CHECK_SA_ZERO_LEN(&addr[0], -50); 
     412 
     413        /* pj_getaddrinfo() on a host name */ 
     414        cnt = PJ_ARRAY_SIZE(ai); 
     415        rc = pj_getaddrinfo(pj_AF_UNSPEC(), pj_gethostname(), &cnt, ai); 
     416        if (rc == PJ_SUCCESS) { 
     417            while (cnt--) 
     418                CHECK_SA_ZERO_LEN(&ai[cnt].ai_addr, -60); 
     419        } 
     420 
     421        /* pj_getaddrinfo() on an IP address */ 
     422        cnt = PJ_ARRAY_SIZE(ai); 
     423        rc = pj_getaddrinfo(pj_AF_UNSPEC(), &str_ip, &cnt, ai); 
     424        if (rc == PJ_SUCCESS) { 
     425            pj_assert(cnt == 1); 
     426            CHECK_SA_ZERO_LEN(&ai[0].ai_addr, -70); 
     427        } 
     428    } 
     429#endif 
    350430 
    351431    return 0; 
     
    761841        return rc; 
    762842 
     843    rc = purity_test(); 
     844    if (rc != 0) 
     845        return rc; 
     846 
    763847    rc = gethostbyname_test(); 
    764848    if (rc != 0) 
Note: See TracChangeset for help on using the changeset viewer.