]> arthur.barton.de Git - netatalk.git/blobdiff - bin/nbp/nbplkup.c
Update NEWS
[netatalk.git] / bin / nbp / nbplkup.c
index b677e4600234e692c4572d559c9e2d0ad2c932f7..a43ac41c06d850174b22ad88c9cca9737b4332bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: nbplkup.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
+ * $Id: nbplkup.c,v 1.9 2009-10-29 11:35:57 didg Exp $
  *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
 #include <atalk/util.h>
 #include <string.h>
 #include <stdio.h>
-#if !defined( sun ) || !defined( i386 )
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif /* ! sun || ! i386 */
+#endif
 
-char *Obj = "=";
-char *Type = "=";
-char *Zone = "*";
 
-void Usage( av0 )
-    char       *av0;
+#include <atalk/unicode.h>
+
+static char *Obj = "=";
+static char *Type = "=";
+static char *Zone = "*";
+
+static void Usage(char *av0)
 {
     char       *p;
 
-    if (( p = strrchr( av0, '/' )) == 0 ) {
+    if (( p = strrchr( av0, '/' )) == NULL ) {
        p = av0;
     } else {
        p++;
     }
 
-    printf( "Usage:\t%s [ -A address ] [ -r responses] [ obj:type@zone ]\n", p );
+    printf( "Usage:\t%s [ -A address ] [ -r responses] [-m Mac charset] [ obj:type@zone ]\n", p );
     exit( 1 );
 }
 
-int main( ac, av )
-    int                ac;
-    char       **av;
+int main(int ac, char **av)
 {
     struct nbpnve      *nn;
     char               *name;
     int                        i, c, nresp = 1000;
     struct at_addr      addr;
+    char               *obj = NULL;
+    size_t             obj_len;
+    charset_t          chMac = CH_MAC;
+    char *             convname;
 
     extern char                *optarg;
     extern int         optind;
 
     memset(&addr, 0, sizeof(addr));
-    while (( c = getopt( ac, av, "r:A:" )) != EOF ) {
+    while (( c = getopt( ac, av, "r:A:m:" )) != EOF ) {
        switch ( c ) {
        case 'A':
            if (!atalk_aton(optarg, &addr)) {
@@ -81,6 +85,12 @@ int main( ac, av )
        case 'r' :
            nresp = atoi( optarg );
            break;
+        case 'm':
+            if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
+               fprintf(stderr, "Invalid Mac charset.\n");
+               exit(1);
+           }
+            break;
 
        default :
            Usage( av[ 0 ] );
@@ -137,7 +147,11 @@ int main( ac, av )
     }
 
     if ( ac - optind == 1 ) {
-       if ( nbp_name( av[ optind ], &Obj, &Type, &Zone )) {
+       if ((size_t)(-1) == convert_string_allocate( CH_UNIX, chMac,
+                           av[ optind ], -1, &convname))
+            convname = av[ optind ];
+
+       if ( nbp_name( convname, &Obj, &Type, &Zone )) {
            Usage( av[ 0 ] );
            exit( 1 );
        }
@@ -148,13 +162,26 @@ int main( ac, av )
        exit( -1 );
     }
     for ( i = 0; i < c; i++ ) {
+       
+       if ((size_t)(-1) == (obj_len = convert_string_allocate( chMac, 
+                       CH_UNIX, nn[ i ].nn_obj, nn[ i ].nn_objlen, &obj)) ) {
+            obj_len = nn[ i ].nn_objlen;
+            if (( obj = strdup(nn[ i ].nn_obj)) == NULL ) {
+               perror( "strdup" );
+               exit( 1 );
+           }
+        }
+
        printf( "%31.*s:%-34.*s %u.%u:%u\n",
-               nn[ i ].nn_objlen, nn[ i ].nn_obj,
+               (int)obj_len, obj,
                nn[ i ].nn_typelen, nn[ i ].nn_type,
                ntohs( nn[ i ].nn_sat.sat_addr.s_net ),
                nn[ i ].nn_sat.sat_addr.s_node,
                nn[ i ].nn_sat.sat_port );
+
+       free(obj);
     }
 
+    free(nn);
     return 0;
 }