ptg10805159
804 Communicating with a Network Printer Chapter 21
64 /*
65 * Return the host name running the print server or NULL on error.
66 *
67 * LOCKING: none.
68 */
69 char *
70 get_printserver(void)
71 {
72 return(scan_configfile("printserver"));
73 }
74 /*
75 * Return the address of the network printer or NULL on error.
76 *
77 * LOCKING: none.
78 */
79 struct addrinfo *
80 get_printaddr(void)
81 {
82 int err;
83 char *p;
84 struct addrinfo *ailist;
85 if ((p = scan_configfile("printer")) != NULL) {
86 if ((err = getaddrlist(p, "ipp", &ailist)) != 0) {
87 log_msg("no address information for %s", p);
88 return(NULL);
89 }
90 return(ailist);
91 }
92 log_msg("no printer address specified");
93 return(NULL);
94 }
[64 – 73] Theget_printserver function is simply a wrapper function that calls
scan_configfileto find the name of the computer system wherethe
printer spooling daemon is running.
[74 – 94] We use theget_printaddr function to get the address of the network
printer.It is similar to the previous function except that when we find the
name of the printer in the configuration file, we use the name to find the
corresponding network address.
Bothget_printserverandget_printaddrcallscan_configfile.Ifit
can’t open the printer configuration file,scan_configfilecallslog_systo
print an error message and exit. Althoughget_printserveris meant to be
called from a client command andget_printaddris meant to be called from
the daemon, having both calllog_sysis OK, because we can arrange for the
log functions to print to the standarderror instead of to the log file by setting a
global variable.