2 #include <sys/socket.h>
9 #include <netatalk/endian.h>
10 #include <netatalk/at.h>
11 #include <atalk/atp.h>
12 #include <atalk/zip.h>
17 fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
25 struct atp_handle *ah;
26 struct atp_block atpb;
27 struct sockaddr_at saddr;
29 char reqdata[4], buf[ ATP_MAXDATA ];
31 short temp, index = 0;
32 int c, myzoneflg = 0, localzonesflg = 0, errflg = 0;
35 reqdata[ 0 ] = ZIPOP_GETZONELIST;
37 while (( c = getopt( argc, argv, "ml" )) != EOF ) {
40 if ( localzonesflg ) {
44 reqdata[ 0 ] = ZIPOP_GETMYZONE;
51 reqdata[ 0 ] = ZIPOP_GETLOCALZONES;
58 if ( errflg || argc - optind > 1 ) {
62 memset( &saddr, 0, sizeof( struct sockaddr_at ));
64 saddr.sat_len = sizeof( struct sockaddr_at );
66 saddr.sat_family = AF_APPLETALK;
67 if (( se = getservbyname( "zip", "ddp" )) == NULL )
70 saddr.sat_port = ntohs( se->s_port );
72 if ( argc == optind ) {
73 saddr.sat_addr.s_net = ATADDR_ANYNET;
74 saddr.sat_addr.s_node = ATADDR_ANYNODE;
76 if ( !atalk_aton( argv[ optind ], &saddr.sat_addr )) {
77 fprintf( stderr, "Bad address.\n" );
82 if (( ah = atp_open( ATADDR_ANYPORT, &saddr.sat_addr )) == NULL ) {
87 index = ( myzoneflg ? 0 : 1 );
91 atpb.atp_saddr = &saddr;
92 temp = htons( index );
93 memcpy( reqdata + 2, &temp, 2 );
94 atpb.atp_sreqdata = reqdata;
95 atpb.atp_sreqdlen = 4;
97 atpb.atp_sreqtries = 5;
99 /* send getzone request zones (or get my zone)
101 if ( atp_sreq( ah, &atpb, 1, 0 ) < 0 ) {
102 perror( "atp_sreq" );
107 iov.iov_len = ATP_MAXDATA;
108 atpb.atp_rresiov = &iov;
109 atpb.atp_rresiovcnt = 1;
111 if ( atp_rresp( ah, &atpb ) < 0 ) {
112 perror( "atp_rresp" );
116 memcpy( &temp, (char *) iov.iov_base + 2, 2 );
117 temp = ntohs( temp );
118 print_zones( temp, (char *) iov.iov_base+4 );
120 } while ( !myzoneflg && !((char *)iov.iov_base)[ 0 ] );
122 if ( atp_close( ah ) != 0 ) {
123 perror( "atp_close" );
131 print_zones( n, buf )
132 short n; /* number of zones in this packet */
133 char *buf; /* zone length/name pairs */
135 for ( ; n--; buf += (*buf) + 1 ) {
136 printf( "%.*s\n", *buf, buf+1 );