2 * Copyright (c) 2004 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/types.h>
30 #include <sys/socket.h>
39 * Open, then close a set of UNIX domain socket pairs for datagram and
42 * Confirm that we can't open INET datagram or stream socket pairs.
44 * More tests should be added, including confirming that sending on either
45 * endpoint results in data at the other, that the right kind of socket was
46 * created (stream vs. datagram), and that message boundaries fall in the
50 main(int argc, char *argv[])
55 * UNIX domain socket pair, datagram.
57 if (socketpair(PF_UNIX, SOCK_DGRAM, 0, sv) != 0) {
58 fprintf(stderr, "socketpair(PF_UNIX, SOCK_DGRAM): %s\n",
60 fprintf(stderr, "FAIL\n");
63 if (close(sv[0]) != 0) {
64 fprintf(stderr, "socketpair(PF_UNIX, SOCK_DGRAM) close 0: %s\n",
66 fprintf(stderr, "FAIL\n");
69 if (close(sv[1]) != 0) {
70 fprintf(stderr, "socketpair(PF_UNIX, SOCK_DGRAM) close 1: %s\n",
72 fprintf(stderr, "FAIL\n");
77 * UNIX domain socket pair, stream.
79 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) != 0) {
80 fprintf(stderr, "socketpair(PF_UNIX, SOCK_STREAM): %s\n",
82 fprintf(stderr, "FAIL\n");
85 if (close(sv[0]) != 0) {
86 fprintf(stderr, "socketpair(PF_UNIX, SOCK_STREAM) close 0: %s\n",
88 fprintf(stderr, "FAIL\n");
91 if (close(sv[1]) != 0) {
92 fprintf(stderr, "socketpair(PF_UNIX, SOCK_STREAM) close 1: "
93 "%s\n", strerror(errno));
94 fprintf(stderr, "FAIL\n");
99 * Confirm that PF_INET datagram socket pair creation fails.
101 if (socketpair(PF_INET, SOCK_DGRAM, 0, sv) == 0) {
102 fprintf(stderr, "socketpair(PF_INET, SOCK_DGRAM): opened\n");
103 fprintf(stderr, "FAIL\n");
106 if (errno != EOPNOTSUPP) {
107 fprintf(stderr, "socketpair(PF_INET, SOCK_DGRAM): %s\n",
109 fprintf(stderr, "FAIL\n");
113 * Confirm that PF_INET stream socket pair creation fails.
115 if (socketpair(PF_INET, SOCK_STREAM, 0, sv) == 0) {
116 fprintf(stderr, "socketpair(PF_INET, SOCK_STREAM): opened\n");
117 fprintf(stderr, "FAIL\n");
120 if (errno != EOPNOTSUPP) {
121 fprintf(stderr, "socketpair(PF_INET, SOCK_STREAM): %s\n",
123 fprintf(stderr, "FAIL\n");
126 fprintf(stderr, "PASS\n");