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