sub CheckDisplayNumber
{
- local ($n) = @_;
+ my($n) = @_;
+
+ use Socket;
my $x11_lock_path = "/tmp/.X$n-lock";
for my $port ($rfb_port, $x11_port) {
# Bind to port to confirm it is not in use.
- socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
- eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
- if (!bind(S, pack('S n x12', $AF_INET, $port))) {
+ socket(S, PF_INET, SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
+ setsockopt(S, SOL_SOCKET, SO_REUSEADDR, 1);
+ if (!bind(S, sockaddr_in($port, INADDR_ANY))) {
# Port is in use.
close(S);
return 0;
if (!defined($ENV{HOME})) {
die "$prog: The HOME environment variable is not set.\n";
}
-
- #
- # Find socket constants. 'use Socket' is a perl5-ism, so we wrap it in an
- # eval, and if it fails we try 'require "sys/socket.ph"'. If this fails,
- # we just guess at the values. If you find perl moaning here, just
- # hard-code the values of AF_INET and SOCK_STREAM. You can find these out
- # for your platform by looking in /usr/include/sys/socket.h and related
- # files.
- #
-
- chop($os = `uname`);
- chop($osrev = `uname -r`);
-
- eval 'use Socket';
- if ($@) {
- eval 'require "sys/socket.ph"';
- if ($@) {
- if (($os eq "SunOS") && ($osrev !~ /^4/)) {
- $AF_INET = 2;
- $SOCK_STREAM = 2;
- } else {
- $AF_INET = 2;
- $SOCK_STREAM = 1;
- }
- } else {
- $AF_INET = &AF_INET;
- $SOCK_STREAM = &SOCK_STREAM;
- }
- } else {
- $AF_INET = &AF_INET;
- $SOCK_STREAM = &SOCK_STREAM;
- }
}