Showing with 52 additions and 7 deletions.
  1. +1 −0 Makefile.am
  2. +2 −7 src/uv-common.c
  3. +46 −0 test/test-ip4-addr.c
  4. +2 −0 test/test-list.h
  5. +1 −0 uv.gyp
@@ -139,6 +139,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-getsockname.c \
test/test-hrtime.c \
test/test-idle.c \
test/test-ip4-addr.c \
test/test-ip6-addr.c \
test/test-ipc-send-recv.c \
test/test-ipc.c \
@@ -102,9 +102,7 @@ int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr) {
memset(addr, 0, sizeof(*addr));
addr->sin_family = AF_INET;
addr->sin_port = htons(port);
/* TODO(bnoordhuis) Don't use inet_addr(), no good way to detect errors. */
addr->sin_addr.s_addr = inet_addr(ip);
return 0;
return uv_inet_pton(AF_INET, ip, &(addr->sin_addr.s_addr));
}


@@ -140,10 +138,7 @@ int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr) {
}
#endif

/* TODO(bnoordhuis) Return an error when the address is bad. */
uv_inet_pton(AF_INET6, ip, &addr->sin6_addr);

return 0;
return uv_inet_pton(AF_INET6, ip, &addr->sin6_addr);
}


@@ -0,0 +1,46 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "uv.h"
#include "task.h"

#include <stdio.h>
#include <string.h>


TEST_IMPL(ip4_addr) {

struct sockaddr_in addr;

ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
ASSERT(0 == uv_ip4_addr("255.255.255.255", TEST_PORT, &addr));
ASSERT(UV_EINVAL == uv_ip4_addr("255.255.255*000", TEST_PORT, &addr));
ASSERT(UV_EINVAL == uv_ip4_addr("255.255.255.256", TEST_PORT, &addr));
ASSERT(UV_EINVAL == uv_ip4_addr("2555.0.0.0", TEST_PORT, &addr));
ASSERT(UV_EINVAL == uv_ip4_addr("255", TEST_PORT, &addr));

// for broken address family
ASSERT(UV_EAFNOSUPPORT == uv_inet_pton(42, "127.0.0.1",
&addr.sin_addr.s_addr));

MAKE_VALGRIND_HAPPY();
return 0;
}
@@ -217,6 +217,7 @@ TEST_DECLARE (dlerror)
TEST_DECLARE (poll_duplex)
TEST_DECLARE (poll_unidirectional)
TEST_DECLARE (poll_close)
TEST_DECLARE (ip4_addr)
TEST_DECLARE (ip6_addr_link_local)
#ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
@@ -517,6 +518,7 @@ TASK_LIST_START
TEST_ENTRY (thread_rwlock)
TEST_ENTRY (thread_create)
TEST_ENTRY (dlerror)
TEST_ENTRY (ip4_addr)
TEST_ENTRY (ip6_addr_link_local)
#if 0
/* These are for testing the test runner. */
1 uv.gyp
@@ -382,6 +382,7 @@
'test/test-udp-multicast-join.c',
'test/test-dlerror.c',
'test/test-udp-multicast-ttl.c',
'test/test-ip4-addr.c',
'test/test-ip6-addr.c',
],
'conditions': [