2 * $Id: papstatus.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
30 #include <sys/types.h>
34 #include <netatalk/endian.h>
35 #include <netatalk/at.h>
36 #include <atalk/atp.h>
37 #include <atalk/pap.h>
38 #include <atalk/nbp.h>
39 #include <atalk/util.h>
45 #define _PATH_PAPRC ".paprc"
47 /* Forward Declaration */
48 void getstatus(ATP atp, struct sockaddr_at *sat);
55 if (( p = strrchr( path, '/' )) == NULL ) {
61 "Usage:\t%s [ -A address ] [ -p printername ]\n", p );
68 static char s[ 32 + 1 + 32 + 1 + 32 ];
72 if (( f = fopen( _PATH_PAPRC, "r" )) == NULL ) {
75 while ( fgets( s, sizeof( s ), f ) != NULL ) {
76 s[ strlen( s ) - 1 ] = '\0'; /* remove trailing newline */
98 char *obj = NULL, *type = "LaserWriter", *zone = "*";
104 memset(&addr, 0, sizeof(addr));
105 while (( c = getopt( ac, av, "p:s:A:" )) != EOF ) {
108 if (!atalk_aton(optarg, &addr)) {
109 fprintf(stderr, "Bad address.\n");
118 fprintf( stderr, "Unknown option: '%c'\n", c );
125 if ( printer == NULL && (( printer = paprc()) == NULL )) {
132 if ( nbp_name( printer, &obj, &type, &zone ) < 0 ) {
133 fprintf( stderr, "%s: Bad name\n", printer );
137 fprintf( stderr, "%s: Bad name\n", printer );
140 if ( nbp_lookup( obj, type, zone, &nn, 1, &addr ) <= 0 ) {
142 perror( "nbp_lookup" );
144 fprintf( stderr, "%s:%s@%s: NBP Lookup failed\n", obj, type, zone );
149 if (( atp = atp_open( ATADDR_ANYPORT, &addr )) == NULL ) {
150 perror( "atp_open" );
154 if ( optind == ac ) {
155 getstatus( atp, &nn.nn_sat );
158 if ( optind - ac > 1 ) {
161 wait = atoi( av[ optind ] );
163 getstatus( atp, &nn.nn_sat );
170 void getstatus( atp, sat )
172 struct sockaddr_at *sat;
175 struct atp_block atpb;
176 char rbuf[ ATP_MAXDATA ];
179 cbuf[ 1 ] = PAP_SENDSTATUS;
180 cbuf[ 2 ] = cbuf[ 3 ] = 0;
182 atpb.atp_saddr = sat;
183 atpb.atp_sreqdata = cbuf;
184 atpb.atp_sreqdlen = 4; /* bytes in SendStatus request */
185 atpb.atp_sreqto = 2; /* retry timer */
186 atpb.atp_sreqtries = 5; /* retry count */
187 if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
188 perror( "atp_sreq" );
193 iov.iov_len = sizeof( rbuf );
194 atpb.atp_rresiov = &iov;
195 atpb.atp_rresiovcnt = 1;
196 if ( atp_rresp( atp, &atpb ) < 0 ) {
197 perror( "atp_rresp" );
202 if ( iov.iov_len < 8 ||
203 rbuf[ 1 ] != PAP_STATUS ) {
204 fprintf( stderr, "Bad response!\n" );
205 return; /* This is weird, since TIDs must match... */
208 printf( "%.*s\n", (int)iov.iov_len - 9, (char *) iov.iov_base + 9 );