diff options
author | Nanang Izzuddin <nanang@teluu.com> | 2010-01-04 16:54:50 +0000 |
---|---|---|
committer | Nanang Izzuddin <nanang@teluu.com> | 2010-01-04 16:54:50 +0000 |
commit | 2e7c2feace463e9dc191465271866b51d79e4f1f (patch) | |
tree | b5178f94aa2d7be1f32951bd3e37bb47a4a148f2 /pjlib/src/pjlib-test | |
parent | 2507130ab774b4f3bc9d9d2021629f5dbf111404 (diff) |
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).
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3044 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r-- | pjlib/src/pjlib-test/sock.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/pjlib/src/pjlib-test/sock.c b/pjlib/src/pjlib-test/sock.c index 30c87711..d64586bc 100644 --- a/pjlib/src/pjlib-test/sock.c +++ b/pjlib/src/pjlib-test/sock.c @@ -72,6 +72,18 @@ static char bigdata[BIG_DATA_LEN]; static char bigbuffer[BIG_DATA_LEN]; +/* Macro for checking the value of "sin_len" member of sockaddr + * (it must always be zero). + */ +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 +# define CHECK_SA_ZERO_LEN(addr, ret) \ + if (((pj_addr_hdr*)(addr))->sa_zero_len != 0) \ + return ret +#else +# define CHECK_SA_ZERO_LEN(addr, ret) +#endif + + static int format_test(void) { pj_str_t s = pj_str(ADDRESS); @@ -284,6 +296,9 @@ static int parse_test(void) return -10; } + /* Check "sin_len" member of parse result */ + CHECK_SA_ZERO_LEN(&addr, -20); + /* Build the correct result */ status = pj_sockaddr_init(valid_tests[i].result_af, &result, @@ -312,6 +327,9 @@ static int parse_test(void) return -50; } + /* Check "sin_len" member of parse result */ + CHECK_SA_ZERO_LEN(&addr, -55); + /* Compare the result again */ if (pj_sockaddr_cmp(&addr, &result) != 0) { PJ_LOG(1,("test", ".... parsed result mismatched for %s", @@ -351,6 +369,68 @@ static int parse_test(void) return 0; } +static int purity_test(void) +{ + PJ_LOG(3,("test", "...purity_test()")); + +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + /* Check on "sin_len" member of sockaddr */ + { + const pj_str_t str_ip = {"1.1.1.1", 7}; + pj_sockaddr addr[16]; + pj_addrinfo ai[16]; + unsigned cnt; + pj_status_t rc; + + /* pj_enum_ip_interface() */ + cnt = PJ_ARRAY_SIZE(addr); + rc = pj_enum_ip_interface(pj_AF_UNSPEC(), &cnt, addr); + if (rc == PJ_SUCCESS) { + while (cnt--) + CHECK_SA_ZERO_LEN(&addr[cnt], -10); + } + + /* pj_gethostip() on IPv4 */ + rc = pj_gethostip(pj_AF_INET(), &addr[0]); + if (rc == PJ_SUCCESS) + CHECK_SA_ZERO_LEN(&addr[0], -20); + + /* pj_gethostip() on IPv6 */ + rc = pj_gethostip(pj_AF_INET6(), &addr[0]); + if (rc == PJ_SUCCESS) + CHECK_SA_ZERO_LEN(&addr[0], -30); + + /* pj_getdefaultipinterface() on IPv4 */ + rc = pj_getdefaultipinterface(pj_AF_INET(), &addr[0]); + if (rc == PJ_SUCCESS) + CHECK_SA_ZERO_LEN(&addr[0], -40); + + /* pj_getdefaultipinterface() on IPv6 */ + rc = pj_getdefaultipinterface(pj_AF_INET6(), &addr[0]); + if (rc == PJ_SUCCESS) + CHECK_SA_ZERO_LEN(&addr[0], -50); + + /* pj_getaddrinfo() on a host name */ + cnt = PJ_ARRAY_SIZE(ai); + rc = pj_getaddrinfo(pj_AF_UNSPEC(), pj_gethostname(), &cnt, ai); + if (rc == PJ_SUCCESS) { + while (cnt--) + CHECK_SA_ZERO_LEN(&ai[cnt].ai_addr, -60); + } + + /* pj_getaddrinfo() on an IP address */ + cnt = PJ_ARRAY_SIZE(ai); + rc = pj_getaddrinfo(pj_AF_UNSPEC(), &str_ip, &cnt, ai); + if (rc == PJ_SUCCESS) { + pj_assert(cnt == 1); + CHECK_SA_ZERO_LEN(&ai[0].ai_addr, -70); + } + } +#endif + + return 0; +} + static int simple_sock_test(void) { int types[2]; @@ -760,6 +840,10 @@ int sock_test() if (rc != 0) return rc; + rc = purity_test(); + if (rc != 0) + return rc; + rc = gethostbyname_test(); if (rc != 0) return rc; |