ptg10805159
800 Communicating with a Network Printer Chapter 21
22 #define FILENMSZ 64
23 #define FILEPERM (S_IRUSR|S_IWUSR)
24 #define USERNM_MAX 64
25 #define JOBNM_MAX 256
26 #define MSGLEN_MAX 512
27 #ifndef HOST_NAME_MAX
28 #define HOST_NAME_MAX 256
29 #endif
30 #define IPP_PORT 631
31 #define QLEN 10
32 #define IBUFSZ 512 /* IPP header buffer size */
33 #define HBUFSZ 512 /* HTTP header buffer size */
34 #define IOBUFSZ 8192 /* data buffer size */
35 #ifndef ETIME
36 #define ETIME ETIMEDOUT
37 #endif
38 extern int getaddrlist(const char *, const char *,
39 struct addrinfo **);
40 extern char *get_printserver(void);
41 extern struct addrinfo *get_printaddr(void);
42 extern ssize_t tread(int, void *, size_t, unsigned int);
43 extern ssize_t treadn(int, void *, size_t, unsigned int);
44 extern int connect_retry(int, int, int, const struct sockaddr *,
45 socklen_t);
46 extern int initserver(int, const struct sockaddr *, socklen_t,
47 int);
[22 – 34] Next, we define limits and constants.FILEPERMis the permissions used when
creating copies of files submitted to be printed. The permissions arerestrictive
because we don’t want ordinary users to be able to read each other’s files
while they arewaiting to be printed. We define HOST_NAME_MAXas the
largest host name we will support if we areunable to determine the system’s
limit withsysconf.
IPP is defined to use port 631. TheQLENis the backlog parameter we pass to
listen(see Section 16.4 for details).
[35 – 37] Some platforms don’t define the errorETIME, so we define it to an alternate
error code that makes sense for these systems. This is the error code we return
when a read times out (we don’t want the server to block indefinitely reading
from a socket).
[38 – 47] Next, we declareall the public routines contained inutil.c(we’ll look at
these shortly). Note that theconnect_retryfunction, from Figure16.11, and
theinitserverfunction, from Figure16.22, arenot included inutil.c.