1158577Smaxim/*-
2158577Smaxim * Copyright (c) 2006 Maxim Konovalov
3158577Smaxim * All rights reserved.
4158577Smaxim *
5158577Smaxim * Redistribution and use in source and binary forms, with or without
6158577Smaxim * modification, are permitted provided that the following conditions
7158577Smaxim * are met:
8158577Smaxim * 1. Redistributions of source code must retain the above copyright
9158577Smaxim *    notice, this list of conditions and the following disclaimer.
10158577Smaxim * 2. Redistributions in binary form must reproduce the above copyright
11158577Smaxim *    notice, this list of conditions and the following disclaimer in the
12158577Smaxim *    documentation and/or other materials provided with the distribution.
13158577Smaxim *
14158577Smaxim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15158577Smaxim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16158577Smaxim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17158577Smaxim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18158577Smaxim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19158577Smaxim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20158577Smaxim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21158577Smaxim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22158577Smaxim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23158577Smaxim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24158577Smaxim * SUCH DAMAGE.
25158577Smaxim *
26158577Smaxim * $FreeBSD: releng/10.3/tools/regression/netinet/rawconnect/rawconnect.c 158577 2006-05-14 22:03:00Z maxim $
27158577Smaxim */
28158577Smaxim
29158577Smaxim/*
30158577Smaxim * Bug in IP code panics the system at close(2) on
31158577Smaxim * connected SOCK_RAW, IPPROTO_IP socket.
32158577Smaxim */
33158577Smaxim
34158577Smaxim#include <sys/types.h>
35158577Smaxim#include <sys/socket.h>
36158577Smaxim#include <netinet/in.h>
37158577Smaxim
38158577Smaxim#include <err.h>
39158577Smaxim#include <stdio.h>
40158577Smaxim#include <stdlib.h>
41158577Smaxim#include <strings.h>
42158577Smaxim#include <unistd.h>
43158577Smaxim
44158577Smaximstatic void
45158577Smaximusage(void)
46158577Smaxim{
47158577Smaxim
48158577Smaxim	fprintf(stderr, "rawconnect: no arguments\n");
49158577Smaxim		exit(1);
50158577Smaxim}
51158577Smaxim
52158577Smaximint
53158577Smaximmain(int argc, __unused char *argv[])
54158577Smaxim{
55158577Smaxim	struct sockaddr_in sin;
56158577Smaxim	int sock;
57158577Smaxim
58158577Smaxim	if (argc != 1)
59158577Smaxim		usage();
60158577Smaxim
61158577Smaxim	bzero(&sin, sizeof(sin));
62158577Smaxim	sin.sin_len = sizeof(sin);
63158577Smaxim	sin.sin_family = AF_INET;
64158577Smaxim	sin.sin_addr.s_addr = INADDR_LOOPBACK;
65158577Smaxim	sin.sin_port = htons(65534);
66158577Smaxim
67158577Smaxim	sock = socket(PF_INET, SOCK_RAW, IPPROTO_IP);
68158577Smaxim	if (sock == -1)
69158577Smaxim		err(1, "socket");
70158577Smaxim
71158577Smaxim	if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
72158577Smaxim		err(1, "connect");
73158577Smaxim
74158577Smaxim	close(sock);
75158577Smaxim
76158577Smaxim	return (0);
77158577Smaxim}
78