Permalink
Browse files

allow users to force ipv4 only.

add flag '-4' to commands to force ipv4.
this doesn't work yet because hairtunes unconditionally
uses ipv6 if available.
  • Loading branch information...
splbio committed Dec 23, 2012
1 parent 4746bb1 commit 376b3a53c85490bc52dc7e70e7988c6d77a16681
Showing with 17 additions and 1 deletion.
  1. +17 −1 shairport.pl
View
@@ -82,6 +82,9 @@
# show help
my $help;
+
+my $ipv4;
+
unless (-x $hairtunes_cli) {
say "Can't find the 'hairtunes' decoder binary, you need to build this before using ShairPort.";
say "Read the INSTALL instructions!";
@@ -97,6 +100,7 @@
"ao_devicename=s" => \$libao_devicename,
"ao_deviceid=s" => \$libao_deviceid,
"v|verbose" => \$verbose,
+ "4" => \$ipv4,
"w|writepid=s" => \$writepid,
"s|squeezebox" => \$squeeze,
"c|cliport=s" => \$cliport,
@@ -295,6 +299,7 @@ sub REAP {
my $listen;
{
+ if (!defined($ipv4)) {
eval {
local $SIG{__DIE__};
$listen = new IO::Socket::INET6(Listen => 1,
@@ -309,6 +314,7 @@ sub REAP {
"* Install this if iTunes won't play. *\n",
"**************************************\n\n";
}
+ }
$listen ||= new IO::Socket::INET(Listen => 1,
LocalPort => $port,
@@ -491,6 +497,7 @@ sub performSqueezeboxSetup {
};
while (1) {
+ printf "about to select\n" if $verbose;
my @waiting = $sel->can_read;
foreach my $fh (@waiting) {
if ($fh==$listen) {
@@ -507,6 +514,7 @@ sub performSqueezeboxSetup {
# the 2nd connection is a player connection
if (defined($play_prog) && $sel->count() == 2) {
+ printf "play prog: $play_prog\n" if ($verbose);
system($play_prog);
}
} else {
@@ -541,6 +549,8 @@ sub conn_handle_data {
my $fh = shift;
my $conn = $conns{$fh};
+ printf "handle data 1\n" if ($verbose);
+
if ($conn->{req_need}) {
if (length($conn->{data}) >= $conn->{req_need}) {
$conn->{req}->content(substr($conn->{data}, 0, $conn->{req_need}, ''));
@@ -675,7 +685,7 @@ sub conn_handle_request {
my $dec = $hairtunes_cli . join(' ', '', map { sprintf "%s '%s'", $_, $dec_args{$_} } keys(%dec_args));
- # print "decode command: $dec\n";
+ print "decode command: $dec\n" if ($verbose);
my $decoder = open2(my $dec_out, my $dec_in, $dec);
$conn->{decoder_pid} = $decoder;
@@ -701,10 +711,15 @@ sub conn_handle_request {
};
/^SET_PARAMETER$/ && do {
my @lines = split /[\r\n]+/, $req->content;
+ printf("SET_PARAMETER req: " . $req->content . "\n") if ($verbose);
my %content = map { /^(\S+): (.+)/; (lc $1, $2) } @lines;
my $cfh = $conn->{decoder_fh};
if (exists $content{volume}) {
+ printf("sending-> vol: %f\n", $content{volume}) if ($verbose);
printf $cfh "vol: %f\n", $content{volume};
+ } else {
+ printf("unable to perform content for req: " . $req->content . "\n") if ($verbose);
+
}
last;
};
@@ -713,6 +728,7 @@ sub conn_handle_request {
die("Unknown method: $_");
}
+ printf("%s", $resp->as_string("\r\n")) if ($verbose);
print $fh $resp->as_string("\r\n");
$fh->flush;
}

0 comments on commit 376b3a5

Please sign in to comment.