in reply to How to detect X?
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 ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to detect X?
by bunnyman (Hermit) on Feb 21, 2005 at 15:58 UTC |