Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rx / simple.example / sample_client.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
14 #include <sys/types.h>
15 #include <netdb.h>
16 #include <stdio.h>
17 #include "sample.h"
18
19 /* Bogus procedure to get internet address of host */
20 static unsigned int
21 GetIpAddress(char *hostname)
22 {
23 struct hostent *hostent;
24 unsigned int host;
25 hostent = gethostbyname(hostname);
26 if (!hostent) {
27 printf("host %s not found", hostname);
28 exit(1);
29 }
30 if (hostent->h_length != sizeof(unsigned int)) {
31 printf("host address is disagreeable length (%d)", hostent->h_length);
32 exit(1);
33 }
34 memcpy((char *)&host, hostent->h_addr, sizeof(host));
35 return host;
36 }
37
38 int
39 main(int argc, char **argv)
40 {
41 struct rx_connection *conn;
42 u_long host;
43 struct rx_securityClass *null_securityObject;
44 int i;
45
46 rx_Init(0);
47 host = GetIpAddress(argv[1]);
48 null_securityObject = rxnull_NewClientSecurityObject();
49 conn =
50 rx_NewConnection(host, SAMPLE_SERVER_PORT, SAMPLE_SERVICE_ID,
51 null_securityObject, RX_SECIDX_NULL);
52 for (i = 1; i < 10; i++) {
53 int error, result;
54 printf("add(%d,%d)", i, i * 2);
55 error = TEST_Add(conn, i, i * 2, &result);
56 printf(" ==> %d, error %d\n", result, error);
57 printf("sub(%d,%d)", i, i * 2);
58 error = TEST_Sub(conn, i, i * 2, &result);
59 printf(" ==> %d, error %d\n", result, error);
60 }
61
62 return 0;
63 }