lcrzo_record(3)

NAME
lcrzo_record - lcrzo library : file recording

CONTENTS
/*    Laurent Constantin's network library (lcrzo)
                 lcrzo_record module
  Functions herein allow to save and read data from files.
*/
/*-------------------------------------------------------------*/
/* definition of a lcrzo_record. You should not use its
   fields directly. */
typedef struct
{ LCRZOFILE *pf;
  lcrzo_int16 opentype;
  lcrzo_int32 justbeforeposition;
  lcrzo_uint32 row;
  lcrzo_uint32 column;
} lcrzo_record;
/*-------------------------------------------------------------*/
/* a record can be open in read/write/append mode */
#define LCRZO_RECORD_OPEN_READ   1
#define LCRZO_RECORD_OPEN_WRITE  2
#define LCRZO_RECORD_OPEN_APPEND 3
/*-------------------------------------------------------------*/
/* Name : lcrzo_record_open
   Description :
     Open a lcrzo_record.
   Input parameter(s) :
     filepath : path for the file for this record
                For example "/home/user/rec1.dat".
		Symlinks are forbidden
     openingtype : opening type (LCRZO_RECORD_OPEN_READ,
                   WRITE, APPEND)
   Input/output parameter(s) :
   Output parameter(s) :
     *precord : lcrzo_record opened
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_open(lcrzo_record *precord,
		      lcrzo_conststring filepath,
		      lcrzo_int16 openingtype);
/* Name : lcrzo_record_close
   Description :
     Close a lcrzo_record.
   Input parameter(s) :
   Input/output parameter(s) :
     *precord : lcrzo_record to close
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_close(lcrzo_record *precord);
/*-------------------------------------------------------------*/
/************************************************************
 * Note about a record :                                    *
 * A record is a file where we can save and read data.      *
 *                                                          *
 * Actually, we can only read data if it was saved in       *
 * hexadecimal or mixed form (so be careful when choosing   *
 * a lcrzo_printtype or lcrzo_printprofile for saving).     *
 ************************************************************/
/* Name : lcrzo_printtype_init_stdin_record
   Description :
     Ask user to choose a lcrzo_printtype.
     The choices contains only printtypes which can be read
     be a record.
   Input parameter(s) :
     message : message to print before
     defaultprinttype : default lcrzo_printtype to use if
                        user enters nothing
   Input/output parameter(s) :
   Output parameter(s) :
     *pprinttype : lcrzo_printype chosen
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_printtype_init_stdin_record(lcrzo_conststring message,
				 lcrzo_printtype defaultprinttype,
				 lcrzo_printtype *pprinttype);
/* Name : lcrzo_printprofile_init_stdin_record
   Description :
     Ask user to choose a lcrzo_printprofile
     The choices contains only printprofiles which can be read
     be a record.
   Input parameter(s) :
     message : message to print before
     defaultprintprofile : default lcrzo_printprofile to use if
                        user enters nothing
   Input/output parameter(s) :
   Output parameter(s) :
     *pprintprofile : lcrzo_printype chosen
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_printprofile_init_stdin_record(lcrzo_conststring message,
				    lcrzo_printprofile defaultprintprofile,
				    lcrzo_printprofile *pprintprofile);
/*-------------------------------------------------------------*/
/* Name : lcrzo_record_write_data
   Description :
     Save data in a record.
   Input parameter(s) :
     data : data to save
     datasize : size of data
     printtype : lcrzo_printtype to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_data(lcrzo_record *precord,
			    lcrzo_constdata data,
			    lcrzo_int32 datasize,
			    lcrzo_printtype printtype);
/*-------------------------------------------------------------*/
/* Name : lcrzo_record_write_eth
   Description :
     Save an Ethernet packet in a record.
   Input parameter(s) :
     data : data to print
     datasize : size of data
     printprofile : lcrzo_printprofile to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_eth(lcrzo_record *precord,
			   lcrzo_constdata data,
			   lcrzo_int32 datasize,
			   lcrzo_printprofile printprofile);
/* Name : lcrzo_record_write_ip
   Description :
     Save an IP packet in a record.
   Input parameter(s) :
     data : data to print
     datasize : size of data
     printprofile : lcrzo_printprofile to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_ip(lcrzo_record *precord,
			  lcrzo_constdata data,
			  lcrzo_int32 datasize,
			  lcrzo_printprofile printprofile);
/* Name : lcrzo_record_write_udp
   Description :
     Save an UDP packet in a record.
   Input parameter(s) :
     data : data to print
     datasize : size of data
     printprofile : lcrzo_printprofile to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_udp(lcrzo_record *precord,
			   lcrzo_constdata data,
			   lcrzo_int32 datasize,
			   lcrzo_printprofile printprofile);
/* Name : lcrzo_record_write_tcp
   Description :
     Save an TCP packet in a record.
   Input parameter(s) :
     data : data to print
     datasize : size of data
     printprofile : lcrzo_printprofile to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_tcp(lcrzo_record *precord,
			   lcrzo_constdata data,
			   lcrzo_int32 datasize,
			   lcrzo_printprofile printprofile);
/* Name : lcrzo_record_write_icmp
   Description :
     Save an ICMP packet in a record.
   Input parameter(s) :
     data : data to print
     datasize : size of data
     printprofile : lcrzo_printprofile to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_icmp(lcrzo_record *precord,
			    lcrzo_constdata data,
			    lcrzo_int32 datasize,
			    lcrzo_printprofile printprofile);
/* Name : lcrzo_record_write_arp
   Description :
     Save an ARP packet in a record.
   Input parameter(s) :
     data : data to print
     datasize : size of data
     printprofile : lcrzo_printprofile to use
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_write_arp(lcrzo_record *precord,
			   lcrzo_constdata data,
			   lcrzo_int32 datasize,
			   lcrzo_printprofile printprofile);
/*-------------------------------------------------------------*/
/* Name : lcrzo_record_count
   Description :
     Count the number of items in a record
   Input parameter(s) :
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
     *pcount : number of items
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_count(lcrzo_record *precord,
		       lcrzo_int32 *pcount);
/**********************************************
 * Note about positions :                     *
 * Warning : 0 is an invalid value            *
 * Here are possible values for a position :  *
 *  +1 : first item                           *
 *  +2 : second item                          *
 *  ...                                       *
 * Moreover, we can count from the end :      *
 *  -1 : last item                            *
 *  -2 : last but one item                    *
 *  ...                                       *
 **********************************************/
