1157139Srwatson/*-
2157139Srwatson * Copyright (c) 2006 Robert N. M. Watson
3157139Srwatson * All rights reserved.
4157139Srwatson *
5157139Srwatson * Redistribution and use in source and binary forms, with or without
6157139Srwatson * modification, are permitted provided that the following conditions
7157139Srwatson * are met:
8157139Srwatson * 1. Redistributions of source code must retain the above copyright
9157139Srwatson *    notice, this list of conditions and the following disclaimer.
10157139Srwatson * 2. Redistributions in binary form must reproduce the above copyright
11157139Srwatson *    notice, this list of conditions and the following disclaimer in the
12157139Srwatson *    documentation and/or other materials provided with the distribution.
13157139Srwatson *
14157139Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15157139Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16157139Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17157139Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18157139Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19157139Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20157139Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21157139Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22157139Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23157139Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24157139Srwatson * SUCH DAMAGE.
25157139Srwatson *
26157139Srwatson * $FreeBSD: releng/10.3/tools/regression/netipx/ipxsocket/ipxsocket.c 157146 2006-03-26 15:49:35Z rwatson $
27157139Srwatson */
28157139Srwatson
29157139Srwatson/*
30157139Srwatson * Simple regression test to open and then immediately close various types of
31157146Srwatson * PF_IPX sockets.  Run with various waits in order to make sure that the
32157146Srwatson * various IPX/SPX timers have a chance to walk the pcb lists and hit the
33157146Srwatson * sockets.
34157139Srwatson */
35157139Srwatson
36157139Srwatson#include <sys/types.h>
37157139Srwatson#include <sys/socket.h>
38157139Srwatson
39157139Srwatson#include <netipx/ipx.h>
40157139Srwatson
41157139Srwatson#include <err.h>
42157139Srwatson#include <unistd.h>
43157139Srwatson
44157146Srwatsonstatic int
45157146Srwatsonmaybe_sleep(int sec)
46157146Srwatson{
47157146Srwatson
48157146Srwatson	if (sec == 0)
49157146Srwatson		return (0);
50157146Srwatson	return (sleep(sec));
51157146Srwatson}
52157146Srwatson
53157139Srwatsonint
54157139Srwatsonmain(int argc, char *argv[])
55157139Srwatson{
56157146Srwatson	int delay, s;
57157139Srwatson
58157146Srwatson	for (delay = 0; delay < 5; delay++) {
59157146Srwatson		s = socket(PF_IPX, SOCK_DGRAM, 0);
60157146Srwatson		if (s < 0)
61157146Srwatson			warn("socket(PF_IPX, SOCK_DGRAM, 0)");
62157146Srwatson		else {
63157146Srwatson			maybe_sleep(delay);
64157146Srwatson			close(s);
65157146Srwatson		}
66157139Srwatson
67157146Srwatson		s = socket(PF_IPX, SOCK_STREAM, 0);
68157146Srwatson		if (s < 0)
69157146Srwatson			warn("socket(PF_IPX, SOCK_STREAM, 0)");
70157146Srwatson		else {
71157146Srwatson			maybe_sleep(delay);
72157146Srwatson			close(s);
73157146Srwatson		}
74157139Srwatson
75157146Srwatson		s = socket(PF_IPX, SOCK_SEQPACKET, 0);
76157146Srwatson		if (s < 0)
77157146Srwatson			warn("socket(PF_IPX, SOCK_SEQPACKET, 0)");
78157146Srwatson		else {
79157146Srwatson			maybe_sleep(delay);
80157146Srwatson			close(s);
81157146Srwatson		}
82157139Srwatson
83157146Srwatson		s = socket(PF_IPX, SOCK_RAW, 0);
84157146Srwatson		if (s < 0)
85157146Srwatson			warn("socket(PF_IPX, SOCK_RAW, 0)");
86157146Srwatson		else {
87157146Srwatson			maybe_sleep(delay);
88157146Srwatson			close(s);
89157146Srwatson		}
90157146Srwatson	}
91157139Srwatson
92157139Srwatson	return (0);
93157139Srwatson}
94