1#!/usr/bin/perl 2# $OpenBSD: relay.pl,v 1.3 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 Relay; 25use Server; 26require 'funcs.pl'; 27 28sub usage { 29 die "usage: relay.pl copy|splice [args-test.pl]\n"; 30} 31 32my $testfile; 33our %args; 34if (@ARGV and -f $ARGV[-1]) { 35 $testfile = pop; 36 do $testfile 37 or die "Do test file $testfile failed: ", $@ || $!; 38} 39@ARGV == 1 or usage(); 40 41my $s = Server->new( 42 func => \&read_stream, 43 listendomain => AF_INET, 44 listenaddr => "127.0.0.1", 45 oobinline => 1, 46 %{$args{server}}, 47); 48my $r = Relay->new( 49 forward => $ARGV[0], 50 func => \&relay, 51 listendomain => AF_INET, 52 listenaddr => "127.0.0.1", 53 connectdomain => AF_INET, 54 connectaddr => "127.0.0.1", 55 connectport => $s->{listenport}, 56 %{$args{relay}}, 57); 58my $c = Client->new( 59 func => \&write_stream, 60 connectdomain => AF_INET, 61 connectaddr => "127.0.0.1", 62 connectport => $r->{listenport}, 63 oobinline => 1, 64 %{$args{client}}, 65); 66 67$s->run; 68$r->run; 69$c->run->up; 70$r->up; 71$s->up; 72 73$c->down; 74$r->down; 75$s->down; 76 77check_logs($c, $r, $s, %args); 78