Install
=======
First of all, you need to download the last (>=2.0.0) release of 
Tstat from its official site:

    http://tstat.polito.it/

Unpack the tarball somewhere and enter into the tool's directory.
The most important directories are:
- tstat:          source code for Tstat tool
- libtstat:       autotools files for building Tstat as a shared library
- libtstat-demo:  simple example on how to use libtstat API

Looking inside the
and type:
    ./configure --enable-libtstat   # enable build of the shared library
    make                            # build tstat, libtstat and libtstat-demo
    # as root...
    make install                    # install tstat, libtstat and libtstat.pc

Link to libtstat
================
Libtstat, as Tstat, need libm, and libpthread.
Libpcap is also needed (because IN THE CURRENT VERSION the libpcap support 
in the library is still present).
If Librrd is found at configuration time, is automatically added at 
building time.

The library is provided with pkg-config support so, if it is
installed in the system, so 

    pkg-config --cflags --libs libtstat

return the CFLAGS and LIBS list used at building time.

Installing the library in the system, the following message will be printed 

----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
  during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
  during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

This tells how to link the library to an external program. 
The following example shows how to build and link using 
command in Makefile.am

bin_PROGRAMS = <program_name>
...
<program_name>_LDADD = -ltstat -lpcap -lpthread -lm
<program_name>_LDFLAGS = -Wl,--rpath -Wl,<libtstat_dir>

where <program_name> is the name of program to build and
<libtstat_dir> is the system directory of the library
(for example /usr/local/lib)

Libtstat API
============
int tstat_init (char *config_fname)
    'config_fname' is a file name containing a set of Tstat options
    Example:
        #this is a comments
        -N ../../tstat-conf/net.all
        -ddd
    If NULL is provided, the library use ./tstat.conf
    as filename

void tstat_new_logdir (char *filename, 
                       struct timeval *pckt_time)
    This function has to be called after the first packets
    has been readed, because logs generated by the library are placed 
    in a hierachy as the following:
        <filename>.out
            |__<pckt_time>.out


int tstat_next_pckt (struct timeval *pckt_time, 
                     void *ip_hdr, 
                     void *last_ip_byte, 
                     int tlen,
		     int ip_direction)
    This function enable the processing of a new packet.
    - pckt_time     the timestamp of the packet
    - ip_hdr        a pointer to the first ip byte 
    - last_ip_byte  a pointer to the last ip byte
    - tlen          number of total bytes (captured)
    - ip_direction  packet direction (in/out)
    ip_direction indicates if the packet is incoming or outgoing. Possible
    values :
      - 0  use the address based classification provided 
           by the -N option
      - 1  packet is treated as having internal source and 
           internal destination (local packet)
      - 2  packet is treated as having internal source and 
           external destination (outgoing packet) 	     
      - 3  packet is treated as having external source and
	   internal destination (incoming packet)
      - 4  packet is treated as having external source and
           external destination (external packet, will be ignored)	      

tstat_report *tstat_close (tstat_report *report)
    This function flush to file all the pending statistics
    and fill a tstat_report structure with some general
    results.

void tstat_print_report (tstat_report *report, 
                         FILE *file)
    This function print a formatted report to file
    using tstat_report data.

