diff options
author | Renato Botelho <renato@netgate.com> | 2016-12-05 15:52:27 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-12-05 15:52:27 -0200 |
commit | ec84a59afa973e7e021ba2ae8ecae4cb6ba37b1d (patch) | |
tree | d7d40ac77bda3d6fc35814a1a6484eb324b3c7df /contrib/netbsd-tests/lib/libc/sys/t_connect.c | |
parent | ca825f0a56d174ca9d3478d87cdca9f318a50cc6 (diff) | |
parent | 356fbc072920d7e71c42b310d6bfa2d1a3d36f9f (diff) | |
download | FreeBSD-src-ec84a59afa973e7e021ba2ae8ecae4cb6ba37b1d.zip FreeBSD-src-ec84a59afa973e7e021ba2ae8ecae4cb6ba37b1d.tar.gz |
Merge remote-tracking branch 'origin/stable/11' into devel-11
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/sys/t_connect.c')
-rw-r--r-- | contrib/netbsd-tests/lib/libc/sys/t_connect.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_connect.c b/contrib/netbsd-tests/lib/libc/sys/t_connect.c index 896b490..672a022 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_connect.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_connect.c @@ -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. @@ -102,10 +102,39 @@ ATF_TC_BODY(connect_low_port, tc) #endif } +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(); } |