1*f5bc5997SWolfram Schneider#!/usr/bin/perl 2*f5bc5997SWolfram Schneider# 3*f5bc5997SWolfram Schneider# netprint - Text filter for printer attached to network 4*f5bc5997SWolfram Schneider# Installed in /usr/local/libexec/netprint 5*f5bc5997SWolfram Schneider# 6*f5bc5997SWolfram Schneider 7*f5bc5997SWolfram Schneider$#ARGV eq 1 || die "Usage: $0 <printer-hostname> <port-number>"; 8*f5bc5997SWolfram Schneider 9*f5bc5997SWolfram Schneider$printer_host = $ARGV[0]; 10*f5bc5997SWolfram Schneider$printer_port = $ARGV[1]; 11*f5bc5997SWolfram Schneider 12*f5bc5997SWolfram Schneiderrequire 'sys/socket.ph'; 13*f5bc5997SWolfram Schneider 14*f5bc5997SWolfram Schneider($ignore, $ignore, $protocol) = getprotobyname('tcp'); 15*f5bc5997SWolfram Schneider($ignore, $ignore, $ignore, $ignore, $address) 16*f5bc5997SWolfram Schneider = gethostbyname($printer_host); 17*f5bc5997SWolfram Schneider 18*f5bc5997SWolfram Schneider$sockaddr = pack('S n a4 x8', &AF_INET, $printer_port, $address); 19*f5bc5997SWolfram Schneider 20*f5bc5997SWolfram Schneidersocket(PRINTER, &PF_INET, &SOCK_STREAM, $protocol) 21*f5bc5997SWolfram Schneider || die "Can't create TCP/IP stream socket: $!"; 22*f5bc5997SWolfram Schneiderconnect(PRINTER, $sockaddr) || die "Can't contact $printer_host: $!"; 23*f5bc5997SWolfram Schneiderwhile (<STDIN>) { print PRINTER; } 24*f5bc5997SWolfram Schneiderexit 0; 25