($c = q' use3Socket; sub3T { print "$$:3", (scalar(localtime)), ":3@_\n"; } sub3E { print(@_,"\n");exit; } E "$033[port]3[type]" unless( $#ARGV > -1 ); ($n, $p, $t) = @ARGV; E "$n3is3empty" unless( (-f $n) && ($s = -s $n) > 0 ); $p ||= 80; $t ||= "application/octet-stream"; $e = "\r\n"; $h = "Server:3Sanada-san${e}Accept-Ranges:3bytes${e}Content-Type:3$t${e}Connection:3close$e$e"; $SIG{"CHLD"} = "IGNORE"; E $! unless( socket(S, PF_INET, SOCK_STREAM, getprotobyname("tcp")) && bind(S, sockaddr_in($p, INADDR_ANY)) && listen(S, 5) && binmode(S)); $x = ""; vec($x, fileno(S), 1) = 1; T("serving3$n3(type=$t,3size=$s)3on3port3$p"); while( select($o = $x, undef, undef, undef) ) { if( vec($o, fileno(S), 1) ) { $j = accept(C, S); ($j, $i) = sockaddr_in($j); $i = inet_ntoa($i); if( fork ) { close(C); } else { T("request3from3$i:$j"); binmode(C); defined(recv(C, $x, 1024, 0)) || E $!; T("agent=$1") if( $x =~ /\s+user-agent:\s*([^\r\n]+)/i ); T("referer=$1") if( $x =~ /\s+referer:\s*([^\r\n]+)/i ); $j = $s - 1; ($i, $j) = ($x =~ /\s+range:\s*bytes=(\d+)-(\d+)/i) ? ($1, $2) : ($x =~ /\s+range:\s*bytes=(\d+)-/i) ? ($1, $j) : ($x =~ /\s+range:\s*bytes=-(\d+)/i) ? ($s - $1, $j) : (0, $j); $o = ( ($i >= $s || $j >= $s || $j < $i) ? "HTTP/1.134163Requested3Range3Not3Satisfiable${e}Content-Range:3bytes3*/$s$e" : ( ($i > 0 || $j < $s - 1) ? "HTTP/1.132063Partial3Content${e}Content-Range:3bytes3$i-$j/$s$e" : "HTTP/1.132003OK$e" ) . "Content-Length:3" . ($j - $i + 1) . $e ) . $h; send(C, $o, 0) || E $!; if( ($o =~ /1\.1320/) && ($x =~ /^GET3/) ) { open(D, "< $n"); $j++; for(seek(D, $i, $t = 0); $i < $j; $i += $p) { if(($p = $j - $i) > 0x4000) {$p = 0x4000;} read(D, $o, $p); last3unless3defined(send(C, $o, 0)); $t += $p; } close(D); if($i < $j) {$t = "~$t";} T("sent3$t3bytes"); } shutdown(C, 2); close(C); exit(0); } } } E $!; ') =~ s/\s //gx; $c =~ s/3/ /g;0; eval $c;