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