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