]> arthur.barton.de Git - netatalk.git/blob - bin/nbp/nbpunrgstr.c
19966b180719c3b7d9e4be897303aa6e03a80685
[netatalk.git] / bin / nbp / nbpunrgstr.c
1 /*
2  * $Id: nbpunrgstr.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
3  *
4  * Copyright (c) 1990,1991 Regents of The University of Michigan.
5  * All Rights Reserved.
6  *
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.
16  *
17  *      Research Systems Unix Group
18  *      The University of Michigan
19  *      c/o Mike Clark
20  *      535 W. William Street
21  *      Ann Arbor, Michigan
22  *      +1-313-763-0525
23  *      netatalk@itd.umich.edu
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif /* HAVE_CONFIG_H */
29
30 #include <sys/types.h>
31 #include <stdio.h>
32 #include <string.h>
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif /* HAVE_UNISTD_H */
36 #include <netatalk/endian.h>
37 #include <netatalk/at.h>
38 #include <atalk/util.h>
39 #include <atalk/nbp.h>
40
41 void Usage( av0 )
42     char        *av0;
43 {
44     char        *p;
45
46     if (( p = strrchr( av0, '/' )) == 0 ) {
47         p = av0;
48     } else {
49         p++;
50     }
51
52     fprintf( stderr, "Usage: %s [ -A address ] obj:type@zone\n", p );
53     exit( 1 );
54 }
55
56 int main( ac, av )
57     int         ac;
58     char        **av;
59 {
60     char                *Obj = 0, *Type = 0, *Zone = 0;
61     struct at_addr      addr;
62     int                 c;
63
64     extern char         *optarg;
65     extern int          optind;
66     
67     memset(&addr, 0, sizeof(addr));
68     while ((c = getopt(ac, av, "A:")) != EOF) {
69       switch (c) {
70       case 'A':
71         if (!atalk_aton(optarg, &addr)) {
72           fprintf(stderr, "Bad address.\n");
73           exit(1);
74         }
75         break;
76       default:
77         Usage(av[0]);
78         break;
79       }
80     }
81
82     if (ac - optind != 1) {
83         Usage( av[ 0 ] );
84     }
85
86     /*
87      * Get the name. If Type or Obj aren't specified, error.
88      */
89     if ( nbp_name( av[optind], &Obj, &Type, &Zone ) || !Obj || !Type ) {
90         Usage( av[ 0 ] );
91     }
92
93     if ( nbp_unrgstr( Obj, Type, Zone, &addr ) < 0 ) {
94         fprintf( stderr, "Can't unregister %s:%s@%s\n", Obj, Type,
95                 Zone ? Zone : "*" );
96         exit( 1 );
97     }
98
99     return 0;
100 }