Date: Wed, 24 Sep 2008 10:12:36 -0500 From: Dan Nelson <dnelson@allantgroup.com> To: Andy Kosela <akosela@andykosela.com> Cc: freebsd-questions@freebsd.org Subject: Re: Netprint perl script from Handbook doesn't work Message-ID: <20080924151235.GA3284@dan.emsphone.com> In-Reply-To: <3cc535c80809240333s1036386fnaa597267f0cf12aa@mail.gmail.com> References: <3cc535c80809240333s1036386fnaa597267f0cf12aa@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Sep 24), Andy Kosela said: > The netprint perl script provided in the Handbook (9.4.3.2) is not > working.. or am I missing something: > > plotinus:~> cat new.txt | lp.sh > Can't contact 10.10.21.12: Address family not supported by protocol family at /usr/local/libexec/netprint line 21. Can you telnet to that ip address ("telnet 10.10.21.12 9100", or whatever port you're using)? > plotinus:> cat /usr/local/libexec/netprint > #!/usr/bin/perl > # > # netprint - Text filter for printer attached to network > # Installed in /usr/local/libexec/netprint > # > $#ARGV eq 1 || die "Usage: $0 <printer-hostname> <port-number>"; > > $printer_host = $ARGV[0]; > $printer_port = $ARGV[1]; > > require 'sys/socket.ph'; > > ($ignore, $ignore, $protocol) = getprotobyname('tcp'); > ($ignore, $ignore, $ignore, $ignore, $address) > = gethostbyname($printer_host); > > $sockaddr = pack('S n a4 x8', &AF_INET, $printer_port, $address); > > socket(PRINTER, &PF_INET, &SOCK_STREAM, $protocol) > || die "Can't create TCP/IP stream socket: $!"; > connect(PRINTER, $sockaddr) || die "Can't contact $printer_host: $!"; > while (<STDIN>) { print PRINTER; } > exit 0; Wow. That's a really complicated way to say #! /bin/sh nc $1 $2 -- Dan Nelson dnelson@allantgroup.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080924151235.GA3284>