2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2019 Bjoern A. Zeeb
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/errno.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
37 ATF_TC_WITHOUT_HEAD(socket_afinet);
38 ATF_TC_BODY(socket_afinet, tc)
42 sd = socket(PF_INET, SOCK_DGRAM, 0);
48 ATF_TC_WITHOUT_HEAD(socket_afinet_bind_zero);
49 ATF_TC_BODY(socket_afinet_bind_zero, tc)
52 struct sockaddr_in sin;
54 atf_tc_skip("doesn't work when mac_portacl(4) loaded (bug238781)");
56 sd = socket(PF_INET, SOCK_DGRAM, 0);
59 bzero(&sin, sizeof(sin));
61 * For AF_INET we do not check the family in in_pcbbind_setup(9),
62 * sa_len gets set from the syscall argument in getsockaddr(9),
65 rc = bind(sd, (struct sockaddr *)&sin, sizeof(sin));
71 ATF_TC_WITHOUT_HEAD(socket_afinet_bind_ok);
72 ATF_TC_BODY(socket_afinet_bind_ok, tc)
75 struct sockaddr_in sin;
77 sd = socket(PF_INET, SOCK_DGRAM, 0);
80 bzero(&sin, sizeof(sin));
81 sin.sin_family = AF_INET;
82 sin.sin_len = sizeof(sin);
83 sin.sin_port = htons(6666);
84 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
85 rc = bind(sd, (struct sockaddr *)&sin, sizeof(sin));
94 ATF_TP_ADD_TC(tp, socket_afinet);
95 ATF_TP_ADD_TC(tp, socket_afinet_bind_zero);
96 ATF_TP_ADD_TC(tp, socket_afinet_bind_ok);
98 return atf_no_error();