/* Name : lcrzo_record_valuem_pos
   Description :
     Get an item in a record
   Input parameter(s) :
     pos : position of the wanted item (cf. the above frame to
           know possible values)
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
     *pdataout : pointer which will be malloced (so, the
                 memory will have to be freed by the
                 user with 'free(*pdataout)').
                 The allocated memory will be set with the
		 item number 'pos'
     *pdataoutsize : reached size of *pdataout
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_valuem_pos(lcrzo_record *precord,
			    lcrzo_int32 pos,
			    lcrzo_data *pdataout,
			    lcrzo_int32 *pdataoutsize);
/* Name : lcrzo_record_valuem_first
   Description :
     Get the first item of a record
   Input parameter(s) :
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
     *pdataout : pointer which will be malloced (so, the
                 memory will have to be freed by the
                 user with 'free(*pdataout)').
                 The allocated memory will be set with the
		 first item
     *pdataoutsize : reached size of *pdataout
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_valuem_first(lcrzo_record *precord,
			      lcrzo_data *pdataout,
			      lcrzo_int32 *pdataoutsize);
/* Name : lcrzo_record_valuem_last
   Description :
     Get the last item of a record
   Input parameter(s) :
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
     *pdataout : pointer which will be malloced (so, the
                 memory will have to be freed by the
                 user with 'free(*pdataout)').
                 The allocated memory will be set with the
		 last item
     *pdataoutsize : reached size of *pdataout
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_valuem_last(lcrzo_record *precord,
			     lcrzo_data *pdataout,
			     lcrzo_int32 *pdataoutsize);
/* Name : lcrzo_record_loop_range
   Description :
     Call a function for each item in a
     given position range.
   Input parameter(s) :
     startpos : start position for the loop (cf. the above frame to
                know possible values)
     endpos : end position for the loop (cf. the above frame to
              know possible values)
     pfunc : memory address of the function which will be called
             for each item in the range [startpos->endpos].
             For each call, the first/second parameter
	     ('data','datasize') will be set with the item, and
	     the third parameter
             ('pinfos') will be set with the optional parameter below.
     pinfos : optional parameter (can be NULL) which will be
              used as the second parameter for *pfunc. This may be
              used to send information to *pfunc.
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_loop_range(lcrzo_record *precord,
			    lcrzo_int32 startpos,
			    lcrzo_int32 endpos,
			    int (*pfunc)(void *data,
					 lcrzo_int32 datasize,
					 void *pinfos),
			    void *pinfos);
/* Name : lcrzo_record_loop_all
   Description :
     Call a function for all items.
   Input parameter(s) :
     pfunc : memory address of the function which will be called
             for each item.
             For each call, the first/second parameter
	     ('data','datasize') will be set with the item, and
	     the third parameter
             ('pinfos') will be set with the optional parameter below.
     pinfos : optional parameter (can be NULL) which will be
              used as the second parameter for *pfunc. This may be
              used to send information to *pfunc.
   Input/output parameter(s) :
     *precord : lcrzo_record to use
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_loop_all(lcrzo_record *precord,
			  int (*pfunc)(void *data,
				       lcrzo_int32 datasize,
				       void *pinfos),
			  void *pinfos);
/*-------------------------------------------------------------*/
/* Name : lcrzo_record_recfile_init_pcapfile
   Description :
     Convert a pcapfile (for example generated by tcpdump)
     to a lcrzo_record file.
   Input parameter(s) :
     pcapfile : pcap input file
     recfile : generated record file
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_recfile_init_pcapfile(lcrzo_conststring pcapfile,
				       lcrzo_conststring recfile);
/* Name : lcrzo_record_pcapfile_init_recfile
   Description :
     Convert a lcrzo_record file to a pcapfile.
   Input parameter(s) :
     recfile : input record file
     pcapfile : pcap output file
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_record_pcapfile_init_recfile(lcrzo_conststring recfile,
				       lcrzo_conststring pcapfile);

SEE ALSO
lcrzo(3), lcrzo_types(3), lcrzo_data(3), lcrzo_string(3), lcrzo_time(3), lcrzo_file(3), lcrzo_address(3), lcrzo_device(3), lcrzo_list(3), lcrzo_process(3), lcrzo_ipc(3), lcrzo_header(3), lcrzo_ipopt(3), lcrzo_tcpopt(3), lcrzo_packet(3), lcrzo_icmp(3), lcrzo_print(3), lcrzo_record(3), lcrzo_conf(3), lcrzo_spoof(3), lcrzo_sniff(3), lcrzo_sock(3), lcrzo_wait(3), lcrzo_global(3), lcrzo_error(3) lcrzo_misc(3), lcrzo_obso(3),