]> arthur.barton.de Git - netatalk.git/blobdiff - bin/getzones/getzones.c
Remove bdb env on exit
[netatalk.git] / bin / getzones / getzones.c
index db665e326f5270d1e8994c0dcab957872731497a..b1757109c7ecc3fd9c7c981f198b7c27b27b5bfd 100644 (file)
@@ -1,30 +1,41 @@
+/*
+ * $Id: getzones.c,v 1.9 2009-10-14 01:38:28 didg Exp $
+ */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/param.h>
 #include <sys/uio.h>
 #include <sys/time.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
+#endif /* HAVE_NETDB_H */
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <netatalk/endian.h>
 #include <netatalk/at.h>
 #include <atalk/atp.h>
+#include <atalk/util.h>
+#include <atalk/unicode.h>
 #include <atalk/zip.h>
 
-usage( s )
-    char *s;
+static void print_zones(short n, char *buf);
+
+static void usage( char *s)
 {
     fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
     exit( 1 );
 }
 
-main( argc, argv )
-    int                argc;
-    char       *argv[];
+int main( int argc, char *argv[])
 {
     struct atp_handle  *ah;
     struct atp_block   atpb;
@@ -66,7 +77,7 @@ main( argc, argv )
     memset( &saddr, 0, sizeof( struct sockaddr_at ));
 #ifdef BSD4_4
     saddr.sat_len = sizeof( struct sockaddr_at );
-#endif BSD4_4
+#endif /* BSD4_4 */
     saddr.sat_family = AF_APPLETALK;
     if (( se = getservbyname( "zip", "ddp" )) == NULL )
        saddr.sat_port = 6;
@@ -132,11 +143,28 @@ main( argc, argv )
 }
 
 
-print_zones( n, buf )
-    short      n;      /* number of zones in this packet */
-    char       *buf;   /* zone length/name pairs */
+/*
+ * n:   number of zones in this packet
+ * buf: zone length/name pairs
+ */
+static void print_zones( short n, char *buf )
 {
+    size_t zone_len;
+    char *zone;
+
     for ( ; n--; buf += (*buf) + 1 ) {
-       printf( "%.*s\n", *buf, buf+1 );
+
+        if ((size_t)(-1) == (zone_len = convert_string_allocate( CH_MAC,
+                       CH_UNIX, buf+1, *buf, &zone)) ) {
+            zone_len = *buf;
+            if (( zone = strdup(buf+1)) == NULL ) {
+               perror( "strdup" );
+               exit( 1 );
+            }
+        }
+
+       printf( "%.*s\n", (int)zone_len, zone );
+
+       free(zone);
     }
 }