2 * $Id: nbplkup.c,v 1.4 2001-06-29 14:14:46 rufustfirefly 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>
37 #if !defined( sun ) || !defined( i386 )
39 #endif /* ! sun || ! i386 */
50 if (( p = strrchr( av0, '/' )) == 0 ) {
56 printf( "Usage:\t%s [ -A address ] [ -r responses] [ obj:type@zone ]\n", p );
66 int i, c, nresp = 1000;
72 memset(&addr, 0, sizeof(addr));
73 while (( c = getopt( ac, av, "r:A:" )) != EOF ) {
76 if (!atalk_aton(optarg, &addr)) {
77 fprintf(stderr, "Bad address.\n");
82 nresp = atoi( optarg );
91 if (( nn = (struct nbpnve *)malloc( nresp * sizeof( struct nbpnve )))
97 if ( ac - optind > 1 ) {
103 * Get default values from the environment. We need to copy out
104 * the results, here, since nbp_name returns it's parameters
105 * in static space, and we'll clobber them when we call it again
108 if (( name = getenv( "NBPLKUP" )) != NULL ) {
109 if ( nbp_name( name, &Obj, &Type, &Zone )) {
111 "Environment variable syntax error: NBPLKUP = %s\n",
116 if (( name = (char *)malloc( strlen( Obj ) + 1 )) == NULL ) {
123 if (( name = (char *)malloc( strlen( Type ) + 1 )) == NULL ) {
127 strcpy( name, Type );
130 if (( name = (char *)malloc( strlen( Zone ) + 1 )) == NULL ) {
134 strcpy( name, Zone );
139 if ( ac - optind == 1 ) {
140 if ( nbp_name( av[ optind ], &Obj, &Type, &Zone )) {
146 if (( c = nbp_lookup( Obj, Type, Zone, nn, nresp, &addr)) < 0 ) {
147 perror( "nbp_lookup" );
150 for ( i = 0; i < c; i++ ) {
151 printf( "%31.*s:%-34.*s %u.%u:%u\n",
152 nn[ i ].nn_objlen, nn[ i ].nn_obj,
153 nn[ i ].nn_typelen, nn[ i ].nn_type,
154 ntohs( nn[ i ].nn_sat.sat_addr.s_net ),
155 nn[ i ].nn_sat.sat_addr.s_node,
156 nn[ i ].nn_sat.sat_port );