2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation, and that the name of The University
10 * of Michigan not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. This software is supplied as is without expressed or
13 * implied warranties of any kind.
15 * Research Systems Unix Group
16 * The University of Michigan
18 * 535 W. William Street
21 * netatalk@itd.umich.edu
28 #include <sys/types.h>
32 #include <netatalk/endian.h>
33 #include <netatalk/at.h>
34 #include <atalk/atp.h>
35 #include <atalk/pap.h>
36 #include <atalk/nbp.h>
37 #include <atalk/util.h>
43 #define _PATH_PAPRC ".paprc"
45 /* Forward Declaration */
46 void getstatus(ATP atp, struct sockaddr_at *sat);
53 if (( p = strrchr( path, '/' )) == NULL ) {
59 "Usage:\t%s [ -A address ] [ -p printername ]\n", p );
66 static char s[ 32 + 1 + 32 + 1 + 32 ];
70 if (( f = fopen( _PATH_PAPRC, "r" )) == NULL ) {
73 while ( fgets( s, sizeof( s ), f ) != NULL ) {
74 s[ strlen( s ) - 1 ] = '\0'; /* remove trailing newline */
96 char *obj = NULL, *type = "LaserWriter", *zone = "*";
102 memset(&addr, 0, sizeof(addr));
103 while (( c = getopt( ac, av, "p:s:A:" )) != EOF ) {
106 if (!atalk_aton(optarg, &addr)) {
107 fprintf(stderr, "Bad address.\n");
116 fprintf( stderr, "Unknown option: '%c'\n", c );
123 if ( printer == NULL && (( printer = paprc()) == NULL )) {
130 if ( nbp_name( printer, &obj, &type, &zone ) < 0 ) {
131 fprintf( stderr, "%s: Bad name\n", printer );
135 fprintf( stderr, "%s: Bad name\n", printer );
138 if ( nbp_lookup( obj, type, zone, &nn, 1, &addr ) <= 0 ) {
140 perror( "nbp_lookup" );
142 fprintf( stderr, "%s:%s@%s: NBP Lookup failed\n", obj, type, zone );
147 if (( atp = atp_open( ATADDR_ANYPORT, &addr )) == NULL ) {
148 perror( "atp_open" );
152 if ( optind == ac ) {
153 getstatus( atp, &nn.nn_sat );
156 if ( optind - ac > 1 ) {
159 wait = atoi( av[ optind ] );
161 getstatus( atp, &nn.nn_sat );
168 void getstatus( atp, sat )
170 struct sockaddr_at *sat;
173 struct atp_block atpb;
174 char rbuf[ ATP_MAXDATA ];
177 cbuf[ 1 ] = PAP_SENDSTATUS;
178 cbuf[ 2 ] = cbuf[ 3 ] = 0;
180 atpb.atp_saddr = sat;
181 atpb.atp_sreqdata = cbuf;
182 atpb.atp_sreqdlen = 4; /* bytes in SendStatus request */
183 atpb.atp_sreqto = 2; /* retry timer */
184 atpb.atp_sreqtries = 5; /* retry count */
185 if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
186 perror( "atp_sreq" );
191 iov.iov_len = sizeof( rbuf );
192 atpb.atp_rresiov = &iov;
193 atpb.atp_rresiovcnt = 1;
194 if ( atp_rresp( atp, &atpb ) < 0 ) {
195 perror( "atp_rresp" );
200 if ( iov.iov_len < 8 ||
201 rbuf[ 1 ] != PAP_STATUS ) {
202 fprintf( stderr, "Bad response!\n" );
203 return; /* This is weird, since TIDs must match... */
206 printf( "%.*s\n", (int)iov.iov_len - 9, (char *) iov.iov_base + 9 );