Dieser Code steht vor der while-Schleife:
$host_data = (gethostbyname($g_masterserver_address))[4];
my $address = join(".", unpack("C4", $host_data));
my $port = $g_masterserver_port;
my $dest = sockaddr_in($port, inet_aton($address));
$msg = chr(0xff).chr(0xff)."Z".chr(0xff);
$bytes = send($::s_socket, $msg, 0, $dest);
print("$bytes to '$address:$port'");
Und hier noch den Code den ich von php versuche in Perl zu übertragen:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$packet = chr(255).chr(255)."Z".chr(255);
$bytes_sent = socket_sendto($socket, $packet, strlen($packet), 0, $host, $port);
echo "<b>".$bytes_sent."</b> bytes <b>OK</b></li>";
$recv_bytes = 0;
$buffer = "";
$timeout = 30;
$answer = "";
$packets = 0;
$read = array($socket);
while (socket_select($read, $write = NULL, $except = NULL, &$timeout) > 0) {
$recv_bytes += socket_recvfrom($socket, &$buffer, 2000, 0, &$host, &$port);
if (($buffer[0] == chr(255)) && ($buffer[1] == chr(255)) && ($buffer[2] == "Z") && ($buffer[3] == chr(255)) &&
($buffer[4] == "1") && ($buffer[5] == ".") && ($buffer[6] == "0") && ($buffer[7] == "0") && ($buffer[8] == chr(255))) {
$answer .= substr($buffer, 9, strlen($buffer));
}
$buffer = "";
$timeout = "1";
$packets++;
}