OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [pmap_clnt.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*
2
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3
 * unrestricted use provided that this legend is included on all tape
4
 * media and as a part of the software program in whole or part.  Users
5
 * may copy or modify Sun RPC without charge, but are not authorized
6
 * to license or distribute it to anyone else except as part of a product or
7
 * program developed by the user.
8
 *
9
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12
 *
13
 * Sun RPC is provided with no support and without any obligation on the
14
 * part of Sun Microsystems, Inc. to assist in its use, correction,
15
 * modification or enhancement.
16
 *
17
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19
 * OR ANY PART THEREOF.
20
 *
21
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22
 * or profits or other special, indirect and consequential damages, even if
23
 * Sun has been advised of the possibility of such damages.
24
 *
25
 * Sun Microsystems, Inc.
26
 * 2550 Garcia Avenue
27
 * Mountain View, California  94043
28
 */
29
/*
30
 * Copyright (C) 1984, Sun Microsystems, Inc.
31
 */
32
/*
33
 * pmap_clnt.c
34
 * Client interface to pmap rpc service.
35
 */
36
 
37
#define __FORCE_GLIBC
38
#include <features.h>
39
 
40
#include <stdio.h>
41
#include <unistd.h>
42
#include <net/if.h>
43
#include <sys/ioctl.h>
44
#include <sys/socket.h>
45
#include <netinet/in.h>
46
#include <arpa/inet.h>
47
#include <rpc/rpc.h>
48
#include <rpc/pmap_prot.h>
49
#include <rpc/pmap_clnt.h>
50
 
51
/*
52
 * Same as get_myaddress, but we try to use the loopback
53
 * interface. portmap caches interfaces, and on DHCP clients,
54
 * it could be that only loopback is started at this time.
55
 */
56
static bool_t
57
__get_myaddress (struct sockaddr_in *addr)
58
{
59
  int s;
60
  char buf[BUFSIZ];
61
  struct ifconf ifc;
62
  struct ifreq ifreq, *ifr;
63
  int len, loopback = 1;
64
 
65
  if ((s = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
66
    {
67
      perror ("__get_myaddress: socket");
68
      exit (1);
69
    }
70
  ifc.ifc_len = sizeof (buf);
71
  ifc.ifc_buf = buf;
72
  if (ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0)
73
    {
74
      perror (_("__get_myaddress: ioctl (get interface configuration)"));
75
      exit (1);
76
    }
77
 
78
 again:
79
  ifr = ifc.ifc_req;
80
  for (len = ifc.ifc_len; len; len -= sizeof ifreq)
81
    {
82
      ifreq = *ifr;
83
      if (ioctl (s, SIOCGIFFLAGS, (char *) &ifreq) < 0)
84
        {
85
          perror ("__get_myaddress: ioctl");
86
          exit (1);
87
        }
88
      if ((ifreq.ifr_flags & IFF_UP) && (ifr->ifr_addr.sa_family == AF_INET)
89
          && ((ifreq.ifr_flags & IFF_LOOPBACK) || (loopback == 0)))
90
        {
91
          *addr = *((struct sockaddr_in *) &ifr->ifr_addr);
92
          addr->sin_port = htons (PMAPPORT);
93
          close (s);
94
          return TRUE;
95
        }
96
      ifr++;
97
    }
98
  if (loopback == 1)
99
    {
100
      loopback = 0;
101
      goto again;
102
    }
103
  close (s);
104
  return FALSE;
105
}
106
 
107
 
108
static const struct timeval timeout = {5, 0};
109
static const struct timeval tottimeout = {60, 0};
110
 
111
/*
112
 * Set a mapping between program,version and port.
113
 * Calls the pmap service remotely to do the mapping.
114
 */
115
bool_t
116
pmap_set (u_long program, u_long version, int protocol, u_short port)
117
{
118
  struct sockaddr_in myaddress;
119
  int socket = -1;
120
  CLIENT *client;
121
  struct pmap parms;
122
  bool_t rslt;
123
 
124
  if (!__get_myaddress (&myaddress))
125
    return FALSE;
126
  client = clntudp_bufcreate (&myaddress, PMAPPROG, PMAPVERS,
127
                        timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
128
  if (client == (CLIENT *) NULL)
129
    return (FALSE);
130
  parms.pm_prog = program;
131
  parms.pm_vers = version;
132
  parms.pm_prot = protocol;
133
  parms.pm_port = port;
134
  if (CLNT_CALL (client, PMAPPROC_SET, (xdrproc_t)xdr_pmap, (caddr_t)&parms,
135
                 (xdrproc_t)xdr_bool, (caddr_t)&rslt,
136
                 tottimeout) != RPC_SUCCESS)
137
    {
138
      clnt_perror (client, _("Cannot register service"));
139
      return FALSE;
140
    }
141
  CLNT_DESTROY (client);
142
  /* (void)close(socket); CLNT_DESTROY closes it */
143
  return rslt;
144
}
145
 
146
/*
147
 * Remove the mapping between program,version and port.
148
 * Calls the pmap service remotely to do the un-mapping.
149
 */
150
bool_t
151
pmap_unset (u_long program, u_long version)
152
{
153
  struct sockaddr_in myaddress;
154
  int socket = -1;
155
  CLIENT *client;
156
  struct pmap parms;
157
  bool_t rslt;
158
 
159
  if (!__get_myaddress (&myaddress))
160
    return FALSE;
161
  client = clntudp_bufcreate (&myaddress, PMAPPROG, PMAPVERS,
162
                        timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
163
  if (client == (CLIENT *) NULL)
164
    return FALSE;
165
  parms.pm_prog = program;
166
  parms.pm_vers = version;
167
  parms.pm_port = parms.pm_prot = 0;
168
  CLNT_CALL (client, PMAPPROC_UNSET, (xdrproc_t)xdr_pmap, (caddr_t)&parms,
169
             (xdrproc_t)xdr_bool, (caddr_t)&rslt, tottimeout);
170
  CLNT_DESTROY (client);
171
  /* (void)close(socket); CLNT_DESTROY already closed it */
172
  return rslt;
173
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.