Add a test case for closing a UDPv6 socket that has been connected to

the IPv6 loopback address.

Warns ?= 2.
This commit is contained in:
Robert Watson 2006-07-19 12:54:14 +00:00
parent 9b498b31a9
commit 13496464e5
2 changed files with 30 additions and 0 deletions

View File

@ -4,5 +4,6 @@
PROG= ip6_sockets
NO_MAN=
WARNS?= 2
.include <bsd.prog.mk>

View File

@ -28,7 +28,10 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <err.h>
#include <string.h>
#include <unistd.h>
/*
@ -38,18 +41,44 @@
int
main(int argc, char *argv[])
{
struct sockaddr_in6 sin6;
int s;
/*
* UDPv6 simple test.
*/
s = socket(PF_INET6, SOCK_DGRAM, 0);
if (s < 0)
err(-1, "socket(PF_INET6, SOCK_DGRAM, 0)");
close(s);
/*
* UDPv6 connected case -- connect UDPv6 to an arbitrary port so that
* when we close the socket, it goes through the disconnect logic.
*/
s = socket(PF_INET6, SOCK_DGRAM, 0);
if (s < 0)
err(-1, "socket(PF_INET6, SOCK_DGRAM, 0)");
bzero(&sin6, sizeof(sin6));
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = in6addr_loopback;
sin6.sin6_port = htons(1024);
if (connect(s, (struct sockaddr *)&sin6, sizeof(sin6)) < 0)
err(-1, "connect(SOCK_DGRAM, ::1)");
close(s);
/*
* TCPv6.
*/
s = socket(PF_INET6, SOCK_STREAM, 0);
if (s < 0)
err(-1, "socket(PF_INET6, SOCK_STREAM, 0)");
close(s);
/*
* Raw IPv6.
*/
s = socket(PF_INET6, SOCK_RAW, 0);
if (s < 0)
err(-1, "socket(PF_INET6, SOCK_RAW, 0)");