2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2024-11-22 09:49:50 +00:00

fhem.pl: minor changes (Forum #95146)

git-svn-id: https://svn.fhem.de/fhem/trunk@18110 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2019-01-01 14:18:52 +00:00
parent ce9c491b8d
commit b5af42f784
2 changed files with 28 additions and 11 deletions

View File

@ -13,8 +13,10 @@ my $myPort;
my $ssl; my $ssl;
my $serverHost; my $serverHost;
my $serverPort; my $serverPort;
my $usage = "Usage: tcptee.pl [--bidi] [--loop] [--ssl] " . my $IPV6;
my $usage = "Usage: tcptee.pl [--IPV6] [--bidi] [--loop] [--ssl] " .
"[myIp:]myPort[:serverHost:serverPort]\n"; "[myIp:]myPort[:serverHost:serverPort]\n";
sub tPrint($);
while(@ARGV) { while(@ARGV) {
my $opt = shift @ARGV; my $opt = shift @ARGV;
@ -22,6 +24,15 @@ while(@ARGV) {
if($opt =~ m/^--bidi$/i) { if($opt =~ m/^--bidi$/i) {
$bidi = 1; $bidi = 1;
} elsif($opt =~ m/^--IPV6$/i) {
eval "require IO::Socket::INET6; use Socket6;";
if($@) {
tPrint $@;
tPrint "Can't load INET6, falling back to IPV4";
} else {
$IPV6 = 1;
}
} elsif($opt =~ m/^--loop$/i) { } elsif($opt =~ m/^--loop$/i) {
$loop = 1 $loop = 1
@ -80,12 +91,16 @@ for(;;) {
# Now open our listener # Now open our listener
$myfd = IO::Socket::INET->new( my @opts = (
LocalHost => $myIp, Domain => $IPV6 ? AF_INET6() : AF_UNSPEC,
LocalPort => $myPort, LocalHost => $myIp,
Listen => 10, LocalPort => $myPort,
ReuseAddr => 1 Listen => 10,
); ReuseAddr => 1
);
$myfd = $IPV6 ?
IO::Socket::INET6->new(@opts) :
IO::Socket::INET->new(@opts);
die "Opening port $myPort: $!\n" if(!$myfd); die "Opening port $myPort: $!\n" if(!$myfd);
tPrint "Port $myPort opened"; tPrint "Port $myPort opened";
@ -113,10 +128,12 @@ for(;;) {
tPrint "Accept failed: $!"; tPrint "Accept failed: $!";
next; next;
} }
my ($port, $iaddr) = sockaddr_in($clientinfo[1]); my ($port, $iaddr) = ($IPV6 ? sockaddr_in6($clientinfo[1]) :
sockaddr_in($clientinfo[1]));
my $fd = $clientinfo[0]; my $fd = $clientinfo[0];
$clients{$fd}{fd} = $fd; $clients{$fd}{fd} = $fd;
$clients{$fd}{addr} = inet_ntoa($iaddr) . ":$port"; $clients{$fd}{addr} = ($IPV6 ? inet_ntop(AF_INET6(), $iaddr) :
inet_ntoa($iaddr)) . ":$port";
tPrint "Connection accepted from $clients{$fd}{addr}"; tPrint "Connection accepted from $clients{$fd}{addr}";
if($ssl) { if($ssl) {

View File

@ -4,7 +4,7 @@
# #
# Copyright notice # Copyright notice
# #
# (c) 2005-2018 # (c) 2005-2019
# Copyright: Rudolf Koenig (r dot koenig at koeniglich dot de) # Copyright: Rudolf Koenig (r dot koenig at koeniglich dot de)
# All rights reserved # All rights reserved
# #
@ -2643,7 +2643,7 @@ GlobalAttr($$$$)
my ($type, $me, $name, $val) = @_; my ($type, $me, $name, $val) = @_;
if($type eq "del") { if($type eq "del") {
my %noDel = ( modpath=>1, verbose=>1, logfile=>1 ); my %noDel = ( modpath=>1, verbose=>1, logfile=>1, configfile=>1 );
return "The global attribute $name cannot be deleted" if($noDel{$name}); return "The global attribute $name cannot be deleted" if($noDel{$name});
$featurelevel = 5.9 if($name eq "featurelevel"); $featurelevel = 5.9 if($name eq "featurelevel");
$haveInet6 = 0 if($name eq "useInet6"); # IPv6 $haveInet6 = 0 if($name eq "useInet6"); # IPv6