Linux-6.9: file_lock mbrs moved to file_lock_core
[openafs.git] / src / viced / fsprobe.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 #include <afs/stds.h>
13
14 #include <roken.h>
15
16 #include <afs/afsint.h>
17 #include <rx/rx_globals.h>
18 #include <ubik.h>
19
20 struct ubik_client *cstruct;
21 struct rx_connection *serverconns[MAXSERVERS];
22 char *(args[50]);
23
24 afs_int32
25 pxclient_Initialize(int auth, afs_int32 serverAddr)
26 {
27     afs_int32 code;
28     rx_securityIndex scIndex;
29     struct rx_securityClass *sc;
30
31     code = rx_Init(htons(2115) /*0 */ );
32     if (code) {
33         fprintf(stderr, "pxclient_Initialize:  Could not initialize rx.\n");
34         return code;
35     }
36     scIndex = RX_SECIDX_NULL;
37     rx_SetRxDeadTime(50);
38     sc = rxnull_NewClientSecurityObject();
39     serverconns[0] =
40         rx_NewConnection(serverAddr, htons(7000), 1, sc, scIndex);
41
42     code = ubik_ClientInit(serverconns, &cstruct);
43
44     if (code) {
45         fprintf(stderr, "pxclient_Initialize: ubik client init failed.\n");
46         return code;
47     }
48     return 0;
49 }
50
51 /* main program */
52
53 #include "AFS_component_version_number.c"
54
55 int
56 main(int argc, char **argv)
57 {
58     char **av = argv;
59     struct sockaddr_in host;
60     afs_int32 code;
61     struct hostent *hp;
62     struct timeval tv;
63     int noAuth = 1;             /* Default is authenticated connections */
64
65     argc--, av++;
66     if (argc < 1) {
67         printf("usage: fsprobe <serverHost>\n");
68         exit(1);
69     }
70     memset(&host, 0, sizeof(struct sockaddr_in));
71     host.sin_family = AF_INET;
72     host.sin_addr.s_addr = inet_addr(av[0]);
73 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
74     host.sin_len = sizeof(struct sockaddr_in);
75 #endif
76     if (host.sin_addr.s_addr == -1) {
77         hp = gethostbyname(av[0]);
78         if (hp) {
79             host.sin_family = hp->h_addrtype;
80             memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length);
81         } else {
82             printf("unknown server host %s\n", av[0]);
83             exit(1);
84         }
85     }
86     if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) {
87         printf("Couldn't initialize fs library (code=%d).\n", code);
88         exit(1);
89     }
90
91     code = RXAFS_GetTime(cstruct->conns[0], (afs_uint32 *)&tv.tv_sec, (afs_uint32 *)&tv.tv_usec);
92     if (!code)
93         printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], (long)tv.tv_sec,
94                (long)tv.tv_usec);
95     else
96         printf("return code is %d\n", code);
97
98     return 0;
99 }
100
101
102 void
103 GetArgs(char *line, char **args, int *nargs)
104 {
105     *nargs = 0;
106     while (*line) {
107         char *last = line;
108         while (*line == ' ')
109             line++;
110         if (*last == ' ')
111             *last = 0;
112         if (!*line)
113             break;
114         *args++ = line, (*nargs)++;
115         while (*line && *line != ' ')
116             line++;
117     }
118 }