1#!/usr/bin/perl 2# $OpenBSD: direct.pl,v 1.4 2017/10/27 16:59:14 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 [args-test.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@ARGV == 0 or usage(); 39 40my $s = Server->new( 41 idle => 4, 42 func => \&read_datagram, 43 %{$args{server}}, 44 protocol => "udp", 45 listendomain => AF_INET, 46 listenaddr => "127.0.0.1", 47); 48my $c = Client->new( 49 func => \&write_datagram, 50 %{$args{client}}, 51 protocol => "udp", 52 connectdomain => AF_INET, 53 connectaddr => "127.0.0.1", 54 connectport => $s->{listenport}, 55); 56 57$s->run; 58$c->run->up; 59$s->up; 60 61$c->down; 62$s->down; 63 64check_logs($c, undef, $s, %args); 65