Increased compatibility

This commit is contained in:
Frans Veldman 2026-02-10 14:30:50 +00:00
parent cee5cacfaa
commit d976de8dca

View File

@ -1,13 +1,13 @@
#!perl -w #!perl -w
use strict; use strict;
use Socket; use IO::Socket;
# auto-flush on socket # auto-flush on socket
$| = 1; $| = 1;
my $VERSION="1.10"; my $VERSION="1.20";
print "AISdispatcher.pl $VERSION, by Frans Veldman s/v ZwerfCat (https://www.zwerfcat.nl)\n"; print "AISdispatcher.pl $VERSION, by Frans Veldman, TheFloatingLab (https://www.thefloatinglab.world)\n";
my $tcp=0; my $tcp=0;
my $gpsd=0; my $gpsd=0;
@ -50,6 +50,7 @@ foreach my $a(@ARGV) {
} }
next if($a=~/^-/); next if($a=~/^-/);
if($a=~/^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])):([0-9]+)$/) { if($a=~/^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])):([0-9]+)$/) {
my $dummy=$5; # Dummy variable, somehow necessary for some obscure change of interpretation of $5.
push @sockets,pack_sockaddr_in($5, inet_aton($1)); push @sockets,pack_sockaddr_in($5, inet_aton($1));
} else { } else {
die "Error: $a is not a valid IP:PORT address!\n"; die "Error: $a is not a valid IP:PORT address!\n";
@ -223,16 +224,32 @@ sub getmmsi {
sub sourceconnect { sub sourceconnect {
my ($p,$i)=unpack_sockaddr_in($sockets[0]);
$i=inet_ntoa($i);
if($tcp) { if($tcp) {
# Connect for TCP source # Connect for TCP source
print "Connecting... " if(!$daemon); print "Connecting... " if(!$daemon);
socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die "socket: $!"; $sock = new IO::Socket::INET (
setsockopt($sock, SOL_SOCKET, SO_KEEPALIVE, 1); PeerAddr => $i,
connect($sock,$sockets[0]) || die "Could not connect to TCP port!\n"; PeerPort => $p,
print "Connected!\n" if(!$daemon); Proto => 'tcp',
ReuseAddr => 1,
KeepAlive => 1,
BLocking => 1,
Type => SOCK_STREAM,
Sockopts => [
[ SOL_SOCKET, SO_REUSEADDR ],
[ SOL_SOCKET, SO_KEEPALIVE ],
]
);
die "Could not create socket : $!\n" unless $sock;
print "Socket created: $sock\n" if(!$daemon);
if($gpsd) { if($gpsd) {
# Configure GPSD output, and skip config messages # Configure GPSD output, and skip config messages
send($sock,'?WATCH={"enable":true,"json":false,"nmea":true,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}',0); send($sock,'?WATCH={"enable":true,"json":false,"nmea":true,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}',0);
# print $sock,'?WATCH={"enable":true,"json":false,"nmea":true,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}';
while(my $line= <$sock>) { while(my $line= <$sock>) {
last unless($line=~/\{/); last unless($line=~/\{/);
print $line if(!$daemon); print $line if(!$daemon);
@ -240,10 +257,15 @@ sub sourceconnect {
} }
} else { } else {
# Connect to UDP source # Connect to UDP source
socket($sock, PF_INET, SOCK_DGRAM, getprotobyname('udp')) || die "socket: $!";
setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!"; $sock = new IO::Socket::INET (
setsockopt($sock,SOL_SOCKET,SO_RCVBUF,100000); LocalHost => $i,
bind($sock, $sockets[0]) || die "bind: $!"; LocalPort => $p,
Proto => 'udp',
ReuseAddr => 1,
);
die "Could not create socket : $!\n" unless $sock;
print "Socket created: $sock\n" if(!$daemon);
} }
} }