6 #include <sys/socket.h>
14 #include <netatalk/endian.h>
15 #include <netatalk/at.h>
16 #include <atalk/atp.h>
17 #include <atalk/util.h>
18 #include <atalk/zip.h>
20 void print_zones(short n, char *buf);
25 fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
29 int main( argc, argv )
33 struct atp_handle *ah;
34 struct atp_block atpb;
35 struct sockaddr_at saddr;
37 char reqdata[4], buf[ ATP_MAXDATA ];
39 short temp, index = 0;
40 int c, myzoneflg = 0, localzonesflg = 0, errflg = 0;
43 reqdata[ 0 ] = ZIPOP_GETZONELIST;
45 while (( c = getopt( argc, argv, "ml" )) != EOF ) {
48 if ( localzonesflg ) {
52 reqdata[ 0 ] = ZIPOP_GETMYZONE;
59 reqdata[ 0 ] = ZIPOP_GETLOCALZONES;
66 if ( errflg || argc - optind > 1 ) {
70 memset( &saddr, 0, sizeof( struct sockaddr_at ));
72 saddr.sat_len = sizeof( struct sockaddr_at );
74 saddr.sat_family = AF_APPLETALK;
75 if (( se = getservbyname( "zip", "ddp" )) == NULL )
78 saddr.sat_port = ntohs( se->s_port );
80 if ( argc == optind ) {
81 saddr.sat_addr.s_net = ATADDR_ANYNET;
82 saddr.sat_addr.s_node = ATADDR_ANYNODE;
84 if ( !atalk_aton( argv[ optind ], &saddr.sat_addr )) {
85 fprintf( stderr, "Bad address.\n" );
90 if (( ah = atp_open( ATADDR_ANYPORT, &saddr.sat_addr )) == NULL ) {
95 index = ( myzoneflg ? 0 : 1 );
99 atpb.atp_saddr = &saddr;
100 temp = htons( index );
101 memcpy( reqdata + 2, &temp, 2 );
102 atpb.atp_sreqdata = reqdata;
103 atpb.atp_sreqdlen = 4;
105 atpb.atp_sreqtries = 5;
107 /* send getzone request zones (or get my zone)
109 if ( atp_sreq( ah, &atpb, 1, 0 ) < 0 ) {
110 perror( "atp_sreq" );
115 iov.iov_len = ATP_MAXDATA;
116 atpb.atp_rresiov = &iov;
117 atpb.atp_rresiovcnt = 1;
119 if ( atp_rresp( ah, &atpb ) < 0 ) {
120 perror( "atp_rresp" );
124 memcpy( &temp, (char *) iov.iov_base + 2, 2 );
125 temp = ntohs( temp );
126 print_zones( temp, (char *) iov.iov_base+4 );
128 } while ( !myzoneflg && !((char *)iov.iov_base)[ 0 ] );
130 if ( atp_close( ah ) != 0 ) {
131 perror( "atp_close" );
139 void print_zones( n, buf )
140 short n; /* number of zones in this packet */
141 char *buf; /* zone length/name pairs */
143 for ( ; n--; buf += (*buf) + 1 ) {
144 printf( "%.*s\n", *buf, buf+1 );