1 / 6

/* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255;

/* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255; enum filekind { TEXT=0, DATA=1, EXEC=2 }; union filetype switch (filekind kind) { case TEXT: void; case DATA: string creator<MAXNAMELEN>;

Download Presentation

/* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. /* Descripción XDR */ const MAXUSERNAME=32; const MAXFILELEN=65535; const MAXNAMELEN=255; enum filekind { TEXT=0, DATA=1, EXEC=2 }; union filetype switch (filekind kind) { case TEXT: void; case DATA: string creator<MAXNAMELEN>; case EXEC: string interpretor<MAXNAMELEN>; }; struct file { string filename<MAXNAMELEN>; filetype type; string owner<MAXUSERNAME>; opaque data <MAXFILELEN>; }; fileXDR.x

  2. fileXDR.h struct filetype { filekind kind; union { char *creator; char *interpretor; } filetype_u; }; typedef struct filetype filetype; bool_t xdr_filetype(); struct file { char *filename; filetype type; char *owner; struct { u_int data_len; char *data_val; } data; }; typedef struct file file; bool_t xdr_file(); #include <rpc/types.h> #define MAXUSERNAME 32 #define MAXFILELEN 65535 #define MAXNAMELEN 255 enum filekind { TEXT = 0, DATA = 1, EXEC = 2, }; typedef enum filekind filekind; bool_t xdr_filekind();

  3. fileXDR_xdr.c (I) #include <rpc/rpc.h> #include "fileXDR.h" bool_t xdr_filekind(xdrs, objp) XDR *xdrs; filekind *objp; { if (!xdr_enum(xdrs, (enum_t *)objp)) { return (FALSE); } return (TRUE); }

  4. bool_t xdr_filetype(xdrs, objp) XDR *xdrs; filetype *objp; { if (!xdr_filekind(xdrs, &objp->kind)) { return (FALSE); } switch (objp->kind) { case TEXT: break; case DATA: if (!xdr_string(xdrs, &objp->filetype_u.creator, MAXNAMELEN)) { return (FALSE); } break; case EXEC: if (!xdr_string(xdrs, &objp->filetype_u.interpretor, MAXNAMELEN)){ return (FALSE); } break; default: return (FALSE); } return (TRUE); } fileXDR_xdr.c (II)

  5. fileXDR_xdr.c (III) bool_t xdr_file(xdrs, objp) XDR *xdrs; file *objp; { if (!xdr_string(xdrs, &objp->filename, MAXNAMELEN)) { return (FALSE); } if (!xdr_filetype(xdrs, &objp->type)) { return (FALSE); } if (!xdr_string(xdrs, &objp->owner, MAXUSERNAME)) { return (FALSE); } if (!xdr_bytes(xdrs, (char **)&objp->data.data_val, (u_int *)&objp->data.data_len, MAXFILELEN)) { return (FALSE); } return (TRUE); }

  6. Escribir.c #include <stdio.h> #include <rpc/rpc.h> #include "fileXDR.h" int main() { XDR xdr_handle; FILE *fp; file fichero; char data[5]; data[0]='a'; data[1]='b'; data[2]='c'; data[3]='d'; data[4]='e'; if((fp=fopen("salida","w"))!=NULL) { xdrstdio_create(&xdr_handle,fp,XDR_ENCODE); fichero.filename="nombrefichero"; fichero.type.kind=TEXT; fichero.owner="nombrepropietario"; fichero.data.data_len=5; fichero.data.data_val=data; xdr_file(&xdr_handle,&fichero); xdr_destroy(&xdr_handle); fclose(fp); } }

More Related