1157163Srwatson/*-
2157163Srwatson * Copyright (c) 2006 Robert N. M. Watson
3157163Srwatson * All rights reserved.
4157163Srwatson *
5157163Srwatson * Redistribution and use in source and binary forms, with or without
6157163Srwatson * modification, are permitted provided that the following conditions
7157163Srwatson * are met:
8157163Srwatson * 1. Redistributions of source code must retain the above copyright
9157163Srwatson *    notice, this list of conditions and the following disclaimer.
10157163Srwatson * 2. Redistributions in binary form must reproduce the above copyright
11157163Srwatson *    notice, this list of conditions and the following disclaimer in the
12157163Srwatson *    documentation and/or other materials provided with the distribution.
13157163Srwatson *
14157163Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15157163Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16157163Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17157163Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18157163Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19157163Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20157163Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21157163Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22157163Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23157163Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24157163Srwatson * SUCH DAMAGE.
25157163Srwatson *
26157163Srwatson * $FreeBSD$
27157163Srwatson */
28157163Srwatson
29157163Srwatson/*
30157163Srwatson * Exercise the pru_abort() code for SPX by opening an SPX connection to a
31157163Srwatson * listen socket, then closing the listen socket before accepting.
32157163Srwatson *
33157163Srwatson * We would also like to be able to test the other two abort cases, in which
34157163Srwatson * incomplete connections are aborted due to overflow, and due to close of
35157163Srwatson * the listen socket, but that requires a packet level test rather than using
36157163Srwatson * the socket API.
37157163Srwatson */
38157163Srwatson
39157163Srwatson#include <sys/types.h>
40157163Srwatson#include <sys/socket.h>
41157163Srwatson
42157163Srwatson#include <netipx/ipx.h>
43157163Srwatson
44157163Srwatson#include <err.h>
45157163Srwatson#include <errno.h>
46157163Srwatson#include <fcntl.h>
47157163Srwatson#include <stdio.h>
48157163Srwatson#include <string.h>
49157163Srwatson#include <unistd.h>
50157163Srwatson
51157163Srwatson#define	IPX_ENDPOINT	"0xbebe.1.0x8a13"
52157163Srwatson
53157163Srwatsonint
54157163Srwatsonmain(int argc, char *argv[])
55157163Srwatson{
56157163Srwatson	struct sockaddr_ipx sipx;
57157163Srwatson	int sock_listen, sock;
58157163Srwatson
59157163Srwatson	sock_listen = socket(PF_IPX, SOCK_STREAM, 0);
60157163Srwatson	if (sock_listen < 0)
61157163Srwatson		err(-1, "sock_listen = socket(PF_IPX, SOCK_STREAM, 0)");
62157163Srwatson
63157163Srwatson	bzero(&sipx, sizeof(sipx));
64157163Srwatson	sipx.sipx_len = sizeof(sipx);
65157163Srwatson	sipx.sipx_family = AF_IPX;
66157163Srwatson	sipx.sipx_addr = ipx_addr(IPX_ENDPOINT);
67157163Srwatson
68157163Srwatson	if (bind(sock_listen, (struct sockaddr *)&sipx, sizeof(sipx)) < 0)
69157163Srwatson		err(-1, "bind(sock_listen)");
70157163Srwatson
71157163Srwatson	if (listen(sock_listen, -1) < 0)
72157163Srwatson		err(-1, "listen(sock_listen)");
73157163Srwatson
74157163Srwatson	sock = socket(PF_IPX, SOCK_STREAM, 0);
75157163Srwatson	if (sock < 0)
76157163Srwatson		err(-1, "sock = socket(PF_IPX, SOCK_STREAM, 0)");
77157163Srwatson
78157163Srwatson	bzero(&sipx, sizeof(sipx));
79157163Srwatson	sipx.sipx_len = sizeof(sipx);
80157163Srwatson	sipx.sipx_family = AF_IPX;
81157163Srwatson	sipx.sipx_addr = ipx_addr(IPX_ENDPOINT);
82157163Srwatson
83157163Srwatson	if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0)
84157163Srwatson		err(-1, "fcntl(sock, F_SETFL, O_NONBLOCKING)");
85157163Srwatson
86157163Srwatson	if (connect(sock, (struct sockaddr *)&sipx, sizeof(sipx)) < 0) {
87157163Srwatson		if (errno != EINPROGRESS)
88157163Srwatson			err(-1, "sock = socket(PF_IPX, SOCK_STREAM, 0)");
89157163Srwatson	}
90157163Srwatson
91157163Srwatson	sleep(1);	/* Arbitrary. */
92157163Srwatson
93157163Srwatson	close(sock_listen);
94157163Srwatson
95157163Srwatson	return (0);
96157163Srwatson};
97