diff options
author | David 'Digit' Turner <digit@google.com> | 2009-05-05 07:11:42 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-05-05 07:11:42 -0700 |
commit | e09db60c180b0380811bc03ac2e2ff439cbe7e09 (patch) | |
tree | 463df68b529edc6a081d813d44291cbc8b5078e2 | |
parent | c69163b9339a8e9e326c8865403d290923d2308e (diff) | |
parent | ac6a88edbf65ff3f9e40d6e4bf1e55a002be6d6c (diff) | |
download | extras-e09db60c180b0380811bc03ac2e2ff439cbe7e09.tar.gz |
am ac6a88e: Add a new test to check the behaviour of getaddrinfo()
Merge commit 'ac6a88edbf65ff3f9e40d6e4bf1e55a002be6d6c'
* commit 'ac6a88edbf65ff3f9e40d6e4bf1e55a002be6d6c':
Add a new test to check the behaviour of getaddrinfo()
-rw-r--r-- | tests/bionic/libc/Android.mk | 1 | ||||
-rw-r--r-- | tests/bionic/libc/common/test_getaddrinfo.c | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/bionic/libc/Android.mk b/tests/bionic/libc/Android.mk index a82771a1..63abd3a1 100644 --- a/tests/bionic/libc/Android.mk +++ b/tests/bionic/libc/Android.mk @@ -59,6 +59,7 @@ endef # First, the tests in 'common' sources := \ + common/test_getaddrinfo.c \ common/test_gethostbyname.c \ common/test_gethostname.c \ common/test_pthread_cleanup_push.c \ diff --git a/tests/bionic/libc/common/test_getaddrinfo.c b/tests/bionic/libc/common/test_getaddrinfo.c new file mode 100644 index 00000000..444bef8e --- /dev/null +++ b/tests/bionic/libc/common/test_getaddrinfo.c @@ -0,0 +1,44 @@ +/* this program is used to test that getaddrinfo() works correctly + * without a 'hints' argument + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> + +#include <stdio.h> /* for printf */ +#include <string.h> /* for memset */ +#include <netinet/in.h> /* for IPPROTO_TCP */ + +#define SERVER_NAME "www.android.com" +#define PORT_NUMBER "9999" + +int main(void) +{ + struct addrinfo hints; + struct addrinfo* res; + int ret; + + /* first, try without any hints */ + ret = getaddrinfo( SERVER_NAME, PORT_NUMBER, NULL, &res); + if (ret != 0) { + printf("first getaddrinfo returned error: %s\n", gai_strerror(ret)); + return 1; + } + + freeaddrinfo(res); + + /* now try with the hints */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + ret = getaddrinfo( SERVER_NAME, PORT_NUMBER, &hints, &res ); + if (ret != 0) { + printf("second getaddrinfo returned error: %s\n", gai_strerror(ret)); + return 1; + } + + return 0; +} |