libuv-svace-build
129 строк · 4.0 Кб
1/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy
4* of this software and associated documentation files (the "Software"), to
5* deal in the Software without restriction, including without limitation the
6* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7* sell copies of the Software, and to permit persons to whom the Software is
8* furnished to do so, subject to the following conditions:
9*
10* The above copyright notice and this permission notice shall be included in
11* all copies or substantial portions of the Software.
12*
13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19* IN THE SOFTWARE.
20*/
21
22#include "uv.h"23#include "task.h"24#include <stdio.h>25#include <stdlib.h>26#include <string.h>27
28
29static int connect_cb_called = 0;30static int close_cb_called = 0;31
32
33static void connect_cb(uv_connect_t* handle, int status) {34ASSERT_NOT_NULL(handle);35connect_cb_called++;36}
37
38
39static void close_cb(uv_handle_t* handle) {40ASSERT_NOT_NULL(handle);41close_cb_called++;42}
43
44
45TEST_IMPL(tcp_connect6_error_fault) {46const char garbage[] =47"blah blah blah blah blah blah blah blah blah blah blah blah";48const struct sockaddr_in6* garbage_addr;49uv_tcp_t server;50int r;51uv_connect_t req;52
53if (!can_ipv6())54RETURN_SKIP("IPv6 not supported");55
56garbage_addr = (const struct sockaddr_in6*) &garbage;57
58r = uv_tcp_init(uv_default_loop(), &server);59ASSERT_OK(r);60r = uv_tcp_connect(&req,61&server,62(const struct sockaddr*) garbage_addr,63connect_cb);64ASSERT_EQ(r, UV_EINVAL);65
66uv_close((uv_handle_t*)&server, close_cb);67
68uv_run(uv_default_loop(), UV_RUN_DEFAULT);69
70ASSERT_OK(connect_cb_called);71ASSERT_EQ(1, close_cb_called);72
73MAKE_VALGRIND_HAPPY(uv_default_loop());74return 0;75}
76
77
78TEST_IMPL(tcp_connect6_link_local) {79uv_interface_address_t* ifs;80uv_interface_address_t* p;81struct sockaddr_in6 addr;82uv_connect_t req;83uv_tcp_t server;84int ok;85int n;86
87if (!can_ipv6())88RETURN_SKIP("IPv6 not supported");89
90#if defined(__QEMU__)91/* qemu's sockaddr_in6 translation is broken pre-qemu 8.0.092* when host endianness != guest endiannes.
93* Fixed in https://github.com/qemu/qemu/commit/44cf6731d6b.
94*/
95RETURN_SKIP("Test does not currently work in QEMU");96#endif /* defined(__QEMU__) */97
98/* Check there's an interface that routes link-local (fe80::/10) traffic. */99ASSERT_OK(uv_interface_addresses(&ifs, &n));100for (p = ifs; p < &ifs[n]; p++)101if (p->address.address6.sin6_family == AF_INET6)102if (!memcmp(&p->address.address6.sin6_addr, "\xfe\x80", 2))103break;104ok = (p < &ifs[n]);105uv_free_interface_addresses(ifs, n);106
107if (!ok)108RETURN_SKIP("IPv6 link-local traffic not supported");109
110ASSERT_OK(uv_ip6_addr("fe80::0bad:babe", 1337, &addr));111ASSERT_OK(uv_tcp_init(uv_default_loop(), &server));112
113/* We're making two shaky assumptions here:114* 1. There is a network interface that routes IPv6 link-local traffic, and
115* 2. There is no firewall rule that blackholes or otherwise hard-kills the
116* connection attempt to the address above, i.e., we don't expect the
117* connect() system call to fail synchronously.
118*/
119ASSERT_OK(uv_tcp_connect(&req,120&server,121(struct sockaddr*) &addr,122connect_cb));123
124uv_close((uv_handle_t*) &server, NULL);125ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));126
127MAKE_VALGRIND_HAPPY(uv_default_loop());128return 0;129}
130