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