iPXE
oncrpc_iob.h
Go to the documentation of this file.
00001 #ifndef _IPXE_ONCRPC_IOB_H
00002 #define _IPXE_ONCRPC_IOB_H
00003 
00004 #include <stdint.h>
00005 #include <string.h>
00006 #include <ipxe/iobuf.h>
00007 #include <ipxe/refcnt.h>
00008 #include <ipxe/oncrpc.h>
00009 
00010 /** @file
00011  *
00012  * SUN ONC RPC protocol.
00013  *
00014  */
00015 
00016 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00017 
00018 /**
00019  * Add a string to the end of an I/O buffer
00020  *
00021  * @v io_buf            I/O buffer
00022  * @v val               String
00023  * @ret size            Size of the data written
00024  */
00025 #define oncrpc_iob_add_string( buf, str ) \
00026 ( { \
00027         const char * _str = (str); \
00028         oncrpc_iob_add_array ( (buf), strlen ( _str ), _str ); \
00029 } )
00030 
00031 /**
00032  * Get a 32 bits integer from the beginning of an I/O buffer
00033  *
00034  * @v buf               I/O buffer
00035  * @ret int             Integer
00036  */
00037 
00038 #define oncrpc_iob_get_int( buf ) \
00039 ( { \
00040         uint32_t *_val; \
00041         _val = (buf)->data; \
00042         iob_pull ( (buf), sizeof ( uint32_t ) ); \
00043         ntohl ( *_val ); \
00044 } )
00045 
00046 /**
00047  * Get a 64 bits integer from the beginning of an I/O buffer
00048  *
00049  * @v buf               I/O buffer
00050  * @ret int             Integer
00051  */
00052 #define oncrpc_iob_get_int64( buf ) \
00053 ( { \
00054         uint64_t *_val; \
00055         _val = (buf)->data; \
00056         iob_pull ( (buf), sizeof ( uint64_t ) ); \
00057         ntohll ( *_val ); \
00058 } )
00059 
00060 
00061 size_t oncrpc_iob_add_fields ( struct io_buffer *io_buf,
00062                                const struct oncrpc_field fields[] );
00063 
00064 size_t oncrpc_iob_add_array ( struct io_buffer *io_buf, size_t length,
00065                               const void *data );
00066 
00067 size_t oncrpc_iob_add_intarray ( struct io_buffer *io_buf, size_t length,
00068                                  const uint32_t *array );
00069 
00070 size_t oncrpc_iob_add_cred ( struct io_buffer *io_buf,
00071                              const struct oncrpc_cred *cred );
00072 
00073 size_t oncrpc_iob_get_cred ( struct io_buffer *io_buf,
00074                              struct oncrpc_cred *cred );
00075 
00076 /**
00077  * Add a 32 bits integer to the end of an I/O buffer
00078  *
00079  * @v io_buf            I/O buffer
00080  * @v val               Integer
00081  * @ret size            Size of the data written
00082  */
00083 static inline size_t oncrpc_iob_add_int ( struct io_buffer *io_buf,
00084                                           uint32_t val ) {
00085         * ( uint32_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonl ( val );
00086         return ( sizeof ( val) );
00087 }
00088 
00089 /**
00090  * Add a 64 bits integer to the end of an I/O buffer
00091  *
00092  * @v io_buf            I/O buffer
00093  * @v val               Integer
00094  * @ret size            Size of the data written
00095  */
00096 static inline size_t oncrpc_iob_add_int64 ( struct io_buffer *io_buf,
00097                                             uint64_t val ) {
00098         * ( uint64_t * ) iob_put ( io_buf, sizeof ( val ) ) = htonll ( val );
00099         return ( sizeof ( val) );
00100 }
00101 
00102 #endif /* _IPXE_ONCRPC_IOB_H */