1*3d11b6c8SRobert Watson /*- 2*3d11b6c8SRobert Watson * Copyright (c) 2006 Robert N. M. Watson 3*3d11b6c8SRobert Watson * All rights reserved. 4*3d11b6c8SRobert Watson * 5*3d11b6c8SRobert Watson * Redistribution and use in source and binary forms, with or without 6*3d11b6c8SRobert Watson * modification, are permitted provided that the following conditions 7*3d11b6c8SRobert Watson * are met: 8*3d11b6c8SRobert Watson * 1. Redistributions of source code must retain the above copyright 9*3d11b6c8SRobert Watson * notice, this list of conditions and the following disclaimer. 10*3d11b6c8SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 11*3d11b6c8SRobert Watson * notice, this list of conditions and the following disclaimer in the 12*3d11b6c8SRobert Watson * documentation and/or other materials provided with the distribution. 13*3d11b6c8SRobert Watson * 14*3d11b6c8SRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*3d11b6c8SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*3d11b6c8SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*3d11b6c8SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*3d11b6c8SRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*3d11b6c8SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*3d11b6c8SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*3d11b6c8SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*3d11b6c8SRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*3d11b6c8SRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*3d11b6c8SRobert Watson * SUCH DAMAGE. 25*3d11b6c8SRobert Watson * 26*3d11b6c8SRobert Watson * $FreeBSD$ 27*3d11b6c8SRobert Watson */ 28*3d11b6c8SRobert Watson 29*3d11b6c8SRobert Watson /* 30*3d11b6c8SRobert Watson * Simple UNIX domain socket regression test: create and tear down various 31*3d11b6c8SRobert Watson * supported and unsupported socket types. 32*3d11b6c8SRobert Watson */ 33*3d11b6c8SRobert Watson 34*3d11b6c8SRobert Watson #include <sys/types.h> 35*3d11b6c8SRobert Watson #include <sys/socket.h> 36*3d11b6c8SRobert Watson #include <sys/un.h> 37*3d11b6c8SRobert Watson 38*3d11b6c8SRobert Watson #include <err.h> 39*3d11b6c8SRobert Watson #include <errno.h> 40*3d11b6c8SRobert Watson #include <unistd.h> 41*3d11b6c8SRobert Watson 42*3d11b6c8SRobert Watson int 43*3d11b6c8SRobert Watson main(int argc, char *argv[]) 44*3d11b6c8SRobert Watson { 45*3d11b6c8SRobert Watson int sock, socks[2]; 46*3d11b6c8SRobert Watson 47*3d11b6c8SRobert Watson sock = socket(PF_LOCAL, SOCK_STREAM, 0); 48*3d11b6c8SRobert Watson if (sock < 0) 49*3d11b6c8SRobert Watson err(-1, "socket(PF_LOCAL, SOCK_STREAM, 0)"); 50*3d11b6c8SRobert Watson close(sock); 51*3d11b6c8SRobert Watson 52*3d11b6c8SRobert Watson sock = socket(PF_LOCAL, SOCK_DGRAM, 0); 53*3d11b6c8SRobert Watson if (sock < 0) 54*3d11b6c8SRobert Watson err(-1, "socket(PF_LOCAL, SOCK_DGRAM, 0)"); 55*3d11b6c8SRobert Watson close(sock); 56*3d11b6c8SRobert Watson 57*3d11b6c8SRobert Watson sock = socket(PF_LOCAL, SOCK_RAW, 0); 58*3d11b6c8SRobert Watson if (sock >= 0) { 59*3d11b6c8SRobert Watson close(sock); 60*3d11b6c8SRobert Watson errx(-1, "socket(PF_LOCAL, SOCK_RAW, 0) returned %d", sock); 61*3d11b6c8SRobert Watson } 62*3d11b6c8SRobert Watson if (errno != EPROTONOSUPPORT) 63*3d11b6c8SRobert Watson err(-1, "socket(PF_LOCAL, SOCK_RAW, 0)"); 64*3d11b6c8SRobert Watson 65*3d11b6c8SRobert Watson if (socketpair(PF_LOCAL, SOCK_STREAM, 0, socks) < 0) 66*3d11b6c8SRobert Watson err(-1, "socketpair(PF_LOCAL, SOCK_STREAM, 0, socks)"); 67*3d11b6c8SRobert Watson if (socks[0] < 0) 68*3d11b6c8SRobert Watson errx(-1, "socketpair(PF_LOCAL, SOCK_STREAM, 0, socks) [0] < 0"); 69*3d11b6c8SRobert Watson if (socks[1] < 0) 70*3d11b6c8SRobert Watson errx(-1, "socketpair(PF_LOCAL, SOCK_STREAM, 0, socks) [1] < 1"); 71*3d11b6c8SRobert Watson close(socks[0]); 72*3d11b6c8SRobert Watson close(socks[1]); 73*3d11b6c8SRobert Watson 74*3d11b6c8SRobert Watson if (socketpair(PF_LOCAL, SOCK_DGRAM, 0, socks) < 0) 75*3d11b6c8SRobert Watson err(-1, "socketpair(PF_LOCAL, SOCK_DGRAM, 0, socks)"); 76*3d11b6c8SRobert Watson if (socks[0] < 0) 77*3d11b6c8SRobert Watson errx(-1, "socketpair(PF_LOCAL, SOCK_DGRAM, 0, socks) [0] < 0"); 78*3d11b6c8SRobert Watson if (socks[1] < 0) 79*3d11b6c8SRobert Watson errx(-1, "socketpair(PF_LOCAL, SOCK_DGRAM, 0, socks) [1] < 1"); 80*3d11b6c8SRobert Watson close(socks[0]); 81*3d11b6c8SRobert Watson close(socks[1]); 82*3d11b6c8SRobert Watson 83*3d11b6c8SRobert Watson return (0); 84*3d11b6c8SRobert Watson } 85