Sync usage with man page.
[netbsd-mini2440.git] / tests / net / sys / t_listen.c
blob31b44ed01d37afe763a331ce6fc9dd4fe17ef3dd
1 /* $NetBSD$ */
2 /*
3 * Copyright (c) 2007 The NetBSD Foundation, Inc.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
29 #include <err.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <unistd.h>
34 #include <netinet/in.h>
36 #include <atf-c.h>
38 ATF_TC(low_port);
39 ATF_TC_HEAD(low_port, tc)
41 atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation "
42 "works");
43 atf_tc_set_md_var(tc, "require.user", "root");
45 ATF_TC_BODY(low_port, tc)
47 int sd, val;
49 sd = socket(AF_INET, SOCK_STREAM, 0);
51 val = IP_PORTRANGE_LOW;
52 if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
53 sizeof(val)) == -1)
54 atf_tc_fail("setsockopt failed: %s", strerror(errno));
56 if (listen(sd, 5) == -1) {
57 int err = errno;
58 atf_tc_fail("listen failed: %s%s",
59 strerror(err),
60 err != EACCES ? "" : " (see http://mail-index.netbsd.org/"
61 "source-changes/2007/12/16/0011.html)");
64 close(sd);
67 ATF_TP_ADD_TCS(tp)
69 ATF_TP_ADD_TC(tp, low_port);