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