source: network-demos/rpc_demo/rprintmsg.c @ 0fe6b0d

4.11network-demos-4-10-branch
Last change on this file since 0fe6b0d was e6f3168, checked in by Joel Sherrill <joel.sherrill@…>, on 04/29/00 at 19:53:34

New test from Eric Norum <eric@…> to exercise RPC/XDR.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 * This client runs on the RTEMS target or on the host machine.
3 *
4 *      W. Eric Norum
5 *      eric@cls.usask.ca
6 */
7#include <stdio.h>
8#include <rpc/rpc.h>
9#include <netdb.h>
10#include "msg.h"
11
12int
13main (int argc, char **argv)
14{
15        struct hostent *hp;
16        struct sockaddr_in farAddr;
17        int sock = -1;
18        CLIENT *c1;
19        int *result;
20        char *server;
21        char *message;
22        int itmp;
23
24        /*
25         * Process arguments
26         */
27        if (argc != 3) {
28                fprintf (stderr, "Usage: %s server message\n", argv[0]);
29                return 1;
30        }
31        server = argv[1];
32        message = argv[2];
33        hp = gethostbyname (server);
34        if (hp == NULL) {
35                fprintf (stderr, "No server %s\n", server);
36                return 2;
37        }
38
39        /*
40         * Set up server address
41         */
42        farAddr.sin_family = hp->h_addrtype;
43        farAddr.sin_port = htons (TCP_PORT);
44        memcpy((char*)&farAddr.sin_addr, hp->h_addr, hp->h_length);
45
46        /*
47         * Create connection to server
48         */
49        c1 = clnttcp_create (&farAddr, MESSAGEPROC, MESSAGEVERS, &sock, 0, 0);
50        if (c1 == NULL) {
51                clnt_pcreateerror (server);
52                return 3;
53        }
54
55        /*
56         * Call remote procedures
57         */
58        result = printmessage_1 (&message, c1);
59        if (result == NULL) {
60                clnt_perror (c1, server);
61                return 4;
62        }
63        printf ("Printed %d characters on %s.\n", *result, server);
64
65        itmp = 12;
66        result = printnum_1 (&itmp, c1);
67        if (result == NULL) {
68                clnt_perror (c1, server);
69                return 5;
70        }
71        printf ("Result is %d.\n", *result);
72
73        return 0;
74}
Note: See TracBrowser for help on using the repository browser.