1 1.1 christos /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 1.1 christos * 3 1.1 christos * Permission is hereby granted, free of charge, to any person obtaining a copy 4 1.1 christos * of this software and associated documentation files (the "Software"), to 5 1.1 christos * deal in the Software without restriction, including without limitation the 6 1.1 christos * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 1.1 christos * sell copies of the Software, and to permit persons to whom the Software is 8 1.1 christos * furnished to do so, subject to the following conditions: 9 1.1 christos * 10 1.1 christos * The above copyright notice and this permission notice shall be included in 11 1.1 christos * all copies or substantial portions of the Software. 12 1.1 christos * 13 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 1.1 christos * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 1.1 christos * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 1.1 christos * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 1.1 christos * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 1.1 christos * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 1.1 christos * IN THE SOFTWARE. 20 1.1 christos */ 21 1.1 christos 22 1.1 christos #include "uv.h" 23 1.1 christos #include "task.h" 24 1.1 christos #include <stdio.h> 25 1.1 christos #include <stdlib.h> 26 1.1 christos #include <string.h> 27 1.1 christos 28 1.1 christos 29 1.1 christos static const char* address_ip4 = "127.0.0.1"; 30 1.1 christos static const char* address_ip6 = "::1"; 31 1.1 christos static const int port = 80; 32 1.1 christos 33 1.1 christos static struct sockaddr_in addr4; 34 1.1 christos static struct sockaddr_in6 addr6; 35 1.1 christos static uv_getnameinfo_t req; 36 1.1 christos 37 1.1 christos static void getnameinfo_req(uv_getnameinfo_t* handle, 38 1.1 christos int status, 39 1.1 christos const char* hostname, 40 1.1 christos const char* service) { 41 1.1.1.2 christos ASSERT_NOT_NULL(handle); 42 1.1.1.3 christos ASSERT_OK(status); 43 1.1.1.2 christos ASSERT_NOT_NULL(hostname); 44 1.1.1.2 christos ASSERT_NOT_NULL(service); 45 1.1 christos } 46 1.1 christos 47 1.1 christos 48 1.1 christos TEST_IMPL(getnameinfo_basic_ip4) { 49 1.1.1.2 christos /* TODO(gengjiawen): Fix test on QEMU. */ 50 1.1.1.2 christos #if defined(__QEMU__) 51 1.1.1.2 christos RETURN_SKIP("Test does not currently work in QEMU"); 52 1.1.1.2 christos #endif 53 1.1.1.2 christos 54 1.1 christos int r; 55 1.1 christos 56 1.1 christos r = uv_ip4_addr(address_ip4, port, &addr4); 57 1.1.1.3 christos ASSERT_OK(r); 58 1.1 christos 59 1.1 christos r = uv_getnameinfo(uv_default_loop(), 60 1.1 christos &req, 61 1.1 christos &getnameinfo_req, 62 1.1 christos (const struct sockaddr*)&addr4, 63 1.1 christos 0); 64 1.1.1.3 christos ASSERT_OK(r); 65 1.1 christos 66 1.1 christos uv_run(uv_default_loop(), UV_RUN_DEFAULT); 67 1.1 christos 68 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 69 1.1 christos return 0; 70 1.1 christos } 71 1.1 christos 72 1.1 christos 73 1.1 christos TEST_IMPL(getnameinfo_basic_ip4_sync) { 74 1.1 christos /* TODO(gengjiawen): Fix test on QEMU. */ 75 1.1 christos #if defined(__QEMU__) 76 1.1 christos RETURN_SKIP("Test does not currently work in QEMU"); 77 1.1 christos #endif 78 1.1 christos 79 1.1.1.3 christos ASSERT_OK(uv_ip4_addr(address_ip4, port, &addr4)); 80 1.1 christos 81 1.1.1.3 christos ASSERT_OK(uv_getnameinfo(uv_default_loop(), 82 1.1.1.3 christos &req, 83 1.1.1.3 christos NULL, 84 1.1.1.3 christos (const struct sockaddr*)&addr4, 85 1.1.1.3 christos 0)); 86 1.1.1.3 christos ASSERT_NE(req.host[0], '\0'); 87 1.1.1.3 christos ASSERT_NE(req.service[0], '\0'); 88 1.1 christos 89 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 90 1.1 christos return 0; 91 1.1 christos } 92 1.1 christos 93 1.1 christos 94 1.1 christos TEST_IMPL(getnameinfo_basic_ip6) { 95 1.1.1.2 christos /* TODO(gengjiawen): Fix test on QEMU. */ 96 1.1.1.2 christos #if defined(__QEMU__) 97 1.1.1.2 christos RETURN_SKIP("Test does not currently work in QEMU"); 98 1.1.1.2 christos #endif 99 1.1.1.2 christos 100 1.1 christos int r; 101 1.1 christos 102 1.1 christos r = uv_ip6_addr(address_ip6, port, &addr6); 103 1.1.1.3 christos ASSERT_OK(r); 104 1.1 christos 105 1.1 christos r = uv_getnameinfo(uv_default_loop(), 106 1.1 christos &req, 107 1.1 christos &getnameinfo_req, 108 1.1 christos (const struct sockaddr*)&addr6, 109 1.1 christos 0); 110 1.1.1.3 christos ASSERT_OK(r); 111 1.1 christos 112 1.1 christos uv_run(uv_default_loop(), UV_RUN_DEFAULT); 113 1.1 christos 114 1.1.1.3 christos MAKE_VALGRIND_HAPPY(uv_default_loop()); 115 1.1 christos return 0; 116 1.1 christos } 117