-# $OpenBSD: funcs.pl,v 1.9 2017/11/08 22:14:02 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.10 2024/06/14 15:12:57 bluhm Exp $
# Copyright (c) 2010-2017 Alexander Bluhm <bluhm@openbsd.org>
#
use strict;
use warnings;
-no warnings 'experimental::smartmatch';
-use feature 'switch';
use Errno;
use Digest::MD5;
use IO::Socket qw(sockatmark);
$ctx->add($char);
print $char
or die ref($self), " print failed: $!";
- given ($char) {
- when(/9/) { $char = 'A' }
- when(/Z/) { $char = 'a' }
- when(/z/) { $char = "\n" }
- when(/\n/) { print STDERR "."; $char = '0' }
- default { $char++ }
- }
+ if ($char =~ /9/) { $char = 'A' }
+ elsif ($char =~ /Z/) { $char = 'a' }
+ elsif ($char =~ /z/) { $char = "\n" }
+ elsif ($char =~ /\n/) { print STDERR "."; $char = '0' }
+ else { $char++ }
if ($self->{sleep}) {
IO::Handle::flush(\*STDOUT);
sleep $self->{sleep};
my $char = '0';
for (my $i = 1; $i < $len; $i++) {
$msg .= $char;
- given ($char) {
- when(/9/) {
- $ctx->add("[$char]");
- defined(send(STDOUT, $msg, MSG_OOB))
- or die ref($self), " send OOB failed: $!";
- # If tcp urgent data is sent too fast,
- # it may get overwritten and lost.
- sleep .1;
- $msg = "";
- $char = 'A';
- }
- when(/Z/) { $ctx->add($char); $char = 'a' }
- when(/z/) { $ctx->add($char); $char = "\n" }
- when(/\n/) {
- $ctx->add($char);
- defined(send(STDOUT, $msg, 0))
- or die ref($self), " send failed: $!";
- print STDERR ".";
- $msg = "";
- $char = '0';
- }
- default { $ctx->add($char); $char++ }
+ if ($char =~ /9/) {
+ $ctx->add("[$char]");
+ defined(send(STDOUT, $msg, MSG_OOB))
+ or die ref($self), " send OOB failed: $!";
+ # If tcp urgent data is sent too fast,
+ # it may get overwritten and lost.
+ sleep .1;
+ $msg = "";
+ $char = 'A';
+ } elsif ($char =~ /Z/) {
+ $ctx->add($char);
+ $char = 'a';
+ } elsif ($char =~ /z/) {
+ $ctx->add($char);
+ $char = "\n";
+ } elsif ($char =~ /\n/) {
+ $ctx->add($char);
+ defined(send(STDOUT, $msg, 0))
+ or die ref($self), " send failed: $!";
+ print STDERR ".";
+ $msg = "";
+ $char = '0';
+ } else {
+ $ctx->add($char);
+ $char++;
}
}
if ($len) {
for (my $i = 1; $i < $l; $i++) {
$ctx->add($char);
$string .= $char;
- given ($char) {
- when(/9/) { $char = 'A' }
- when(/Z/) { $char = 'a' }
- when(/z/) { $char = "\n" }
- when(/\n/) { $char = '0' }
- default { $char++ }
- }
+ if ($char =~ /9/) { $char = 'A' }
+ elsif ($char =~ /Z/) { $char = 'a' }
+ elsif ($char =~ /z/) { $char = "\n" }
+ elsif ($char =~ /\n/) { $char = '0' }
+ else { $char++ }
}
if ($l) {
$ctx->add("\n");
my $self = shift;
my $protocol = $self->{protocol} || "tcp";
- given ($protocol) {
- when (/tcp/) { relay_copy_stream($self, @_) }
- when (/udp/) { relay_copy_datagram($self, @_) }
- default { die ref($self), " unknown protocol name: $protocol" }
+ if ($protocol =~ /tcp/) {
+ relay_copy_stream($self, @_);
+ } elsif ($protocol =~ /udp/) {
+ relay_copy_datagram($self, @_);
+ } else {
+ die ref($self), " unknown protocol name: $protocol";
}
}
my $self = shift;
my $protocol = $self->{protocol} || "tcp";
- given ($protocol) {
- when (/tcp/) { relay_splice_stream($self, @_) }
- when (/udp/) { relay_splice_datagram($self, @_) }
- default { die ref($self), " unknown protocol name: $protocol" }
+ if ($protocol =~ /tcp/) {
+ relay_splice_stream($self, @_);
+ } elsif ($protocol =~ /udp/) {
+ relay_splice_datagram($self, @_);
+ } else {
+ die ref($self), " unknown protocol name: $protocol";
}
}
my $self = shift;
my $forward = $self->{forward};
- given ($forward) {
- when (/copy/) { relay_copy($self, @_) }
- when (/splice/) { relay_splice($self, @_) }
- default { die ref($self), " unknown forward name: $forward" }
+ if ($forward =~ /copy/) {
+ relay_copy($self, @_);
+ } elsif ($forward =~ /splice/) {
+ relay_splice($self, @_);
+ } else {
+ die ref($self), " unknown forward name: $forward";
}
my $soerror;
-# $OpenBSD: funcs.pl,v 1.9 2021/12/22 15:54:01 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.10 2024/06/14 15:12:57 bluhm Exp $
# Copyright (c) 2010-2021 Alexander Bluhm <bluhm@openbsd.org>
#
use strict;
use warnings;
-no warnings 'experimental::smartmatch';
-use feature 'switch';
use Errno;
use Digest::MD5;
+use POSIX;
use Socket;
use Socket6;
use IO::Socket;
$ctx->add($char);
print $char
or die ref($self), " print failed: $!";
- given ($char) {
- when(/9/) { $char = 'A' }
- when(/Z/) { $char = 'a' }
- when(/z/) { $char = "\n" }
- when(/\n/) { print STDERR "."; $char = '0' }
- default { $char++ }
- }
+ if ($char =~ /9/) { $char = 'A' }
+ elsif ($char =~ /Z/) { $char = 'a' }
+ elsif ($char =~ /z/) { $char = "\n" }
+ elsif ($char =~ /\n/) { print STDERR "."; $char = '0' }
+ else { $char++ }
if ($self->{sleep}) {
IO::Handle::flush(\*STDOUT);
sleep $self->{sleep};
print STDERR "LEN: ", $len, "\n";
print STDERR "MD5: ", $ctx->hexdigest, "\n";
-
}
sub errignore {
-# $OpenBSD: funcs.pl,v 1.25 2021/12/22 11:50:28 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.26 2024/06/14 15:12:57 bluhm Exp $
# Copyright (c) 2010-2021 Alexander Bluhm <bluhm@openbsd.org>
#
use strict;
use warnings;
-no warnings 'experimental::smartmatch';
-use feature 'switch';
use Errno;
use Digest::MD5;
use Socket;
$ctx->add($char);
print $char
or die ref($self), " print failed: $!";
- given ($char) {
- when(/9/) { $char = 'A' }
- when(/Z/) { $char = 'a' }
- when(/z/) { $char = "\n" }
- when(/\n/) { print STDERR "."; $char = '0' }
- default { $char++ }
- }
+ if ($char =~ /9/) { $char = 'A' }
+ elsif ($char =~ /Z/) { $char = 'a' }
+ elsif ($char =~ /z/) { $char = "\n" }
+ elsif ($char =~ /\n/) { print STDERR "."; $char = '0' }
+ else { $char++ }
if ($self->{sleep}) {
IO::Handle::flush(\*STDOUT);
sleep $self->{sleep};
and die "relayd lost child";
}
+sub array_eq {
+ my ($a, $b) = @_;
+ return if @$a != @$b;
+ for (my $i = 0; $i < @$a; $i++) {
+ return if $$a[$i] ne $$b[$i];
+ }
+ return 1;
+}
+
sub check_len {
my ($c, $r, $s, %args) = @_;
unless $args{client}{nocheck};
@slen = $s->loggrep(qr/^LEN: /) or die "no server len"
unless $args{server}{nocheck};
- !@clen || !@slen || @clen ~~ @slen
+ !@clen || !@slen || array_eq \@clen, \@slen
or die "client: @clen", "server: @slen", "len mismatch";
!defined($args{len}) || !$clen[0] || $clen[0] eq "LEN: $args{len}\n"
or die "client: $clen[0]", "len $args{len} expected";