]> nv-tegra.nvidia Code Review - android/platform/system/extras.git/commitdiff
Add a new test to check the behaviour of getaddrinfo()
authorDavid 'Digit' Turner <digit@google.com>
Tue, 5 May 2009 13:54:39 +0000 (15:54 +0200)
committerDavid 'Digit' Turner <digit@google.com>
Tue, 5 May 2009 13:54:39 +0000 (15:54 +0200)
tests/bionic/libc/Android.mk
tests/bionic/libc/common/test_getaddrinfo.c [new file with mode: 0644]

index 89d9ade219e78bdd13a769a0a12c3582cff74fdd..c7e7305d4190e779ea9545a411a54bba2dfe54d9 100644 (file)
@@ -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 (file)
index 0000000..444bef8
--- /dev/null
@@ -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;
+}