[Slim-Checkins] r10135 - in /branches/6.5/server: Changelog6.html
Slim/Utils/IPDetect.pm
dsully at svn.slimdevices.com
dsully at svn.slimdevices.com
Mon Oct 2 16:04:24 PDT 2006
Author: dsully
Date: Mon Oct 2 16:04:22 2006
New Revision: 10135
URL: http://svn.slimdevices.com?rev=10135&view=rev
Log:
Bug: 4186
Description: Merge from trunk -r 10133:10134
Modified:
branches/6.5/server/Changelog6.html
branches/6.5/server/Slim/Utils/IPDetect.pm
Modified: branches/6.5/server/Changelog6.html
URL: http://svn.slimdevices.com/branches/6.5/server/Changelog6.html?rev=10135&r1=10134&r2=10135&view=diff
==============================================================================
--- branches/6.5/server/Changelog6.html (original)
+++ branches/6.5/server/Changelog6.html Mon Oct 2 16:04:22 2006
@@ -23,6 +23,7 @@
<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4173">#4173</a> - press right to add to favorites option disappears once you've used it, until you restart server</li>
<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4173">#4178</a> - Live365 stations don't have a note symbol</li>
<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4181">#4181</a> - Softsqueeze refuses connection to Squeezenetwork</li>
+ <li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4186">#4186</a> - webinterface (server settings) not responding because of denied connection to www.google.com</li>
<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4189">#4189</a> - mp3 file playback gets truncated</li>
<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4190">#4190</a> - xmlbrower transition problem</li>
<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4191">#4191</a> - Live365 Search has missing strings</li>
Modified: branches/6.5/server/Slim/Utils/IPDetect.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Utils/IPDetect.pm?rev=10135&r1=10134&r2=10135&view=diff
==============================================================================
--- branches/6.5/server/Slim/Utils/IPDetect.pm (original)
+++ branches/6.5/server/Slim/Utils/IPDetect.pm Mon Oct 2 16:04:22 2006
@@ -8,10 +8,12 @@
# version 2.
use strict;
-use IO::Socket;
+use Socket;
+use Symbol;
use Slim::Utils::Misc;
my $detectedIP = undef;
+my $localhost = '127.0.0.1';
=head1 NAME
@@ -48,24 +50,73 @@
sub _init {
- my $server = 'www.google.com:80';
+ if ($detectedIP) {
+ return;
+ }
- if (!$detectedIP) {
+ # This code used to try and connect to www.google.com:80 in order to
+ # find the local IP address.
+ #
+ # Thanks to trick from Bill Fenner, trying to use a UDP socket won't
+ # send any packets out over the network, but will cause the routing
+ # table to do a lookup, so we can find our address. Don't use a high
+ # level abstraction like IO::Socket, as it dies when connect() fails.
+ #
+ # time.nist.gov - though it doesn't really matter.
+ my $raddr = '192.43.244.18';
+ my $rport = 123;
- my $socket = IO::Socket::INET->new(
- 'PeerAddr' => $server,
- 'LocalAddr' => $main::localClientNetAddr,
- ) or do {
+ my $proto = (getprotobyname('udp'))[2];
+ my $pname = (getprotobynumber($proto))[0];
+ my $sock = Symbol::gensym();
- errorMsg("Failed to detect server IP address. $!\n");
+ my $iaddr = inet_aton($raddr) || do {
+
+ msg("Warning: Couldn't call inet_aton($raddr) - falling back to $localhost\n");
+
+ $detectedIP = $localhost;
+
+ return;
+ };
+
+ my $paddr = sockaddr_in($rport, $iaddr);
+
+ socket($sock, PF_INET, SOCK_DGRAM, $proto) || do {
+
+ msg("Warning: Couldn't call socket(PF_INET, SOCK_DGRAM, \$proto) - falling back to $localhost\n");
+
+ $detectedIP = $localhost;
+
+ return;
+ };
+
+ if ($main::localClientNetAddr && $main::localClientNetAddr =~ /^[\d\.]+$/) {
+
+ my $laddr = inet_aton($main::localClientNetAddr) || INADDR_ANY;
+
+ bind($sock, pack_sockaddr_in(0, $laddr)) or do {
+
+ msg("Warning: Couldn't call bind(pack_sockaddr_in(0, \$laddr) - falling back to $localhost\n");
+
+ $detectedIP = $localhost;
+
return;
};
+ }
- # Find my half of the connection
- my ($port, $address) = sockaddr_in( (getsockname($socket))[0] );
+ connect($sock, $paddr) || do {
- $detectedIP = inet_ntoa($address);
- }
+ msg("Warning: Couldn't call connect() - falling back to $localhost\n");
+
+ $detectedIP = $localhost;
+
+ return;
+ };
+
+ # Find my half of the connection
+ my ($port, $address) = sockaddr_in( (getsockname($sock))[0] );
+
+ $detectedIP = inet_ntoa($address);
}
1;
More information about the checkins
mailing list