+/*
+ * $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>
-void print_zones(short n, char *buf);
+static void print_zones(short n, char *buf);
-void usage( s )
- char *s;
+static void usage( char *s)
{
fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
exit( 1 );
}
-int main( argc, argv )
- int argc;
- char *argv[];
+int main( int argc, char *argv[])
{
struct atp_handle *ah;
struct atp_block atpb;
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;
}
-void 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);
}
}