From ab4e50681034f2456ab5de1e93fbd115e4c29813 Mon Sep 17 00:00:00 2001 From: pooka Date: Sat, 12 Jun 2010 14:31:29 +0000 Subject: [PATCH] Connect to localhost instead of www.netbsd.org to a) make this work in non-routed setups b) avoid the dubious security implications. Also, to make the test actually do what it claims to do, call getsockname() and verify we got a low port. --- tests/net/sys/t_connect.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/net/sys/t_connect.c b/tests/net/sys/t_connect.c index 1bd702cf6460..4a45f4c067bc 100644 --- a/tests/net/sys/t_connect.c +++ b/tests/net/sys/t_connect.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_connect.c,v 1.1 2008/05/01 15:38:17 jmmv Exp $ */ +/* $NetBSD: t_connect.c,v 1.2 2010/06/12 14:31:29 pooka Exp $ */ /* * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -45,11 +45,23 @@ ATF_TC_HEAD(low_port, tc) } ATF_TC_BODY(low_port, tc) { - struct sockaddr_in sin; - int sd, val; + struct sockaddr_in sin, sinlist; + int sd, val, slist; + socklen_t slen; + slist = socket(AF_INET, SOCK_STREAM, 0); sd = socket(AF_INET, SOCK_STREAM, 0); + /* bind listening sucket */ + memset(&sinlist, 0, sizeof(sinlist)); + sinlist.sin_family = AF_INET; + sinlist.sin_port = htons(31522); + sinlist.sin_addr.s_addr = inet_addr("127.0.0.1"); + + ATF_REQUIRE_EQ(bind(slist, + (struct sockaddr *)&sinlist, sizeof(sinlist)), 0); + ATF_REQUIRE_EQ(listen(slist, 1), 0); + val = IP_PORTRANGE_LOW; if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, sizeof(val)) == -1) @@ -57,8 +69,8 @@ ATF_TC_BODY(low_port, tc) memset(&sin, 0, sizeof(sin)); - sin.sin_port = htons(80); - sin.sin_addr.s_addr = inet_addr("204.152.190.12"); /* www.NetBSD.org */ + sin.sin_port = htons(31522); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_family = AF_INET; if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { @@ -69,6 +81,11 @@ ATF_TC_BODY(low_port, tc) "source-changes/2007/12/16/0011.html)"); } + slen = sizeof(sin); + ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0); + ATF_REQUIRE_EQ(slen, sizeof(sin)); + ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX); + close(sd); }