1 /* $NetBSD: t_bind.c,v 1.3 2015/04/05 23:28:10 rtr Exp $ */
3 * Copyright (c) 2015 The NetBSD Foundation, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/socket.h>
36 #include <arpa/inet.h>
37 #include <netinet/in.h>
41 ATF_TC(bind_foreign_family
);
43 ATF_TC_HEAD(bind_foreign_family
, tc
)
45 atf_tc_set_md_var(tc
, "descr", "Checks that binding a socket "
46 "with a different address family fails");
49 ATF_TC_BODY(bind_foreign_family
, tc
)
51 struct sockaddr_in addr
;
53 /* addr.sin_family = AF_UNSPEC = 0 */
54 memset(&addr
, 0, sizeof(addr
));
57 * it is not necessary to initialize sin_{addr,port} since
58 * those structure members shall not be accessed if bind
62 int sock
= socket(AF_LOCAL
, SOCK_STREAM
, 0);
63 ATF_REQUIRE(sock
!= -1);
65 /* should fail but currently doesn't */
66 ATF_REQUIRE(-1 == bind(sock
, (struct sockaddr
*)&addr
, sizeof(addr
)));
67 ATF_REQUIRE(EAFNOSUPPORT
== errno
);
75 ATF_TP_ADD_TC(tp
, bind_foreign_family
);
77 return atf_no_error();