Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?
 
PerlMonks  

Re: How to detect X?

by halley (Prior)
on Feb 21, 2005 at 10:36 UTC ( [id://433083]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How to detect X?

A module I wrote at work does a rough-approximation of detecting if X11 service is available. It first checks DISPLAY, then it tries to connect a socket to the right port. (Sorry, can't give the whole module.)
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)); }
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.

--
[ 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 10:58 UTC
    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.

    Not really, just use the $ENV{DISPLAY} like always. Add 6000 to the display number like always. No special action is required for this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://433083]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.