mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
add NFS v3 filesystem implementation.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@721 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
1 parent
5836237ae3
commit
0fbfdec40d
25 files changed
+8304
No files matched your search
@@ -0,0 +1,40 @@
|
||||
Import('env')
|
||||
Import('projects')
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
|
||||
src = Split('''
|
||||
mount_clnt.c
|
||||
mount_xdr.c
|
||||
nfs_clnt.c
|
||||
nfs_xdr.c
|
||||
dfs_nfs.c
|
||||
rpc/auth_none.c
|
||||
rpc/clnt_generic.c
|
||||
rpc/clnt_udp.c
|
||||
rpc/rpc_prot.c
|
||||
rpc/pmap.c
|
||||
rpc/xdr.c
|
||||
rpc/xdr_mem.c
|
||||
''')
|
||||
|
||||
# group definitions
|
||||
group = {}
|
||||
group['name'] = 'nfsclient'
|
||||
group['src'] = File(src) #Glob('*.c')
|
||||
group['CCFLAGS'] = ''
|
||||
group['CPPPATH'] = [RTT_ROOT + '/components/dfs/filesystems/nfs']
|
||||
group['CPPDEFINES'] = ''
|
||||
group['LINKFLAGS'] = ''
|
||||
|
||||
# add group to project list
|
||||
projects.append(group)
|
||||
|
||||
env.Append(CCFLAGS = group['CCFLAGS'])
|
||||
env.Append(CPPPATH = group['CPPPATH'])
|
||||
env.Append(CPPDEFINES = group['CPPDEFINES'])
|
||||
env.Append(LINKFLAGS = group['LINKFLAGS'])
|
||||
|
||||
objs = env.Object(group['src'])
|
||||
|
||||
Return('objs')
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
||||
#ifndef __NFS_H__
|
||||
#define __NFS_H__
|
||||
|
||||
int nfs_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _MOUNT_H_RPCGEN
|
||||
#define _MOUNT_H_RPCGEN
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file is copied from RFC1813
|
||||
* Copyright 1995 Sun Micrososystems (I assume)
|
||||
*/
|
||||
#define MNTPATHLEN 1024
|
||||
#define MNTNAMLEN 255
|
||||
#define FHSIZE3 64
|
||||
|
||||
typedef struct {
|
||||
u_int fhandle3_len;
|
||||
char *fhandle3_val;
|
||||
} fhandle3;
|
||||
|
||||
typedef char *dirpath;
|
||||
|
||||
typedef char *name;
|
||||
|
||||
typedef struct exportnode *exports;
|
||||
|
||||
typedef struct groupnode *groups;
|
||||
|
||||
typedef struct mountbody *mountlist;
|
||||
|
||||
enum mountstat3 {
|
||||
MNT3_OK = 0,
|
||||
MNT3ERR_PERM = 1,
|
||||
MNT3ERR_NOENT = 2,
|
||||
MNT3ERR_IO = 5,
|
||||
MNT3ERR_ACCES = 13,
|
||||
MNT3ERR_NOTDIR = 20,
|
||||
MNT3ERR_INVAL = 22,
|
||||
MNT3ERR_NAMETOOLONG = 63,
|
||||
MNT3ERR_NOTSUPP = 10004,
|
||||
MNT3ERR_SERVERFAULT = 10006
|
||||
};
|
||||
typedef enum mountstat3 mountstat3;
|
||||
|
||||
struct mountres3_ok {
|
||||
fhandle3 fhandle;
|
||||
struct {
|
||||
u_int auth_flavors_len;
|
||||
int *auth_flavors_val;
|
||||
} auth_flavors;
|
||||
};
|
||||
typedef struct mountres3_ok mountres3_ok;
|
||||
|
||||
struct mountres3 {
|
||||
mountstat3 fhs_status;
|
||||
union {
|
||||
mountres3_ok mountinfo;
|
||||
} mountres3_u;
|
||||
};
|
||||
typedef struct mountres3 mountres3;
|
||||
|
||||
struct mountbody {
|
||||
name ml_hostname;
|
||||
dirpath ml_directory;
|
||||
mountlist ml_next;
|
||||
};
|
||||
typedef struct mountbody mountbody;
|
||||
|
||||
struct groupnode {
|
||||
name gr_name;
|
||||
groups gr_next;
|
||||
};
|
||||
typedef struct groupnode groupnode;
|
||||
|
||||
struct exportnode {
|
||||
dirpath ex_dir;
|
||||
groups ex_groups;
|
||||
exports ex_next;
|
||||
};
|
||||
typedef struct exportnode exportnode;
|
||||
|
||||
#define MOUNT_PROGRAM 100005
|
||||
#define MOUNT_V3 3
|
||||
|
||||
#define MOUNTPROC3_NULL 0
|
||||
extern enum clnt_stat mountproc3_null_3(void *, CLIENT *);
|
||||
#define MOUNTPROC3_MNT 1
|
||||
extern enum clnt_stat mountproc3_mnt_3(dirpath , mountres3 *, CLIENT *);
|
||||
#define MOUNTPROC3_DUMP 2
|
||||
extern enum clnt_stat mountproc3_dump_3(mountlist *, CLIENT *);
|
||||
#define MOUNTPROC3_UMNT 3
|
||||
extern enum clnt_stat mountproc3_umnt_3(dirpath , void *, CLIENT *);
|
||||
#define MOUNTPROC3_UMNTALL 4
|
||||
extern enum clnt_stat mountproc3_umntall_3(void *, CLIENT *);
|
||||
#define MOUNTPROC3_EXPORT 5
|
||||
extern enum clnt_stat mountproc3_export_3(exports *, CLIENT *);
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
extern bool_t xdr_fhandle3(XDR *, fhandle3*);
|
||||
extern bool_t xdr_dirpath(XDR *, dirpath*);
|
||||
extern bool_t xdr_name(XDR *, name*);
|
||||
extern bool_t xdr_exports(XDR *, exports*);
|
||||
extern bool_t xdr_groups(XDR *, groups*);
|
||||
extern bool_t xdr_mountlist(XDR *, mountlist*);
|
||||
extern bool_t xdr_mountstat3(XDR *, mountstat3*);
|
||||
extern bool_t xdr_mountres3_ok(XDR *, mountres3_ok*);
|
||||
extern bool_t xdr_mountres3(XDR *, mountres3*);
|
||||
extern bool_t xdr_mountbody(XDR *, mountbody*);
|
||||
extern bool_t xdr_groupnode(XDR *, groupnode*);
|
||||
extern bool_t xdr_exportnode(XDR *, exportnode*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_MOUNT_H_RPCGEN */
|
||||
@@ -0,0 +1,68 @@
|
||||
%/* This file is copied from RFC1813
|
||||
% * Copyright 1995 Sun Micrososystems (I assume)
|
||||
% */
|
||||
|
||||
const MNTPATHLEN = 1024; /* Maximum bytes in a path name */
|
||||
const MNTNAMLEN = 255; /* Maximum bytes in a name */
|
||||
const FHSIZE3 = 64; /* Maximum bytes in a V3 file handle */
|
||||
|
||||
typedef opaque fhandle3<FHSIZE3>;
|
||||
typedef string dirpath<MNTPATHLEN>;
|
||||
typedef string name<MNTNAMLEN>;
|
||||
|
||||
typedef struct exportnode *exports;
|
||||
typedef struct groupnode *groups;
|
||||
typedef struct mountbody *mountlist;
|
||||
|
||||
enum mountstat3 {
|
||||
MNT3_OK = 0, /* no error */
|
||||
MNT3ERR_PERM = 1, /* Not owner */
|
||||
MNT3ERR_NOENT = 2, /* No such file or directory */
|
||||
MNT3ERR_IO = 5, /* I/O error */
|
||||
MNT3ERR_ACCES = 13, /* Permission denied */
|
||||
MNT3ERR_NOTDIR = 20, /* Not a directory */
|
||||
MNT3ERR_INVAL = 22, /* Invalid argument */
|
||||
MNT3ERR_NAMETOOLONG = 63, /* Filename too long */
|
||||
MNT3ERR_NOTSUPP = 10004, /* Operation not supported */
|
||||
MNT3ERR_SERVERFAULT = 10006 /* A failure on the server */
|
||||
};
|
||||
|
||||
struct mountres3_ok {
|
||||
fhandle3 fhandle;
|
||||
int auth_flavors<>;
|
||||
};
|
||||
|
||||
union mountres3 switch (mountstat3 fhs_status) {
|
||||
case MNT3_OK:
|
||||
mountres3_ok mountinfo;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
struct mountbody {
|
||||
name ml_hostname;
|
||||
dirpath ml_directory;
|
||||
mountlist ml_next;
|
||||
};
|
||||
|
||||
struct groupnode {
|
||||
name gr_name;
|
||||
groups gr_next;
|
||||
};
|
||||
|
||||
struct exportnode {
|
||||
dirpath ex_dir;
|
||||
groups ex_groups;
|
||||
exports ex_next;
|
||||
};
|
||||
|
||||
program MOUNT_PROGRAM {
|
||||
version MOUNT_V3 {
|
||||
void MOUNTPROC3_NULL(void) = 0;
|
||||
mountres3 MOUNTPROC3_MNT(dirpath) = 1;
|
||||
mountlist MOUNTPROC3_DUMP(void) = 2;
|
||||
void MOUNTPROC3_UMNT(dirpath) = 3;
|
||||
void MOUNTPROC3_UMNTALL(void) = 4;
|
||||
exports MOUNTPROC3_EXPORT(void) = 5;
|
||||
} = 3;
|
||||
} = 100005;
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#include <string.h> /* for memset */
|
||||
#include "mount.h"
|
||||
|
||||
/* This file is copied from RFC1813
|
||||
* Copyright 1995 Sun Micrososystems (I assume)
|
||||
*/
|
||||
|
||||
typedef char* caddr_t;
|
||||
|
||||
/* Default timeout can be changed using clnt_control() */
|
||||
static struct timeval TIMEOUT = { 25, 0 };
|
||||
|
||||
enum clnt_stat
|
||||
mountproc3_null_3(void *clnt_res, CLIENT *clnt)
|
||||
{
|
||||
return (clnt_call(clnt, MOUNTPROC3_NULL,
|
||||
(xdrproc_t) xdr_void, (caddr_t) NULL,
|
||||
(xdrproc_t) xdr_void, (caddr_t) clnt_res,
|
||||
TIMEOUT));
|
||||
}
|
||||
|
||||
enum clnt_stat
|
||||
mountproc3_mnt_3(dirpath arg1, mountres3 *clnt_res, CLIENT *clnt)
|
||||
{
|
||||
return (clnt_call(clnt, MOUNTPROC3_MNT,
|
||||
(xdrproc_t) xdr_dirpath, (caddr_t) &arg1,
|
||||
(xdrproc_t) xdr_mountres3, (caddr_t) clnt_res,
|
||||
TIMEOUT));
|
||||
}
|
||||
|
||||
enum clnt_stat
|
||||
mountproc3_dump_3(mountlist *clnt_res, CLIENT *clnt)
|
||||
{
|
||||
return (clnt_call(clnt, MOUNTPROC3_DUMP,
|
||||
(xdrproc_t) xdr_void, (caddr_t) NULL,
|
||||
(xdrproc_t) xdr_mountlist, (caddr_t) clnt_res,
|
||||
TIMEOUT));
|
||||
}
|
||||
|
||||
enum clnt_stat
|
||||
mountproc3_umnt_3(dirpath arg1, void *clnt_res, CLIENT *clnt)
|
||||
{
|
||||
return (clnt_call(clnt, MOUNTPROC3_UMNT,
|
||||
(xdrproc_t) xdr_dirpath, (caddr_t) &arg1,
|
||||
(xdrproc_t) xdr_void, (caddr_t) clnt_res,
|
||||
TIMEOUT));
|
||||
}
|
||||
|
||||
enum clnt_stat
|
||||
mountproc3_umntall_3(void *clnt_res, CLIENT *clnt)
|
||||
{
|
||||
return (clnt_call(clnt, MOUNTPROC3_UMNTALL,
|
||||
(xdrproc_t) xdr_void, (caddr_t) NULL,
|
||||
(xdrproc_t) xdr_void, (caddr_t) clnt_res,
|
||||
TIMEOUT));
|
||||
}
|
||||
|
||||
enum clnt_stat
|
||||
mountproc3_export_3(exports *clnt_res, CLIENT *clnt)
|
||||
{
|
||||
return (clnt_call(clnt, MOUNTPROC3_EXPORT,
|
||||
(xdrproc_t) xdr_void, (caddr_t) NULL,
|
||||
(xdrproc_t) xdr_exports, (caddr_t) clnt_res,
|
||||
TIMEOUT));
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,104 @@
|
||||
#ifndef __AUTH_H__
|
||||
#define __AUTH_H__
|
||||
|
||||
#include <rpc/xdr.h>
|
||||
|
||||
/*
|
||||
* Status returned from authentication check
|
||||
*/
|
||||
enum auth_stat {
|
||||
AUTH_OK=0,
|
||||
/*
|
||||
* failed at remote end
|
||||
*/
|
||||
AUTH_BADCRED=1, /* bogus credentials (seal broken) */
|
||||
AUTH_REJECTEDCRED=2, /* client should begin new session */
|
||||
AUTH_BADVERF=3, /* bogus verifier (seal broken) */
|
||||
AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
|
||||
AUTH_TOOWEAK=5, /* rejected due to security reasons */
|
||||
/*
|
||||
* failed locally
|
||||
*/
|
||||
AUTH_INVALIDRESP=6, /* bogus response verifier */
|
||||
AUTH_FAILED=7 /* some unknown reason */
|
||||
};
|
||||
|
||||
union des_block {
|
||||
struct {
|
||||
uint32_t high;
|
||||
uint32_t low;
|
||||
} key;
|
||||
char c[8];
|
||||
};
|
||||
typedef union des_block des_block;
|
||||
|
||||
/*
|
||||
* Authentication info. Opaque to client.
|
||||
*/
|
||||
struct opaque_auth {
|
||||
enum_t oa_flavor; /* flavor of auth */
|
||||
char* oa_base; /* address of more auth stuff */
|
||||
unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */
|
||||
};
|
||||
|
||||
/*
|
||||
* Auth handle, interface to client side authenticators.
|
||||
*/
|
||||
typedef struct AUTH AUTH;
|
||||
struct AUTH {
|
||||
struct opaque_auth ah_cred;
|
||||
struct opaque_auth ah_verf;
|
||||
union des_block ah_key;
|
||||
struct auth_ops {
|
||||
void (*ah_nextverf) (AUTH *);
|
||||
int (*ah_marshal) (AUTH *, XDR *); /* nextverf & serialize */
|
||||
int (*ah_validate) (AUTH *, struct opaque_auth *);
|
||||
/* validate verifier */
|
||||
int (*ah_refresh) (AUTH *); /* refresh credentials */
|
||||
void (*ah_destroy) (AUTH *); /* destroy this structure */
|
||||
} *ah_ops;
|
||||
char* ah_private;
|
||||
};
|
||||
|
||||
extern struct opaque_auth _null_auth;
|
||||
|
||||
|
||||
/*
|
||||
* Authentication ops.
|
||||
* The ops and the auth handle provide the interface to the authenticators.
|
||||
*
|
||||
* AUTH *auth;
|
||||
* XDR *xdrs;
|
||||
* struct opaque_auth verf;
|
||||
*/
|
||||
#define AUTH_NEXTVERF(auth) \
|
||||
((*((auth)->ah_ops->ah_nextverf))(auth))
|
||||
#define auth_nextverf(auth) \
|
||||
((*((auth)->ah_ops->ah_nextverf))(auth))
|
||||
|
||||
#define AUTH_MARSHALL(auth, xdrs) \
|
||||
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
|
||||
#define auth_marshall(auth, xdrs) \
|
||||
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
|
||||
|
||||
#define AUTH_VALIDATE(auth, verfp) \
|
||||
((*((auth)->ah_ops->ah_validate))((auth), verfp))
|
||||
#define auth_validate(auth, verfp) \
|
||||
((*((auth)->ah_ops->ah_validate))((auth), verfp))
|
||||
|
||||
#define AUTH_REFRESH(auth) \
|
||||
((*((auth)->ah_ops->ah_refresh))(auth))
|
||||
#define auth_refresh(auth) \
|
||||
((*((auth)->ah_ops->ah_refresh))(auth))
|
||||
|
||||
#define AUTH_DESTROY(auth) \
|
||||
((*((auth)->ah_ops->ah_destroy))(auth))
|
||||
#define auth_destroy(auth) \
|
||||
((*((auth)->ah_ops->ah_destroy))(auth))
|
||||
|
||||
#define MAX_AUTH_BYTES 400
|
||||
#define MAXNETNAMELEN 255 /* maximum length of network user's name */
|
||||
|
||||
AUTH *authnone_create(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
/* @(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC */
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
#if !defined(lint) && defined(SCCSIDS)
|
||||
static char sccsid[] =
|
||||
|
||||
"@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* auth_none.c
|
||||
* Creates a client authentication handle for passing "null"
|
||||
* credentials and verifiers to remote systems.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#define MAX_MARSHEL_SIZE 20
|
||||
|
||||
static void authnone_verf(AUTH *);
|
||||
static bool_t authnone_validate(AUTH *, struct opaque_auth *);
|
||||
static bool_t authnone_refresh(AUTH *);
|
||||
static void authnone_destroy(AUTH *);
|
||||
static bool_t authnone_marshal(AUTH *client, XDR *xdrs);
|
||||
|
||||
struct opaque_auth _null_auth;
|
||||
|
||||
static struct auth_ops ops = {
|
||||
authnone_verf,
|
||||
authnone_marshal,
|
||||
authnone_validate,
|
||||
authnone_refresh,
|
||||
authnone_destroy
|
||||
};
|
||||
|
||||
static struct authnone_private {
|
||||
AUTH no_client;
|
||||
char marshalled_client[MAX_MARSHEL_SIZE];
|
||||
unsigned int mcnt;
|
||||
} *authnone_private;
|
||||
|
||||
AUTH *authnone_create()
|
||||
{
|
||||
register struct authnone_private *ap = authnone_private;
|
||||
XDR xdr_stream;
|
||||
register XDR *xdrs;
|
||||
|
||||
if (ap == 0) {
|
||||
ap = (struct authnone_private *) rt_malloc (sizeof(*ap));
|
||||
if (ap == 0) return NULL;
|
||||
memset(ap, 0, sizeof(*ap));
|
||||
authnone_private = ap;
|
||||
}
|
||||
if (!ap->mcnt) {
|
||||
ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
|
||||
ap->no_client.ah_ops = &ops;
|
||||
xdrs = &xdr_stream;
|
||||
xdrmem_create(xdrs, ap->marshalled_client,
|
||||
(unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
|
||||
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
|
||||
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
|
||||
ap->mcnt = XDR_GETPOS(xdrs);
|
||||
XDR_DESTROY(xdrs);
|
||||
}
|
||||
return (&ap->no_client);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t authnone_marshal(client, xdrs)
|
||||
AUTH *client;
|
||||
XDR *xdrs;
|
||||
{
|
||||
register struct authnone_private *ap = authnone_private;
|
||||
|
||||
if (ap == 0)
|
||||
return (0);
|
||||
return ((*xdrs->x_ops->x_putbytes) (xdrs,
|
||||
ap->marshalled_client, ap->mcnt));
|
||||
}
|
||||
|
||||
static void authnone_verf(AUTH *x)
|
||||
{
|
||||
}
|
||||
|
||||
static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
|
||||
{
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static bool_t authnone_refresh(AUTH *x)
|
||||
{
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static void authnone_destroy(AUTH *x)
|
||||
{
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,89 @@
|
||||
/* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
#if !defined(lint) && defined(SCCSIDS)
|
||||
static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) 1987, Sun Microsystems, Inc.
|
||||
*/
|
||||
#include <rpc/rpc.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Generic client creation: takes (hostname, program-number, protocol) and
|
||||
* returns client handle. Default options are set, which the user can
|
||||
* change using the rpc equivalent of ioctl()'s.
|
||||
*/
|
||||
CLIENT *clnt_create (const char *hostname, const unsigned long prog,
|
||||
const unsigned long vers, const char *proto)
|
||||
{
|
||||
int sock;
|
||||
struct hostent *h;
|
||||
struct sockaddr_in sin;
|
||||
struct timeval tv;
|
||||
CLIENT *client;
|
||||
|
||||
h = gethostbyname(hostname);
|
||||
if (h == NULL) {
|
||||
rt_kprintf("unknown host\n");
|
||||
return (NULL);
|
||||
}
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
rt_kprintf("unknow inet\n");
|
||||
return (NULL);
|
||||
}
|
||||
memset((char*)&sin,0,sizeof(sin));
|
||||
sin.sin_family = h->h_addrtype;
|
||||
sin.sin_port = 0;
|
||||
memmove((char *) &sin.sin_addr, h->h_addr, h->h_length);
|
||||
|
||||
sock = -1;
|
||||
if (strcmp(proto, "udp") == 0)
|
||||
{
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
client = clntudp_create(&sin, prog, vers, tv, &sock);
|
||||
if (client == NULL) return NULL;
|
||||
tv.tv_sec = 25;
|
||||
clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("unknow protocol\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (client);
|
||||
}
|
||||
|
||||
void clnt_perror(CLIENT *rpch, const char *s)
|
||||
{
|
||||
rt_kprintf("rpc client error:%s\n", s);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,60 @@
|
||||
#include "pmap.h"
|
||||
#include "clnt.h"
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
static struct timeval timeout = { 5, 0 };
|
||||
static struct timeval tottimeout = { 60, 0 };
|
||||
|
||||
|
||||
bool_t xdr_pmap(xdrs, regs)
|
||||
XDR *xdrs;
|
||||
struct pmap *regs;
|
||||
{
|
||||
if (xdr_u_long(xdrs, ®s->pm_prog) &&
|
||||
xdr_u_long(xdrs, ®s->pm_vers) &&
|
||||
xdr_u_long(xdrs, ®s->pm_prot))
|
||||
return (xdr_u_long(xdrs, ®s->pm_port));
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the mapped port for program,version.
|
||||
* Calls the pmap service remotely to do the lookup.
|
||||
* Returns 0 if no map exists.
|
||||
*/
|
||||
unsigned short pmap_getport(address, program, version, protocol)
|
||||
struct sockaddr_in *address;
|
||||
unsigned long program;
|
||||
unsigned long version;
|
||||
unsigned int protocol;
|
||||
{
|
||||
unsigned short port = 0;
|
||||
int socket = -1;
|
||||
register CLIENT *client;
|
||||
struct pmap parms;
|
||||
|
||||
address->sin_port = htons((unsigned short)PMAPPORT);
|
||||
if (protocol == IPPROTO_UDP)
|
||||
client = clntudp_bufcreate(address, PMAPPROG, PMAPVERS, timeout,
|
||||
&socket, RPCSMALLMSGSIZE,
|
||||
RPCSMALLMSGSIZE);
|
||||
|
||||
if (client != (CLIENT *) NULL)
|
||||
{
|
||||
parms.pm_prog = program;
|
||||
parms.pm_vers = version;
|
||||
parms.pm_prot = protocol;
|
||||
parms.pm_port = 0; /* not needed or used */
|
||||
if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (char*)&parms,
|
||||
(xdrproc_t)xdr_u_short, (char*)&port, tottimeout) != RPC_SUCCESS)
|
||||
{
|
||||
rt_kprintf("pmap failure\n");
|
||||
}
|
||||
CLNT_DESTROY(client);
|
||||
}
|
||||
|
||||
(void) lwip_close(socket);
|
||||
address->sin_port = 0;
|
||||
|
||||
return (port);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef __RPC_PMAP_PROT_H__
|
||||
#define __RPC_PMAP_PROT_H__
|
||||
|
||||
#include <rpc/xdr.h>
|
||||
|
||||
/* The following procedures are supported by the protocol:
|
||||
*
|
||||
* PMAPPROC_NULL() returns ()
|
||||
* takes nothing, returns nothing
|
||||
*
|
||||
* PMAPPROC_SET(struct pmap) returns (bool_t)
|
||||
* TRUE is success, FALSE is failure. Registers the tuple
|
||||
* [prog, vers, prot, port].
|
||||
*
|
||||
* PMAPPROC_UNSET(struct pmap) returns (bool_t)
|
||||
* TRUE is success, FALSE is failure. Un-registers pair
|
||||
* [prog, vers]. prot and port are ignored.
|
||||
*
|
||||
* PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
|
||||
* 0 is failure. Otherwise returns the port number where the pair
|
||||
* [prog, vers] is registered. It may lie!
|
||||
*
|
||||
* PMAPPROC_DUMP() RETURNS (struct pmaplist *)
|
||||
*
|
||||
* PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
|
||||
* RETURNS (port, string<>);
|
||||
* usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
|
||||
* Calls the procedure on the local machine. If it is not registered,
|
||||
* this procedure is quite; ie it does not return error information!!!
|
||||
* This procedure only is supported on rpc/udp and calls via
|
||||
* rpc/udp. This routine only passes null authentication parameters.
|
||||
* This file has no interface to xdr routines for PMAPPROC_CALLIT.
|
||||
*
|
||||
* The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
|
||||
*/
|
||||
|
||||
#define PMAPPORT ((unsigned short)111)
|
||||
#define PMAPPROG ((unsigned long)100000)
|
||||
#define PMAPVERS ((unsigned long)2)
|
||||
#define PMAPVERS_PROTO ((unsigned long)2)
|
||||
#define PMAPVERS_ORIG ((unsigned long)1)
|
||||
#define PMAPPROC_NULL ((unsigned long)0)
|
||||
#define PMAPPROC_SET ((unsigned long)1)
|
||||
#define PMAPPROC_UNSET ((unsigned long)2)
|
||||
#define PMAPPROC_GETPORT ((unsigned long)3)
|
||||
#define PMAPPROC_DUMP ((unsigned long)4)
|
||||
#define PMAPPROC_CALLIT ((unsigned long)5)
|
||||
|
||||
struct pmap {
|
||||
long unsigned pm_prog;
|
||||
long unsigned pm_vers;
|
||||
long unsigned pm_prot;
|
||||
long unsigned pm_port;
|
||||
};
|
||||
|
||||
extern bool_t xdr_pmap (XDR *__xdrs, struct pmap *__regs);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
/* @(#)rpc.h 2.3 88/08/10 4.0 RPCSRC; from 1.9 88/02/08 SMI */
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
|
||||
/*
|
||||
* rpc.h, Just includes the billions of rpc header files necessary to
|
||||
* do remote procedure calling.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _RPC_RPC_H
|
||||
#define _RPC_RPC_H 1
|
||||
|
||||
#include <rpc/types.h> /* some typedefs */
|
||||
|
||||
/* external data representation interfaces */
|
||||
#include <rpc/xdr.h> /* generic (de)serializer */
|
||||
|
||||
#include <rpc/auth.h>
|
||||
|
||||
/* Client side (mostly) remote procedure call */
|
||||
#include <rpc/clnt.h> /* generic rpc stuff */
|
||||
|
||||
/* semi-private protocol headers */
|
||||
#include <rpc/rpc_msg.h> /* protocol for rpc messages */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,195 @@
|
||||
/* @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC */
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
/* @(#)rpc_msg.h 1.7 86/07/16 SMI */
|
||||
|
||||
#ifndef _RPC_MSG_H
|
||||
#define _RPC_MSG_H 1
|
||||
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/clnt.h>
|
||||
|
||||
/*
|
||||
* rpc_msg.h
|
||||
* rpc message definition
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#define RPC_MSG_VERSION ((unsigned long) 2)
|
||||
#define RPC_SERVICE_PORT ((unsigned short) 2048)
|
||||
|
||||
/*
|
||||
* Bottom up definition of an rpc message.
|
||||
* NOTE: call and reply use the same overall struct but
|
||||
* different parts of unions within it.
|
||||
*/
|
||||
|
||||
enum msg_type {
|
||||
CALL=0,
|
||||
REPLY=1
|
||||
};
|
||||
|
||||
enum reply_stat {
|
||||
MSG_ACCEPTED=0,
|
||||
MSG_DENIED=1
|
||||
};
|
||||
|
||||
enum accept_stat {
|
||||
SUCCESS=0,
|
||||
PROG_UNAVAIL=1,
|
||||
PROG_MISMATCH=2,
|
||||
PROC_UNAVAIL=3,
|
||||
GARBAGE_ARGS=4,
|
||||
SYSTEM_ERR=5
|
||||
};
|
||||
|
||||
enum reject_stat {
|
||||
RPC_MISMATCH=0,
|
||||
AUTH_ERROR=1
|
||||
};
|
||||
|
||||
/*
|
||||
* Reply part of an rpc exchange
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reply to an rpc request that was accepted by the server.
|
||||
* Note: there could be an error even though the request was
|
||||
* accepted.
|
||||
*/
|
||||
struct accepted_reply {
|
||||
struct opaque_auth ar_verf;
|
||||
int ar_stat;
|
||||
union {
|
||||
struct {
|
||||
unsigned long low;
|
||||
unsigned long high;
|
||||
} AR_versions;
|
||||
struct {
|
||||
char* where;
|
||||
xdrproc_t proc;
|
||||
} AR_results;
|
||||
/* and many other null cases */
|
||||
} ru;
|
||||
#define ar_results ru.AR_results
|
||||
#define ar_vers ru.AR_versions
|
||||
};
|
||||
|
||||
/*
|
||||
* Reply to an rpc request that was rejected by the server.
|
||||
*/
|
||||
struct rejected_reply {
|
||||
int rj_stat;
|
||||
union {
|
||||
struct {
|
||||
unsigned long low;
|
||||
unsigned long high;
|
||||
} RJ_versions;
|
||||
int RJ_why; /* why authentication did not work */
|
||||
} ru;
|
||||
#define rj_vers ru.RJ_versions
|
||||
#define rj_why ru.RJ_why
|
||||
};
|
||||
|
||||
/*
|
||||
* Body of a reply to an rpc request.
|
||||
*/
|
||||
struct reply_body {
|
||||
int rp_stat;
|
||||
union {
|
||||
struct accepted_reply RP_ar;
|
||||
struct rejected_reply RP_dr;
|
||||
} ru;
|
||||
#define rp_acpt ru.RP_ar
|
||||
#define rp_rjct ru.RP_dr
|
||||
};
|
||||
|
||||
/*
|
||||
* Body of an rpc request call.
|
||||
*/
|
||||
struct call_body {
|
||||
unsigned long cb_rpcvers; /* must be equal to two */
|
||||
unsigned long cb_prog;
|
||||
unsigned long cb_vers;
|
||||
unsigned long cb_proc;
|
||||
struct opaque_auth cb_cred;
|
||||
struct opaque_auth cb_verf; /* protocol specific - provided by client */
|
||||
};
|
||||
|
||||
/*
|
||||
* The rpc message
|
||||
*/
|
||||
struct rpc_msg {
|
||||
unsigned long rm_xid;
|
||||
int rm_direction;
|
||||
union {
|
||||
struct call_body RM_cmb;
|
||||
struct reply_body RM_rmb;
|
||||
} ru;
|
||||
#define rm_call ru.RM_cmb
|
||||
#define rm_reply ru.RM_rmb
|
||||
};
|
||||
#define acpted_rply ru.RM_rmb.ru.RP_ar
|
||||
#define rjcted_rply ru.RM_rmb.ru.RP_dr
|
||||
|
||||
|
||||
/*
|
||||
* XDR routine to handle a rpc message.
|
||||
* xdr_callmsg(xdrs, cmsg)
|
||||
* XDR *xdrs;
|
||||
* struct rpc_msg *cmsg;
|
||||
*/
|
||||
extern bool_t xdr_callmsg (XDR *__xdrs, struct rpc_msg *__cmsg);
|
||||
|
||||
/*
|
||||
* XDR routine to pre-serialize the static part of a rpc message.
|
||||
* xdr_callhdr(xdrs, cmsg)
|
||||
* XDR *xdrs;
|
||||
* struct rpc_msg *cmsg;
|
||||
*/
|
||||
extern bool_t xdr_callhdr (XDR *__xdrs, struct rpc_msg *__cmsg);
|
||||
|
||||
/*
|
||||
* XDR routine to handle a rpc reply.
|
||||
* xdr_replymsg(xdrs, rmsg)
|
||||
* XDR *xdrs;
|
||||
* struct rpc_msg *rmsg;
|
||||
*/
|
||||
extern bool_t xdr_replymsg (XDR *__xdrs, struct rpc_msg *__rmsg);
|
||||
|
||||
/*
|
||||
* Fills in the error part of a reply message.
|
||||
* _seterr_reply(msg, error)
|
||||
* struct rpc_msg *msg;
|
||||
* struct rpc_err *error;
|
||||
*/
|
||||
extern void _seterr_reply (struct rpc_msg *__msg, struct rpc_err *__error);
|
||||
|
||||
#endif /* rpc/rpc_msg.h */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
/* fixincludes should not add extern "C" to this file */
|
||||
/*
|
||||
* Rpc additions to <sys/types.h>
|
||||
*/
|
||||
#ifndef _RPC_TYPES_H
|
||||
#define _RPC_TYPES_H 1
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <lwip/netdb.h>
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
#include <string.h>
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
typedef rt_int32_t ssize_t;
|
||||
|
||||
typedef rt_int8_t int8_t;
|
||||
typedef rt_uint8_t uint8_t;
|
||||
typedef rt_int16_t int16_t;
|
||||
typedef rt_uint16_t uint16_t;
|
||||
typedef rt_int32_t int32_t;
|
||||
typedef rt_uint32_t uint32_t;
|
||||
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
typedef int bool_t;
|
||||
typedef int enum_t;
|
||||
|
||||
typedef unsigned long mode_t;
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
/* This needs to be changed to uint32_t in the future */
|
||||
typedef unsigned long rpcprog_t;
|
||||
typedef unsigned long rpcvers_t;
|
||||
typedef unsigned long rpcproc_t;
|
||||
typedef unsigned long rpcprot_t;
|
||||
typedef unsigned long rpcport_t;
|
||||
|
||||
#define __dontcare__ -1
|
||||
|
||||
#ifndef FALSE
|
||||
# define FALSE (0)
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1)
|
||||
#endif
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 64
|
||||
#endif
|
||||
|
||||
#endif /* rpc/types.h */
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,166 @@
|
||||
/* @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC */
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
#if !defined(lint) && defined(SCCSIDS)
|
||||
static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* xdr_mem.h, XDR implementation using memory buffers.
|
||||
*
|
||||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*
|
||||
* If you have some data to be interpreted as external data representation
|
||||
* or to be converted to external data representation in a memory buffer,
|
||||
* then this is the package for you.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
static bool_t xdrmem_getlong (XDR *, long *);
|
||||
static bool_t xdrmem_putlong (XDR *, const long *);
|
||||
static bool_t xdrmem_getbytes (XDR *, char *, unsigned int);
|
||||
static bool_t xdrmem_putbytes (XDR *, const char *, unsigned int);
|
||||
static unsigned int xdrmem_getpos (const XDR *);
|
||||
static bool_t xdrmem_setpos (XDR *, unsigned int);
|
||||
static int32_t *xdrmem_inline (XDR *, unsigned int);
|
||||
static void xdrmem_destroy (XDR *);
|
||||
|
||||
static struct xdr_ops xdrmem_ops = {
|
||||
xdrmem_getlong,
|
||||
xdrmem_putlong,
|
||||
xdrmem_getbytes,
|
||||
xdrmem_putbytes,
|
||||
xdrmem_getpos,
|
||||
xdrmem_setpos,
|
||||
xdrmem_inline,
|
||||
xdrmem_destroy,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The procedure xdrmem_create initializes a stream descriptor for a
|
||||
* memory buffer.
|
||||
*/
|
||||
void
|
||||
xdrmem_create (XDR *xdrs, const char* addr, unsigned int size, enum xdr_op op)
|
||||
{
|
||||
xdrs->x_op = op;
|
||||
xdrs->x_ops = &xdrmem_ops;
|
||||
xdrs->x_private = xdrs->x_base = (char*)addr;
|
||||
xdrs->x_handy = size;
|
||||
}
|
||||
|
||||
static void
|
||||
xdrmem_destroy (XDR *xdrs)
|
||||
{
|
||||
}
|
||||
|
||||
static bool_t
|
||||
xdrmem_getlong (XDR *xdrs, long *lp)
|
||||
{
|
||||
if (xdrs->x_handy < 4) return FALSE;
|
||||
xdrs->x_handy -= 4;
|
||||
|
||||
*lp = (int32_t) ntohl((*((int32_t *) (xdrs->x_private))));
|
||||
xdrs->x_private += 4;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
xdrmem_putlong (XDR *xdrs, const long *lp)
|
||||
{
|
||||
if (xdrs->x_handy < 4) return FALSE;
|
||||
xdrs->x_handy -= 4;
|
||||
|
||||
*(int32_t *) xdrs->x_private = htonl(*lp);
|
||||
xdrs->x_private += 4;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
xdrmem_getbytes (XDR *xdrs, char *addr, unsigned int len)
|
||||
{
|
||||
if (xdrs->x_handy < len) return FALSE;
|
||||
xdrs->x_handy -= len;
|
||||
memmove(addr, xdrs->x_private, len);
|
||||
xdrs->x_private += len;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
xdrmem_putbytes (XDR *xdrs, const char *addr, unsigned int len)
|
||||
{
|
||||
if (xdrs->x_handy < len) return FALSE;
|
||||
xdrs->x_handy -= len;
|
||||
memmove(xdrs->x_private, addr, len);
|
||||
xdrs->x_private += len;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static unsigned int xdrmem_getpos (const XDR *xdrs)
|
||||
{
|
||||
return ((unsigned long) xdrs->x_private - (unsigned long) xdrs->x_base);
|
||||
}
|
||||
|
||||
static bool_t xdrmem_setpos(xdrs, pos)
|
||||
register XDR *xdrs;
|
||||
unsigned int pos;
|
||||
{
|
||||
register char* newaddr = xdrs->x_base + pos;
|
||||
register char* lastaddr = xdrs->x_private + xdrs->x_handy;
|
||||
|
||||
if ((long) newaddr > (long) lastaddr
|
||||
|| (UINT_MAX < LONG_MAX
|
||||
&& (long) UINT_MAX < (long) lastaddr - (long) newaddr))
|
||||
return (FALSE);
|
||||
xdrs->x_private = newaddr;
|
||||
xdrs->x_handy = (long) lastaddr - (long) newaddr;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static int32_t *
|
||||
xdrmem_inline (XDR *xdrs, unsigned int len)
|
||||
{
|
||||
int32_t *buf = 0;
|
||||
|
||||
if (xdrs->x_handy >= len) {
|
||||
xdrs->x_handy -= len;
|
||||
buf = (int32_t *) xdrs->x_private;
|
||||
xdrs->x_private += len;
|
||||
}
|
||||
return (buf);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user