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>
42 #define _PATH_PAPRC ".paprc"
49 if (( p = strrchr( path, '/' )) == NULL ) {
55 "Usage:\t%s [ -A address ] [ -p printername ]\n", p );
62 static char s[ 32 + 1 + 32 + 1 + 32 ];
66 if (( f = fopen( _PATH_PAPRC, "r" )) == NULL ) {
69 while ( fgets( s, sizeof( s ), f ) != NULL ) {
70 s[ strlen( s ) - 1 ] = '\0'; /* remove trailing newline */
92 char *obj = NULL, *type = "LaserWriter", *zone = "*";
98 memset(&addr, 0, sizeof(addr));
99 while (( c = getopt( ac, av, "p:s:A:" )) != EOF ) {
102 if (!atalk_aton(optarg, &addr)) {
103 fprintf(stderr, "Bad address.\n");
112 fprintf( stderr, "Unknown option: '%c'\n", c );
119 if ( printer == NULL && (( printer = paprc()) == NULL )) {
126 if ( nbp_name( printer, &obj, &type, &zone ) < 0 ) {
127 fprintf( stderr, "%s: Bad name\n", printer );
131 fprintf( stderr, "%s: Bad name\n", printer );
134 if ( nbp_lookup( obj, type, zone, &nn, 1, &addr ) <= 0 ) {
136 perror( "nbp_lookup" );
138 fprintf( stderr, "%s:%s@%s: NBP Lookup failed\n", obj, type, zone );
143 if (( atp = atp_open( ATADDR_ANYPORT, &addr )) == NULL ) {
144 perror( "atp_open" );
148 if ( optind == ac ) {
149 getstatus( atp, &nn.nn_sat );
152 if ( optind - ac > 1 ) {
155 wait = atoi( av[ optind ] );
157 getstatus( atp, &nn.nn_sat );
162 getstatus( atp, sat )
164 struct sockaddr_at *sat;
167 struct atp_block atpb;
168 char rbuf[ ATP_MAXDATA ];
171 cbuf[ 1 ] = PAP_SENDSTATUS;
172 cbuf[ 2 ] = cbuf[ 3 ] = 0;
174 atpb.atp_saddr = sat;
175 atpb.atp_sreqdata = cbuf;
176 atpb.atp_sreqdlen = 4; /* bytes in SendStatus request */
177 atpb.atp_sreqto = 2; /* retry timer */
178 atpb.atp_sreqtries = 5; /* retry count */
179 if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
180 perror( "atp_sreq" );
185 iov.iov_len = sizeof( rbuf );
186 atpb.atp_rresiov = &iov;
187 atpb.atp_rresiovcnt = 1;
188 if ( atp_rresp( atp, &atpb ) < 0 ) {
189 perror( "atp_rresp" );
194 if ( iov.iov_len < 8 ||
195 rbuf[ 1 ] != PAP_STATUS ) {
196 fprintf( stderr, "Bad response!\n" );
197 return; /* This is weird, since TIDs must match... */
200 printf( "%.*s\n", iov.iov_len - 9, (char *) iov.iov_base + 9 );