Commit 35340052 authored by 's avatar
Browse files

+ Added an example function.



git-svn-id: file:///home/svn/mapi/trunk@1274 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 4de2f646
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include "mapi.h"
static void dump_packet( FILE *f, const unsigned char *buf, unsigned int sz )
{
unsigned int i;
int in_string = 0;
for( i=0; i<sz; i++ ){
unsigned char c = buf[i];
if( c>=' ' && c<0x7f ){
if( !in_string ){
fputs( "\" ", f );
in_string = 1;
}
fputc( c, f );
}
else {
if( in_string ){
fputs( "\" ", f );
in_string = 0;
}
fprintf( f, "%02X ", c );
}
}
if( in_string ){
fputc( '"', f );
}
fputs( "\n", f );
fflush( f );
}
static void callback( const struct mapipkt *pkt )
{
dump_packet( stdout, &pkt->pkt, pkt->caplen );
}
int main( int argc, char **argv )
{
int res;
char *interface = "eth0";
int fd = mapi_create_flow( interface );
//int fd = mapi_create_offline_flow( "tests/tracefile", MFF_PCAP );
if( fd<0 ){
fprintf( stderr, "Could not create a MAPI flow for interface `%s'\n", interface );
exit( EXIT_FAILURE );
}
int sid = mapi_apply_function( fd, "RULER", "/home/reeuwijk/lobster/src/ruler/mapi/filter.rl" );
if( sid<0 ){
fprintf( stderr, "Could not apply function\n" );
exit( EXIT_FAILURE );
}
int bufid = mapi_apply_function( fd, "TO_BUFFER" );
if( bufid<0 ){
fprintf( stderr, "Could not apply function\n" );
exit( EXIT_FAILURE );
}
res = mapi_connect( fd );
if( res<0 ){
fprintf( stderr, "Could not connect to flow %d\n", fd );
exit( EXIT_FAILURE );
}
mapi_loop( fd, bufid, 50, &callback );
mapi_close_flow( fd );
return EXIT_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment