There are other situations where the port in question is not so easily computed; these usually relate to tunneling of some sort, such as with (ssh -X) commands. Extend as desired.use Socket qw(SOCK_DGRAM SOCK_STREAM SOCK_RAW PF_INET inet_aton sockad +dr_in); use FileHandle; # ... other module junk ... # $spec = display(); # sub display { return $ENV{DISPLAY} || ':0'; } # $bool = scan($hostname, $tcpport); # sub scan { my $host = shift; my $port = shift; my $proto = (getprotobyname('tcp'))[2]; my $fh = new FileHandle(); my $ip = inet_aton($host); return undef if not defined $ip; return undef if not socket($fh, &PF_INET(), &SOCK_STREAM(), $proto); my $saddr = sockaddr_in($port, $ip); return undef if not connect($fh, $saddr); close($fh); return 1; } # $bool = ready(); # sub ready { my $display = display(); my ($host, $screen) = split(/:/, $display); $host ||= 'localhost'; return scan($host, 6000 + int($screen)); }
--
[ e d @ h a l l e y . c c ]
In reply to Re: How to detect X?
by halley
in thread How to detect X?
by blazar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |