AIX: Fix undefined symbols
[openafs.git] / src / ubik / ubikcmd.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <lock.h>
16 #include <rx/xdr.h>
17 #include <rx/rx.h>
18
19 #define UBIK_INTERNALS
20 #include "ubik.h"
21
22 /*! \file
23  * This file contain useful subroutines for parsing command line args for ubik
24  * applications.
25  */
26 int
27 ubik_ParseServerList(int argc, char **argv, afs_uint32 *ahost,
28                      afs_uint32 *aothers)
29 {
30     afs_int32 i;
31     char *tp;
32     struct hostent *th;
33     char hostname[64];
34     afs_uint32 myHost, temp;
35     afs_int32 counter;
36     int inServer, sawServer;
37
38     gethostname(hostname, sizeof(hostname));
39     th = gethostbyname(hostname);
40     if (!th)
41         return UBADHOST;
42     memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
43     *ahost = myHost;
44
45     inServer = 0;               /* haven't seen -servers yet */
46     sawServer = 0;
47     counter = 0;
48     for (i = 1; i < argc; i++) {
49         /* look for -servers argument */
50         tp = argv[i];
51
52         if (inServer) {
53             if (*tp == '-') {
54                 inServer = 0;
55             } else {
56                 /* otherwise this is a new host name */
57                 th = gethostbyname(tp);
58                 if (!th)
59                     return UBADHOST;
60                 memcpy(&temp, th->h_addr, sizeof(afs_uint32));
61                 if (temp != myHost) {
62                     if (counter++ >= MAXSERVERS)
63                         return UNHOSTS;
64                     *aothers++ = temp;
65                 }
66             }
67         }
68         /* haven't seen a -server yet */
69         if (!strcmp(tp, "-servers")) {
70             inServer = 1;
71             sawServer = 1;
72         } else if (!strcmp(tp, "-dubik")) {
73             ubik_debugFlag = 1;
74         }
75     }
76     if (!sawServer) {
77         /* never saw a -server */
78         return UNOENT;
79     }
80     if (counter < MAXSERVERS)
81         *aothers++ = 0;         /* null terminate if there's room */
82     return 0;
83 }