xref: /openbsd-src/regress/usr.sbin/relayd/direct.pl (revision aa8f13000c8e201a15f3d7fbf27406f6d379b00c)
1#!/usr/bin/perl
2#	$OpenBSD: direct.pl,v 1.3 2014/08/18 22:58:19 bluhm Exp $
3
4# Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18use strict;
19use warnings;
20use Socket;
21use Socket6;
22
23use Client;
24use Server;
25require 'funcs.pl';
26
27sub usage {
28	die "usage: direct.pl [test-args.pl]\n";
29}
30
31my $testfile;
32our %args;
33if (@ARGV and -f $ARGV[-1]) {
34	$testfile = pop;
35	do $testfile
36	    or die "Do test file $testfile failed: ", $@ || $!;
37}
38
39@ARGV == 0 or usage();
40
41my $s = Server->new(
42    func		=> \&read_char,
43    %{$args{server}},
44    listendomain	=> AF_INET,
45    listenaddr		=> "127.0.0.1",
46);
47my $c = Client->new(
48    func		=> \&write_char,
49    %{$args{client}},
50    connectdomain	=> AF_INET,
51    connectaddr		=> "127.0.0.1",
52    connectport		=> $s->{listenport},
53);
54
55$s->run;
56$c->run->up;
57$s->up;
58
59$c->down;
60$s->down;
61
62check_logs($c, undef, $s, %args);
63