~ubuntu-branches/ubuntu/hardy/klibc/hardy-updates

« back to all changes in this revision

Viewing changes to usr/kinit/nfsmount/portmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2006-01-04 20:24:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104202452-ec4v3n829rymukuv
Tags: 1.1.15-0ubuntu1
* New upstream version.

* Patch to fix compilation on parisc64 kernels.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <sys/types.h>
 
2
#include <netinet/in.h>
 
3
#include <asm/byteorder.h>      /* __constant_hton* */
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
 
 
7
#include "nfsmount.h"
 
8
#include "sunrpc.h"
 
9
 
 
10
struct portmap_call
 
11
{
 
12
        struct rpc_call rpc;
 
13
        __u32 program;
 
14
        __u32 version;
 
15
        __u32 proto;
 
16
        __u32 port;
 
17
};
 
18
 
 
19
struct portmap_reply
 
20
{
 
21
        struct rpc_reply rpc;
 
22
        __u32 port;
 
23
};
 
24
 
 
25
static struct portmap_call call = {
 
26
        .rpc.program   = __constant_htonl(RPC_PMAP_PROGRAM),
 
27
        .rpc.prog_vers = __constant_htonl(RPC_PMAP_VERSION),
 
28
        .rpc.proc      = __constant_htonl(PMAP_PROC_GETPORT),
 
29
};
 
30
 
 
31
__u32 portmap(__u32 server, __u32 program, __u32 version, __u32 proto)
 
32
{
 
33
        struct portmap_reply reply;
 
34
        struct client *clnt;
 
35
        struct rpc rpc;
 
36
        __u32 port = 0;
 
37
 
 
38
        if ((clnt = tcp_client(server, RPC_PMAP_PORT, 0)) == NULL) {
 
39
                if ((clnt = udp_client(server, RPC_PMAP_PORT, 0)) == NULL) {
 
40
                        goto bail;
 
41
                }
 
42
        }
 
43
 
 
44
        call.program = htonl(program);
 
45
        call.version = htonl(version);
 
46
        call.proto = htonl(proto);
 
47
 
 
48
        rpc.call = (struct rpc_call *) &call;
 
49
        rpc.call_len = sizeof(call);
 
50
        rpc.reply = (struct rpc_reply *) &reply;
 
51
        rpc.reply_len = sizeof(reply);
 
52
 
 
53
        if (rpc_call(clnt, &rpc) < 0)
 
54
                goto bail;
 
55
 
 
56
        if (rpc.reply_len < sizeof(reply)) {
 
57
                fprintf(stderr, "incomplete reply: %zu < %zu\n",
 
58
                        rpc.reply_len, sizeof(reply));
 
59
                goto bail;
 
60
        }
 
61
 
 
62
        port = ntohl(reply.port);
 
63
 
 
64
 bail:
 
65
        DEBUG(("Port for %d/%d[%s]: %d\n", program, version,
 
66
               proto == IPPROTO_TCP ? "tcp" : "udp", port));
 
67
 
 
68
        if (clnt) {
 
69
                client_free(clnt);
 
70
        }
 
71
 
 
72
        return port;
 
73
}