[sanboot] Prevent leaking a stack reference for "keep-san" AoE
[gpxe.git] / contrib / p910nd-0.8 / client.pl
blob0b0e4c360693431a5845af93022f087f402cc58a
1 #!/usr/bin/perl
3 # edit this to the printer hostname
4 $them = 'ken';
5 $port = 9101;
7 open(STDIN, "$ARGV[0]") if $#ARGV >= 0;
9 use Socket;
10 #use Sys::Hostname;
12 #$hostname = hostname;
14 ($name, $aliases, $proto) = getprotobyname('tcp');
15 ($name, $aliases, $port) = getservbyname($port, 'tcp')
16 unless $port =~ /^\d+$/;
18 #$thisaddr = inet_aton($hostname);
19 #defined($thisaddr) or &errexit("inet_aton: cannot resolve $hostname\n");
21 $thataddr = inet_aton($them);
22 defined($thataddr) or &errexit("inet_aton: cannot resolve $them\n");
24 socket(S, PF_INET, SOCK_STREAM, $proto) or &errexit("socket: $!\n");
26 #$this = sockaddr_in(0, $thisaddr);
27 #bind(S, $this) || &errexit("bind: $!\n");
29 $that = sockaddr_in($port, $thataddr);
30 connect(S, $that) || &errexit("connect: $!\n");
32 select(S); $| = 1; select(STDOUT);
34 $buffer = '';
35 while (1)
37 $rin = '';
38 vec($rin, fileno(S), 1) = 1;
39 $nfound = select($rout=$rin, $wout=$rin, undef, undef);
40 if (vec($rout, fileno(S), 1)) {
41 print STDERR "$buffer\n" if
42 defined($nread = sysread(S, $buffer, 8192));
44 if (vec($wout, fileno(S), 1)) {
45 $nread = read(STDIN, $buffer, 8192);
46 last if $nread == 0;
47 &errexit("write: $!\n") unless
48 defined($written = syswrite(S,$buffer,$nread));
51 close(S);
52 exit 0;
54 sub errexit
56 print STDERR @_;
57 exit 2;