6 #include <sys/socket.h>
13 #include <netatalk/endian.h>
14 #include <netatalk/at.h>
15 #include <atalk/atp.h>
16 #include <atalk/zip.h>
21 fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
29 struct atp_handle *ah;
30 struct atp_block atpb;
31 struct sockaddr_at saddr;
33 char reqdata[4], buf[ ATP_MAXDATA ];
35 short temp, index = 0;
36 int c, myzoneflg = 0, localzonesflg = 0, errflg = 0;
39 reqdata[ 0 ] = ZIPOP_GETZONELIST;
41 while (( c = getopt( argc, argv, "ml" )) != EOF ) {
44 if ( localzonesflg ) {
48 reqdata[ 0 ] = ZIPOP_GETMYZONE;
55 reqdata[ 0 ] = ZIPOP_GETLOCALZONES;
62 if ( errflg || argc - optind > 1 ) {
66 memset( &saddr, 0, sizeof( struct sockaddr_at ));
68 saddr.sat_len = sizeof( struct sockaddr_at );
70 saddr.sat_family = AF_APPLETALK;
71 if (( se = getservbyname( "zip", "ddp" )) == NULL )
74 saddr.sat_port = ntohs( se->s_port );
76 if ( argc == optind ) {
77 saddr.sat_addr.s_net = ATADDR_ANYNET;
78 saddr.sat_addr.s_node = ATADDR_ANYNODE;
80 if ( !atalk_aton( argv[ optind ], &saddr.sat_addr )) {
81 fprintf( stderr, "Bad address.\n" );
86 if (( ah = atp_open( ATADDR_ANYPORT, &saddr.sat_addr )) == NULL ) {
91 index = ( myzoneflg ? 0 : 1 );
95 atpb.atp_saddr = &saddr;
96 temp = htons( index );
97 memcpy( reqdata + 2, &temp, 2 );
98 atpb.atp_sreqdata = reqdata;
99 atpb.atp_sreqdlen = 4;
101 atpb.atp_sreqtries = 5;
103 /* send getzone request zones (or get my zone)
105 if ( atp_sreq( ah, &atpb, 1, 0 ) < 0 ) {
106 perror( "atp_sreq" );
111 iov.iov_len = ATP_MAXDATA;
112 atpb.atp_rresiov = &iov;
113 atpb.atp_rresiovcnt = 1;
115 if ( atp_rresp( ah, &atpb ) < 0 ) {
116 perror( "atp_rresp" );
120 memcpy( &temp, (char *) iov.iov_base + 2, 2 );
121 temp = ntohs( temp );
122 print_zones( temp, (char *) iov.iov_base+4 );
124 } while ( !myzoneflg && !((char *)iov.iov_base)[ 0 ] );
126 if ( atp_close( ah ) != 0 ) {
127 perror( "atp_close" );
135 print_zones( n, buf )
136 short n; /* number of zones in this packet */
137 char *buf; /* zone length/name pairs */
139 for ( ; n--; buf += (*buf) + 1 ) {
140 printf( "%.*s\n", *buf, buf+1 );