FreeBSD supports networked printing: sending jobs to remote printers. Networked printing generally refers to two different things:
The LPD spooling system has built-in support for sending jobs to other hosts also running LPD (or are compatible with LPD). This feature enables you to install a printer on one host and make it accessible from other hosts. It also works with printers that have network interfaces that understand the LPD protocol.
To enable this kind of remote printing, first install a printer on one host, the printer host, using the simple printer setup described in Simple Printer Setup. Do any advanced setup in Advanced Printer Setup that you need. Make sure to test the printer and see if it works with the features of LPD you have enabled. Also ensure that the local host has authorization to use the LPD service in the printer host (see Restricting Jobs from Remote Printers).
If you are using a printer with a network interface that is compatible with LPD, then the printer host in the discussion below is the printer itself, and the printer name is the name you configured for the printer. See the documentation that accompanied your printer and/or printer-network interface.
Then, on the other hosts you want to have access to the
printer, make an entry in their /etc/printcap
files with the following:
lp
capability blank, explicitly
(:lp=:
).
sd
capability. LPD will store
jobs here before they get sent to the printer host.
rm
capability.
rp
capability./etc/printcap
file.
Here is an example. The host rose has two printers,
bamboo
and rattan
. We will enable users on the
host orchid to print to those printers. Here is the
/etc/printcap
file for orchid (back from section
Enabling Header Pages). It already had the entry
for the printer teak
; we have added entries for the two
printers on the host rose:
# # /etc/printcap for host orchid - added (remote) printers on rose # # # teak is local; it is connected directly to orchid: # teak|hp|laserjet|Hewlett Packard LaserJet 3Si:\ :lp=/dev/lpt0:sd=/var/spool/lpd/teak:mx#0:\ :if=/usr/local/libexec/ifhp:\ :vf=/usr/local/libexec/vfhp:\ :of=/usr/local/libexec/ofhp: # # rattan is connected to rose; send jobs for rattan to rose: # rattan|line|diablo|lp|Diablo 630 Line Printer:\ :lp=:rm=rose:rp=rattan:sd=/var/spool/lpd/rattan: # # bamboo is connected to rose as well: # bamboo|ps|PS|S|panasonic|Panasonic KX-P4455 PostScript v51.4:\ :lp=:rm=rose:rp=bamboo:sd=/var/spool/lpd/bamboo:
mkdir -p /var/spool/lpd/rattan /var/spool/lpd/bamboo
chmod 770 /var/spool/lpd/rattan /var/spool/lpd/bamboo
chown daemon.daemon /var/spool/lpd/rattan /var/spool/lpd/bamboo
Now, users on orchid can print to rattan
and
bamboo
. If, for example, a user on orchid typed
lpr -P bamboo -d sushi-review.dvi
the LPD system on orchid would copy the job to the
spooling directory /var/spool/lpd/bamboo
and note
that it was a DVI job. As soon as the host rose has room
in its bamboo
spooling directory, the two
LPDs would transfer the file to rose. The file would wait
in rose's queue until it was finally printed. It would be
converted from DVI to PostScript (since bamboo is a
PostScript printer) on rose.
Often, when you buy a network interface card for a printer, you can get two versions: one which emulates a spooler (the more expensive version), or one which just lets you send data to it as if you were using a serial or parallel port (the cheaper version). This section tells how to use the cheaper version. For the more expensive one, see the previous section Printers Installed on Remote Hosts.
The format of the /etc/printcap
file lets you
specify what serial or parallel interface to use, and (if
you are using a serial interface), what baud rate, whether
to use flow control, delays for tabs, conversion of
newlines, and more. But there is no way to specify a
connection to a printer that is listening on a TCP/IP or
other network port.
To send data to a networked printer, you need to develop a
communications program that can be called by the text and
conversion filters. Here is one such example: the script
netprint
takes all data on standard input and sends
it to a network-attached printer. We specify the hostname
of the printer as the first argument and the port number
to which to connect as the second argument to
netprint
. Note that this supports one-way
communication only (FreeBSD to printer); many network
printers support two-way communication, and you might want
to take advantage of that (to get printer status, perform
accounting, etc.).
#!/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;
#!/bin/sh # # diablo-if-net - Text filter for Diablo printer `scrivener' listening # on port 5100. Installed in /usr/local/libexec/diablo-if-net # exec /usr/libexec/lpr/lpf "$@" | /usr/local/libexec/netprint scrivener 5100