You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.pl 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/perl
  2. # edit this to the printer hostname
  3. $them = 'ken';
  4. $port = 9101;
  5. open(STDIN, "$ARGV[0]") if $#ARGV >= 0;
  6. use Socket;
  7. #use Sys::Hostname;
  8. #$hostname = hostname;
  9. ($name, $aliases, $proto) = getprotobyname('tcp');
  10. ($name, $aliases, $port) = getservbyname($port, 'tcp')
  11. unless $port =~ /^\d+$/;
  12. #$thisaddr = inet_aton($hostname);
  13. #defined($thisaddr) or &errexit("inet_aton: cannot resolve $hostname\n");
  14. $thataddr = inet_aton($them);
  15. defined($thataddr) or &errexit("inet_aton: cannot resolve $them\n");
  16. socket(S, PF_INET, SOCK_STREAM, $proto) or &errexit("socket: $!\n");
  17. #$this = sockaddr_in(0, $thisaddr);
  18. #bind(S, $this) || &errexit("bind: $!\n");
  19. $that = sockaddr_in($port, $thataddr);
  20. connect(S, $that) || &errexit("connect: $!\n");
  21. select(S); $| = 1; select(STDOUT);
  22. $buffer = '';
  23. while (1)
  24. {
  25. $rin = '';
  26. vec($rin, fileno(S), 1) = 1;
  27. $nfound = select($rout=$rin, $wout=$rin, undef, undef);
  28. if (vec($rout, fileno(S), 1)) {
  29. print STDERR "$buffer\n" if
  30. defined($nread = sysread(S, $buffer, 8192));
  31. }
  32. if (vec($wout, fileno(S), 1)) {
  33. $nread = read(STDIN, $buffer, 8192);
  34. last if $nread == 0;
  35. &errexit("write: $!\n") unless
  36. defined($written = syswrite(S,$buffer,$nread));
  37. }
  38. }
  39. close(S);
  40. exit 0;
  41. sub errexit
  42. {
  43. print STDERR @_;
  44. exit 2;
  45. }