]> arthur.barton.de Git - netatalk.git/blob - bin/nbp/nbprgstr.c
Correct prototyping.
[netatalk.git] / bin / nbp / nbprgstr.c
1 /*
2  * Copyright (c) 1990,1993 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/param.h>
15
16 #include <netatalk/endian.h>
17 #include <netatalk/at.h>
18 #include <atalk/netddp.h>
19 #include <atalk/nbp.h>
20 #include <atalk/util.h>
21
22 void Usage( av0 )
23     char        *av0;
24 {
25     char        *p;
26
27     if (( p = strrchr( av0, '/' )) == 0 ) {
28         p = av0;
29     } else {
30         p++;
31     }
32
33     fprintf( stderr, "Usage: %s [ -A address ] obj:type@zone\n", p );
34     exit( 1 );
35 }
36
37 int main( ac, av )
38     int         ac;
39     char        **av;
40 {
41     struct sockaddr_at  addr;
42     struct at_addr      ataddr;
43     char                *Obj = 0, *Type = 0, *Zone = 0;
44     int                 s, c, port = 0;
45     
46     extern char         *optarg;
47     extern int          optind;
48
49     memset(&ataddr, 0, sizeof(ataddr));
50     while (( c = getopt( ac, av, "p:A:" )) != EOF ) {
51         switch ( c ) {
52         case 'A':
53             if (!atalk_aton(optarg, &ataddr)) {
54                 fprintf(stderr, "Bad address.\n");
55                 exit(1);
56             }
57             break;
58
59         case 'p' :
60             port = atoi( optarg );
61             break;
62
63         default :
64             Usage( av[ 0 ] );
65         }
66     }
67
68     if ( ac - optind != 1 ) {
69         Usage( av[ 0 ] );
70     }
71
72     /*
73      * Get the name. If Type or Obj aren't specified, error.
74      */
75     if ( nbp_name( av[ optind ], &Obj, &Type, &Zone ) || !Obj || !Type ) {
76         Usage( av[ 0 ] );
77     }
78
79     memset(&addr, 0, sizeof(addr));
80     memcpy(&addr.sat_addr, &ataddr, sizeof(addr.sat_addr));
81     if ((s = netddp_open(&addr, NULL)) < 0)
82         return( -1 );
83
84     if ( port ) {
85         addr.sat_port = port;
86     }
87
88     if ( nbp_rgstr( &addr, Obj, Type, Zone ) < 0 ) {
89         perror( "nbp_rgstr" );
90         fprintf( stderr, "Can't register %s:%s@%s\n", Obj, Type,
91                 Zone ? Zone : "*" );
92         exit( 1 );
93     }
94     netddp_close(s);
95
96     return 0;
97 }