1*c311ab13SSascha Wildner#!/usr/bin/env perl 2984263bcSMatthew Dillon# 3984263bcSMatthew Dillon# netprint - Text filter for printer attached to network 4984263bcSMatthew Dillon# Installed in /usr/local/libexec/netprint 5984263bcSMatthew Dillon# 6984263bcSMatthew Dillon 7984263bcSMatthew Dillon$#ARGV eq 1 || die "Usage: $0 <printer-hostname> <port-number>"; 8984263bcSMatthew Dillon 9984263bcSMatthew Dillon$printer_host = $ARGV[0]; 10984263bcSMatthew Dillon$printer_port = $ARGV[1]; 11984263bcSMatthew Dillon 12984263bcSMatthew Dillonrequire 'sys/socket.ph'; 13984263bcSMatthew Dillon 14984263bcSMatthew Dillon($ignore, $ignore, $protocol) = getprotobyname('tcp'); 15984263bcSMatthew Dillon($ignore, $ignore, $ignore, $ignore, $address) 16984263bcSMatthew Dillon = gethostbyname($printer_host); 17984263bcSMatthew Dillon 18984263bcSMatthew Dillon$sockaddr = pack('S n a4 x8', &AF_INET, $printer_port, $address); 19984263bcSMatthew Dillon 20984263bcSMatthew Dillonsocket(PRINTER, &PF_INET, &SOCK_STREAM, $protocol) 21984263bcSMatthew Dillon || die "Can't create TCP/IP stream socket: $!"; 22984263bcSMatthew Dillonconnect(PRINTER, $sockaddr) || die "Can't contact $printer_host: $!"; 23984263bcSMatthew Dillonwhile (<STDIN>) { print PRINTER; } 24984263bcSMatthew Dillonexit 0; 25