diff options
author | Michael Brown | 2005-05-17 18:44:57 +0200 |
---|---|---|
committer | Michael Brown | 2005-05-17 18:44:57 +0200 |
commit | 1097cf8685cd81f0003bd6f17d050e5174a85b90 (patch) | |
tree | 47a39f2a1e980cca43c28c4d1a6dfdf431b910b2 /contrib/p910nd-0.8/client.pl | |
parent | Quickly hacked to use a buffer rather than a processor. (diff) | |
download | ipxe-1097cf8685cd81f0003bd6f17d050e5174a85b90.tar.gz ipxe-1097cf8685cd81f0003bd6f17d050e5174a85b90.tar.xz ipxe-1097cf8685cd81f0003bd6f17d050e5174a85b90.zip |
Initial revision
Diffstat (limited to 'contrib/p910nd-0.8/client.pl')
-rwxr-xr-x | contrib/p910nd-0.8/client.pl | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/contrib/p910nd-0.8/client.pl b/contrib/p910nd-0.8/client.pl new file mode 100755 index 00000000..0b0e4c36 --- /dev/null +++ b/contrib/p910nd-0.8/client.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +# edit this to the printer hostname +$them = 'ken'; +$port = 9101; + +open(STDIN, "$ARGV[0]") if $#ARGV >= 0; + +use Socket; +#use Sys::Hostname; + +#$hostname = hostname; + +($name, $aliases, $proto) = getprotobyname('tcp'); +($name, $aliases, $port) = getservbyname($port, 'tcp') + unless $port =~ /^\d+$/; + +#$thisaddr = inet_aton($hostname); +#defined($thisaddr) or &errexit("inet_aton: cannot resolve $hostname\n"); + +$thataddr = inet_aton($them); +defined($thataddr) or &errexit("inet_aton: cannot resolve $them\n"); + +socket(S, PF_INET, SOCK_STREAM, $proto) or &errexit("socket: $!\n"); + +#$this = sockaddr_in(0, $thisaddr); +#bind(S, $this) || &errexit("bind: $!\n"); + +$that = sockaddr_in($port, $thataddr); +connect(S, $that) || &errexit("connect: $!\n"); + +select(S); $| = 1; select(STDOUT); + +$buffer = ''; +while (1) +{ + $rin = ''; + vec($rin, fileno(S), 1) = 1; + $nfound = select($rout=$rin, $wout=$rin, undef, undef); + if (vec($rout, fileno(S), 1)) { + print STDERR "$buffer\n" if + defined($nread = sysread(S, $buffer, 8192)); + } + if (vec($wout, fileno(S), 1)) { + $nread = read(STDIN, $buffer, 8192); + last if $nread == 0; + &errexit("write: $!\n") unless + defined($written = syswrite(S,$buffer,$nread)); + } +} +close(S); +exit 0; + +sub errexit +{ + print STDERR @_; + exit 2; +} |