aboutsummaryrefslogtreecommitdiff
path: root/share/examples/printing/netprint
diff options
context:
space:
mode:
authorWolfram Schneider <wosch@FreeBSD.org>1997-01-02 22:47:46 +0000
committerWolfram Schneider <wosch@FreeBSD.org>1997-01-02 22:47:46 +0000
commitf5bc5997b24114f383586d72086ad33c5031e895 (patch)
treeef16fd22f6bdb83df08f2c5f243403f4098be2e6 /share/examples/printing/netprint
parentc13b19be64e4516f29da6154371b2dedfd2939be (diff)
printing examples, automatically generated from
src/share/doc/handbook/printing.sgml with src/tools/tools/epfe/epfe.pl
Notes
Notes: svn path=/head/; revision=21240
Diffstat (limited to 'share/examples/printing/netprint')
-rw-r--r--share/examples/printing/netprint24
1 files changed, 24 insertions, 0 deletions
diff --git a/share/examples/printing/netprint b/share/examples/printing/netprint
new file mode 100644
index 000000000000..9b5010cc8cc5
--- /dev/null
+++ b/share/examples/printing/netprint
@@ -0,0 +1,24 @@
+#!/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;