142d0cbarwatson/*-
242d0cbarwatson * Copyright (c) 2006 Robert N. M. Watson
342d0cbarwatson * All rights reserved.
442d0cbarwatson *
542d0cbarwatson * Redistribution and use in source and binary forms, with or without
642d0cbarwatson * modification, are permitted provided that the following conditions
742d0cbarwatson * are met:
842d0cbarwatson * 1. Redistributions of source code must retain the above copyright
942d0cbarwatson *    notice, this list of conditions and the following disclaimer.
1042d0cbarwatson * 2. Redistributions in binary form must reproduce the above copyright
1142d0cbarwatson *    notice, this list of conditions and the following disclaimer in the
1242d0cbarwatson *    documentation and/or other materials provided with the distribution.
1342d0cbarwatson *
1442d0cbarwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1542d0cbarwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1642d0cbarwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1742d0cbarwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1842d0cbarwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1942d0cbarwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2042d0cbarwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2142d0cbarwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2242d0cbarwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2342d0cbarwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2442d0cbarwatson * SUCH DAMAGE.
2542d0cbarwatson *
2642d0cbarwatson * $FreeBSD$
2742d0cbarwatson */
2842d0cbarwatson
2942d0cbarwatson#include <sys/socket.h>
3042d0cbarwatson
318ccc47arwatson#include <netinet/in.h>
328ccc47arwatson
3342d0cbarwatson#include <err.h>
348ccc47arwatson#include <string.h>
3542d0cbarwatson#include <unistd.h>
3642d0cbarwatson
3742d0cbarwatson/*
3842d0cbarwatson * Simple regression test to create and close a variety of IPv6 socket types.
3942d0cbarwatson */
4042d0cbarwatson
4142d0cbarwatsonint
4242d0cbarwatsonmain(int argc, char *argv[])
4342d0cbarwatson{
448ccc47arwatson	struct sockaddr_in6 sin6;
4542d0cbarwatson	int s;
4642d0cbarwatson
478ccc47arwatson	/*
488ccc47arwatson	 * UDPv6 simple test.
498ccc47arwatson	 */
508ccc47arwatson	s = socket(PF_INET6, SOCK_DGRAM, 0);
518ccc47arwatson	if (s < 0)
528ccc47arwatson		err(-1, "socket(PF_INET6, SOCK_DGRAM, 0)");
538ccc47arwatson	close(s);
548ccc47arwatson
558ccc47arwatson	/*
568ccc47arwatson	 * UDPv6 connected case -- connect UDPv6 to an arbitrary port so that
578ccc47arwatson	 * when we close the socket, it goes through the disconnect logic.
588ccc47arwatson	 */
5942d0cbarwatson	s = socket(PF_INET6, SOCK_DGRAM, 0);
6042d0cbarwatson	if (s < 0)
6142d0cbarwatson		err(-1, "socket(PF_INET6, SOCK_DGRAM, 0)");
628ccc47arwatson	bzero(&sin6, sizeof(sin6));
638ccc47arwatson	sin6.sin6_len = sizeof(sin6);
648ccc47arwatson	sin6.sin6_family = AF_INET6;
658ccc47arwatson	sin6.sin6_addr = in6addr_loopback;
668ccc47arwatson	sin6.sin6_port = htons(1024);
678ccc47arwatson	if (connect(s, (struct sockaddr *)&sin6, sizeof(sin6)) < 0)
688ccc47arwatson		err(-1, "connect(SOCK_DGRAM, ::1)");
6942d0cbarwatson	close(s);
7042d0cbarwatson
718ccc47arwatson	/*
728ccc47arwatson	 * TCPv6.
738ccc47arwatson	 */
7442d0cbarwatson	s = socket(PF_INET6, SOCK_STREAM, 0);
7542d0cbarwatson	if (s < 0)
7642d0cbarwatson		err(-1, "socket(PF_INET6, SOCK_STREAM, 0)");
7742d0cbarwatson	close(s);
7842d0cbarwatson
798ccc47arwatson	/*
808ccc47arwatson	 * Raw IPv6.
818ccc47arwatson	 */
8242d0cbarwatson	s = socket(PF_INET6, SOCK_RAW, 0);
8342d0cbarwatson	if (s < 0)
8442d0cbarwatson		err(-1, "socket(PF_INET6, SOCK_RAW, 0)");
8542d0cbarwatson	close(s);
8642d0cbarwatson
8742d0cbarwatson	return (0);
8842d0cbarwatson}
89