File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,31 @@ sub import {
111111sub run {
112112 my $self = shift ;
113113
114+ my $listen_host ;
115+
116+ require Socket;
117+ require IO::Socket::IP;
118+ my ($err , @res ) = Socket::getaddrinfo(" localhost" , " http" , {
119+ protocol => Socket::IPPROTO_TCP(),
120+ } );
121+
122+ my @local_hosts = map +(Socket::getnameinfo($_ -> {addr }, Socket::NI_NUMERICHOST()))[1], @res ;
123+ push @local_hosts , ' 127.0.0.1' ;
124+
125+ for my $host (@local_hosts ) {
126+ my $try = IO::Socket::IP-> new(LocalAddr => $host , Listen => 1);
127+ if ($try ) {
128+ $listen_host = $host ;
129+ $try -> close ;
130+ last ;
131+ }
132+ }
133+
114134 require HTTP::Daemon;
115- my $d = HTTP::Daemon-> new(Timeout => 10);
135+ my $d = HTTP::Daemon-> new(
136+ Timeout => 10,
137+ $listen_host ? ( LocalHost => $listen_host ) : (),
138+ );
116139
117140 print " HTTP::Daemon running at <URL:" , $d -> url, " >\n " ;
118141 open STDOUT , ' >' , File::Spec-> devnull;
You can’t perform that action at this time.
0 commit comments