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