Module Name:    src
Committed By:   rtr
Date:           Sun Apr  5 23:17:41 UTC 2015

Modified Files:
        src/tests/lib/libc/sys: t_connect.c

Log Message:
add another test program for connect(2) that checks that connect fails
with EAFNOSUPPORT (similar to the bind test) if the domain of the socket
does not match the address family of the supplied address.

test currently fails as it should


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_connect.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_connect.c
diff -u src/tests/lib/libc/sys/t_connect.c:1.1 src/tests/lib/libc/sys/t_connect.c:1.2
--- src/tests/lib/libc/sys/t_connect.c:1.1	Sat Nov  5 18:19:02 2011
+++ src/tests/lib/libc/sys/t_connect.c	Sun Apr  5 23:17:41 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_connect.c,v 1.1 2011/11/05 18:19:02 jruoho Exp $	*/
+/*	$NetBSD: t_connect.c,v 1.2 2015/04/05 23:17:41 rtr Exp $	*/
 /*
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -90,10 +90,39 @@ ATF_TC_BODY(connect_low_port, tc)
 	close(sd);
 }
 
+ATF_TC(connect_foreign_family);
+ATF_TC_HEAD(connect_foreign_family, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks that connecting a socket "
+	    "with a different address family fails");
+}
+ATF_TC_BODY(connect_foreign_family, tc)
+{
+	struct sockaddr_in addr;
+
+	/* addr.sin_family = AF_UNSPEC = 0 */
+	memset(&addr, 0, sizeof(addr));
+
+	/*
+	 * it is not necessary to initialize sin_{addr,port} since
+	 * those structure members shall not be accessed if connect
+	 * fails correctly.
+	 */
+
+	int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
+	ATF_REQUIRE(sock != -1);
+
+	ATF_REQUIRE(-1 == connect(sock, (struct sockaddr *)&addr, sizeof(addr)));
+	ATF_REQUIRE(EAFNOSUPPORT == errno);
+
+	close(sock);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, connect_low_port);
+	ATF_TP_ADD_TC(tp, connect_foreign_family);
 
 	return atf_no_error();
 }

Reply via email to