2 * $Id: getzones.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
7 #endif /* HAVE_CONFIG_H */
10 #include <sys/socket.h>
11 #include <sys/param.h>
16 #endif /* HAVE_UNISTD_H */
19 #endif /* HAVE_NETDB_H */
22 #include <netatalk/endian.h>
23 #include <netatalk/at.h>
24 #include <atalk/atp.h>
25 #include <atalk/util.h>
26 #include <atalk/zip.h>
28 void print_zones(short n, char *buf);
33 fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
37 int main( argc, argv )
41 struct atp_handle *ah;
42 struct atp_block atpb;
43 struct sockaddr_at saddr;
45 char reqdata[4], buf[ ATP_MAXDATA ];
47 short temp, index = 0;
48 int c, myzoneflg = 0, localzonesflg = 0, errflg = 0;
51 reqdata[ 0 ] = ZIPOP_GETZONELIST;
53 while (( c = getopt( argc, argv, "ml" )) != EOF ) {
56 if ( localzonesflg ) {
60 reqdata[ 0 ] = ZIPOP_GETMYZONE;
67 reqdata[ 0 ] = ZIPOP_GETLOCALZONES;
74 if ( errflg || argc - optind > 1 ) {
78 memset( &saddr, 0, sizeof( struct sockaddr_at ));
80 saddr.sat_len = sizeof( struct sockaddr_at );
82 saddr.sat_family = AF_APPLETALK;
83 if (( se = getservbyname( "zip", "ddp" )) == NULL )
86 saddr.sat_port = ntohs( se->s_port );
88 if ( argc == optind ) {
89 saddr.sat_addr.s_net = ATADDR_ANYNET;
90 saddr.sat_addr.s_node = ATADDR_ANYNODE;
92 if ( !atalk_aton( argv[ optind ], &saddr.sat_addr )) {
93 fprintf( stderr, "Bad address.\n" );
98 if (( ah = atp_open( ATADDR_ANYPORT, &saddr.sat_addr )) == NULL ) {
103 index = ( myzoneflg ? 0 : 1 );
107 atpb.atp_saddr = &saddr;
108 temp = htons( index );
109 memcpy( reqdata + 2, &temp, 2 );
110 atpb.atp_sreqdata = reqdata;
111 atpb.atp_sreqdlen = 4;
113 atpb.atp_sreqtries = 5;
115 /* send getzone request zones (or get my zone)
117 if ( atp_sreq( ah, &atpb, 1, 0 ) < 0 ) {
118 perror( "atp_sreq" );
123 iov.iov_len = ATP_MAXDATA;
124 atpb.atp_rresiov = &iov;
125 atpb.atp_rresiovcnt = 1;
127 if ( atp_rresp( ah, &atpb ) < 0 ) {
128 perror( "atp_rresp" );
132 memcpy( &temp, (char *) iov.iov_base + 2, 2 );
133 temp = ntohs( temp );
134 print_zones( temp, (char *) iov.iov_base+4 );
136 } while ( !myzoneflg && !((char *)iov.iov_base)[ 0 ] );
138 if ( atp_close( ah ) != 0 ) {
139 perror( "atp_close" );
147 void print_zones( n, buf )
148 short n; /* number of zones in this packet */
149 char *buf; /* zone length/name pairs */
151 for ( ; n--; buf += (*buf) + 1 ) {
152 printf( "%.*s\n", *buf, buf+1 );