2 * $Id: nbplkup.c,v 1.9 2009-10-29 11:35:57 didg Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
30 #include <sys/types.h>
31 #include <netatalk/endian.h>
32 #include <netatalk/at.h>
33 #include <atalk/nbp.h>
34 #include <atalk/util.h>
42 #include <atalk/unicode.h>
44 static char *Obj = "=";
45 static char *Type = "=";
46 static char *Zone = "*";
48 static void Usage(char *av0)
52 if (( p = strrchr( av0, '/' )) == NULL ) {
58 printf( "Usage:\t%s [ -A address ] [ -r responses] [-m Mac charset] [ obj:type@zone ]\n", p );
62 int main(int ac, char **av)
66 int i, c, nresp = 1000;
70 charset_t chMac = CH_MAC;
76 memset(&addr, 0, sizeof(addr));
77 while (( c = getopt( ac, av, "r:A:m:" )) != EOF ) {
80 if (!atalk_aton(optarg, &addr)) {
81 fprintf(stderr, "Bad address.\n");
86 nresp = atoi( optarg );
89 if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
90 fprintf(stderr, "Invalid Mac charset.\n");
101 if (( nn = (struct nbpnve *)malloc( nresp * sizeof( struct nbpnve )))
107 if ( ac - optind > 1 ) {
113 * Get default values from the environment. We need to copy out
114 * the results, here, since nbp_name returns it's parameters
115 * in static space, and we'll clobber them when we call it again
118 if (( name = getenv( "NBPLKUP" )) != NULL ) {
119 if ( nbp_name( name, &Obj, &Type, &Zone )) {
121 "Environment variable syntax error: NBPLKUP = %s\n",
126 if (( name = (char *)malloc( strlen( Obj ) + 1 )) == NULL ) {
133 if (( name = (char *)malloc( strlen( Type ) + 1 )) == NULL ) {
137 strcpy( name, Type );
140 if (( name = (char *)malloc( strlen( Zone ) + 1 )) == NULL ) {
144 strcpy( name, Zone );
149 if ( ac - optind == 1 ) {
150 if ((size_t)(-1) == convert_string_allocate( CH_UNIX, chMac,
151 av[ optind ], -1, &convname))
152 convname = av[ optind ];
154 if ( nbp_name( convname, &Obj, &Type, &Zone )) {
160 if (( c = nbp_lookup( Obj, Type, Zone, nn, nresp, &addr)) < 0 ) {
161 perror( "nbp_lookup" );
164 for ( i = 0; i < c; i++ ) {
166 if ((size_t)(-1) == (obj_len = convert_string_allocate( chMac,
167 CH_UNIX, nn[ i ].nn_obj, nn[ i ].nn_objlen, &obj)) ) {
168 obj_len = nn[ i ].nn_objlen;
169 if (( obj = strdup(nn[ i ].nn_obj)) == NULL ) {
175 printf( "%31.*s:%-34.*s %u.%u:%u\n",
177 nn[ i ].nn_typelen, nn[ i ].nn_type,
178 ntohs( nn[ i ].nn_sat.sat_addr.s_net ),
179 nn[ i ].nn_sat.sat_addr.s_node,
180 nn[ i ].nn_sat.sat_port );