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