Re: Netprint perl script from Handbook doesn't work
On Wednesday 24 September 2008 17:12:36 Dan Nelson wrote: 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 It's also ugly (and very old-fashioned) Perl. Starting at (and replacing) the require 'sys/socket.ph' line (which is Perl 4, I think), it should look more like this (with appropriate error-checking added): use Socket; my $proto = getprotobyname('tcp'); socket(my $socket, PF_INET, SOCK_STREAM, $proto); my $sock_in = sockaddr_in($printer_port, inet_aton($printer_host)); connect($socket, $sock_in); Although this rewrite removes the need, if you want in general to ignore some of the return values of a function returning a list, the usual way is to assign to undef: (undef, undef, undef, undef, $address) = gethostbyname($printer_host); Although when you're throwing away that many, it makes more sense to index the returned list in the same way you would index an array: $address = (gethostbyname($printer_host))[4] # returns 5th element I really should submit a doc patch for this (incorporating Dan's sterling suggestion of nc $1 $2). Jonathan ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Netprint perl script from Handbook doesn't work
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jonathan McKeown Sent: Thursday, September 25, 2008 12:41 AM To: freebsd-questions@freebsd.org Subject: Re: Netprint perl script from Handbook doesn't work On Wednesday 24 September 2008 17:12:36 Dan Nelson wrote: 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 It's also ugly (and very old-fashioned) Perl. Starting at (and replacing) the require 'sys/socket.ph' line (which is Perl 4, I think), it should look more like this (with appropriate error-checking added): use Socket; my $proto = getprotobyname('tcp'); socket(my $socket, PF_INET, SOCK_STREAM, $proto); my $sock_in = sockaddr_in($printer_port, inet_aton($printer_host)); connect($socket, $sock_in); Although this rewrite removes the need, if you want in general to ignore some of the return values of a function returning a list, the usual way is to assign to undef: (undef, undef, undef, undef, $address) = gethostbyname($printer_host); Although when you're throwing away that many, it makes more sense to index the returned list in the same way you would index an array: $address = (gethostbyname($printer_host))[4] # returns 5th element I really should submit a doc patch for this (incorporating Dan's sterling suggestion of nc $1 $2). Jonathan, Submit a patch but rewrite the script as well as include use of the nc utility. It is important that when possible the handbook contain solutions that are portable to other UNIX variants. Everything in the handbook is indexed in search engines and we want people looking for solutions to be able to use the Handbook, this can help them get interested in FreeBSD. Ted ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Netprint perl script from Handbook doesn't work
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. 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; System is 7.0-RELEASE, I got to say it was working on 6.2-RELEASE Best Regards, Andy Kosela ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Netprint perl script from Handbook doesn't work
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 [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Netprint perl script from Handbook doesn't work
On Wed, Sep 24, 2008 at 5:12 PM, Dan Nelson [EMAIL PROTECTED] wrote: 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)? Yes, no problem with that (standard HP JetDirect 9100 port). The very same script *IS* working on 6.2-RELEASE. Perl versions on 6.x and 7 seems to be the same: 5.8.8 perl -V on 6.2-RELEASE: config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.8/mach -Dprivlib=/usr/local/lib/perl5/5.8.8 -Dman3dir=/usr/local/lib/perl5/5.8.8/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.8/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.8 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.8.8/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dccflags=-DAPPLLIB_EXP=/usr/local/lib/perl5/5.8.8/BSDPAN -Doptimize=-O2 -fno-strict-aliasing -pipe -Ud_dosuid -Ui_gdbm -Dusethreads=n -Dusemymalloc=y -Duse64bitint' perl -V on 7.0-RELEASE: config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.8/mach -Dprivlib=/usr/local/lib/perl5/5.8.8 -Dman3dir=/usr/local/lib/perl5/5.8.8/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.8/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.8 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.8.8/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dccflags=-DAPPLLIB_EXP=/usr/local/lib/perl5/5.8.8/BSDPAN -Doptimize=-O2 -fno-strict-aliasing -pipe -Ud_dosuid -Ui_gdbm -Dusethreads=n -Dusemymalloc=y -Duse64bitint' -- Andy Kosela ora et labora ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Netprint perl script from Handbook doesn't work
On Wednesday 24 September 2008 12:33:29 Andy Kosela wrote: ($ignore, $ignore, $protocol) = getprotobyname('tcp'); $ perl -e 'print join(\n, getprotobyname(tcp));' tcp TCP 6 -- Mel Problem with today's modular software: they start with the modules and never get to the software part. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]