Commit abe93204 authored by Arne Øslebø's avatar Arne Øslebø
Browse files

added new function

git-svn-id: file:///home/svn/mapi/trunk@218 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent b74a58f1
......@@ -19,7 +19,7 @@ all: $(TARGETS)
mapidstdflib.o: mapidstdflib.c ../mapidflib.h ../mapi.h
$(CC) $(CFLAGS) -c $<
mapidstdflib.so: mapidstdflib.o pktcounter.o bytecounter.o getres.o strsearch.o bpffilter.o cooking.o ../fhelp.o ../mapiipc.o ../mstring.o ../list.o tobuffer.o tobuffer_all.o to_tcpdump.o sample.o startstop.o hash.o gap.o pktinfo.o res2file.o stats.o dist.o ../slist.o ../fifo.o ../cbuf.o ../flist.o hashsamp.o threshold.o bucket.o bpf_lib.a libnids.a libnet.a
mapidstdflib.so: mapidstdflib.o pktcounter.o bytecounter.o getres.o strsearch.o bpffilter.o cooking.o ../fhelp.o ../mapiipc.o ../mstring.o ../list.o tobuffer.o tobuffer_all.o to_tcpdump.o sample.o startstop.o hash.o gap.o pktinfo.o res2file.o stats.o binop.o dist.o ../slist.o ../fifo.o ../cbuf.o ../flist.o hashsamp.o threshold.o bucket.o bpf_lib.a libnids.a libnet.a
$(CC) $(CFLAGS) -shared -o $@ $^ -lfl -lrt -L.. -L. $(LIB_DIR) -lm -lpcap
cp $@ ..
......@@ -56,6 +56,9 @@ sample.o: sample.c sample.h
hash.o: hash.c
$(CC) $(CFLAGS) -c $<
binop.o: binop.c
$(CC) $(CFLAGS) -c $<
startstop.o: startstop.c
$(CC) $(CFLAGS) -c $<
......
#include <stdlib.h>
#include <stdio.h>
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
#include "mapid.h"
#include "fhelp.h"
#include "binop.h"
typedef struct binop_inst {
int left_fd,left_fid,right_fd,right_fid;
} binop_inst_t;
static int binop_init(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist)
{
int type;
mapiFunctArg* fargs;
//Check argument and get pointer to other function instance
fargs=instance->args;
type = getargint(&fargs);
if(type!=BINOP_ADD && type!=BINOP_SUB)
return MFUNCT_INVALID_ARGUMENT_2;
return 0;
}
static int binop_process_add(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt,
MAPI_UNUSED const unsigned char* link_pkt,
MAPI_UNUSED mapid_pkthdr_t* pkt_head)
{
unsigned long long *res,*left,*right;
binop_inst_t *i=instance->internal_data;
res=instance->result.data;
left=((mapidflib_result_t*)fhlp_new_get_res(i->left_fd,i->left_fid,instance->pid))->data;
right=((mapidflib_result_t*)fhlp_new_get_res(i->right_fd,i->right_fid,instance->pid))->data;
*res=*left+*right;
return 1;
}
static int binop_process_sub(mapidflib_function_instance_t *instance,
MAPI_UNUSED const unsigned char* dev_pkt,
MAPI_UNUSED const unsigned char* link_pkt,
MAPI_UNUSED mapid_pkthdr_t* pkt_head)
{
unsigned long long *res,*left,*right;
binop_inst_t *i=instance->internal_data;
res=instance->result.data;
left=((mapidflib_result_t*)fhlp_new_get_res(i->left_fd,i->left_fid,instance->pid))->data;
right=((mapidflib_result_t*)fhlp_new_get_res(i->right_fd,i->right_fid,instance->pid))->data;
*res=*left-*right;
// printf("%llu - %llu = %llu\n",*left,*right,*res);
return 1;
}
static int binop_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod, MAPI_UNUSED function_manipulation_t* manip)
{
int type;
mapiFunctArg* fargs;
binop_inst_t *i=instance->internal_data=malloc(sizeof(binop_inst_t));
//Check argument and get pointer to other function instance
fargs=instance->args;
type = getargint(&fargs);
i->left_fd = getargint(&fargs);
i->left_fid = getargint(&fargs);
i->right_fd = getargint(&fargs);
i->right_fid = getargint(&fargs);
if(type==BINOP_SUB)
instance->def->process=binop_process_sub;
else if(type!=BINOP_ADD)
return MFUNCT_INVALID_ARGUMENT_2;
return 0;
}
static mapidflib_function_def_t finfo={
"", //libname
"BINOP", //name
"Simulates binary operators like sum, subtract, multiply etc", //descr
"iiiii", //argdescr
MAPI_DEVICE_ALL, //devoid
MAPIRES_SHM, //Method for returning results
sizeof(unsigned long long), //shm size
0, //modifies_pkts
binop_instance, //instance
binop_init, //init
binop_process_add, //process
NULL, //get_result,
NULL, //change_args
NULL, //reset
NULL, //cleanup
NULL, //client_init
NULL, //client_read_result
NULL //client_cleanup
};
mapidflib_function_def_t* binop_get_funct_info();
mapidflib_function_def_t* binop_get_funct_info() {
return &finfo;
};
#ifndef BINOP_
#define BINOP_
enum binop {
BINOP_ADD, BINOP_SUB
};
#endif /*BINOP_*/
//Thu Mar 10 13:24:13 2005
//Tue Oct 4 09:30:43 2005
//This file was created automatically by createlib.pl
#include <stdio.h>
......@@ -10,8 +10,9 @@
__attribute__ ((constructor)) void init ();
__attribute__ ((destructor)) void fini ();
mapidflib_functionlist_t functions[20];
mapidflib_functionlist_t functions[22];
extern mapidflib_function_def_t * binop_get_funct_info();
extern mapidflib_function_def_t * bpf_get_funct_info();
extern mapidflib_function_def_t * bpf_get_funct_info();
extern mapidflib_function_def_t * bucket_get_funct_info();
......@@ -36,7 +37,7 @@ extern mapidflib_function_def_t * tobuffer_get_funct_info();
mapidflib_functionlist_t* mapidflib_get_function_list()
{
functions[0].def=bpf_get_funct_info();
functions[0].def=binop_get_funct_info();
functions[0].def->libname=libname;
functions[0].next=&functions[1];
......@@ -44,81 +45,85 @@ mapidflib_functionlist_t* mapidflib_get_function_list()
functions[1].def->libname=libname;
functions[1].next=&functions[2];
functions[2].def=bucket_get_funct_info();
functions[2].def=bpf_get_funct_info();
functions[2].def->libname=libname;
functions[2].next=&functions[3];
functions[3].def=bytec_get_funct_info();
functions[3].def=bucket_get_funct_info();
functions[3].def->libname=libname;
functions[3].next=&functions[4];
functions[4].def=cooking_get_funct_info();
functions[4].def=bytec_get_funct_info();
functions[4].def->libname=libname;
functions[4].next=&functions[5];
functions[5].def=dist_get_funct_info();
functions[5].def=cooking_get_funct_info();
functions[5].def->libname=libname;
functions[5].next=&functions[6];
functions[6].def=gap_get_funct_info();
functions[6].def=dist_get_funct_info();
functions[6].def->libname=libname;
functions[6].next=&functions[7];
functions[7].def=getres_get_funct_info();
functions[7].def=gap_get_funct_info();
functions[7].def->libname=libname;
functions[7].next=&functions[8];
functions[8].def=hash_get_funct_info();
functions[8].def=getres_get_funct_info();
functions[8].def->libname=libname;
functions[8].next=&functions[9];
functions[9].def=hashsamp_get_funct_info();
functions[9].def=hash_get_funct_info();
functions[9].def->libname=libname;
functions[9].next=&functions[10];
functions[10].def=pktc_get_funct_info();
functions[10].def=hashsamp_get_funct_info();
functions[10].def->libname=libname;
functions[10].next=&functions[11];
functions[11].def=pktinfo_get_funct_info();
functions[11].def=pktc_get_funct_info();
functions[11].def->libname=libname;
functions[11].next=&functions[12];
functions[12].def=res2file_get_funct_info();
functions[12].def=pktinfo_get_funct_info();
functions[12].def->libname=libname;
functions[12].next=&functions[13];
functions[13].def=sample_get_funct_info();
functions[13].def=res2file_get_funct_info();
functions[13].def->libname=libname;
functions[13].next=&functions[14];
functions[14].def=startstop_get_funct_info();
functions[14].def=sample_get_funct_info();
functions[14].def->libname=libname;
functions[14].next=&functions[15];
functions[15].def=stats_get_funct_info();
functions[15].def=startstop_get_funct_info();
functions[15].def->libname=libname;
functions[15].next=&functions[16];
functions[16].def=strsearch_get_funct_info();
functions[16].def=stats_get_funct_info();
functions[16].def->libname=libname;
functions[16].next=&functions[17];
functions[17].def=threshold_get_funct_info();
functions[17].def=strsearch_get_funct_info();
functions[17].def->libname=libname;
functions[17].next=&functions[18];
functions[18].def=to_tcpdump_get_funct_info();
functions[18].def=threshold_get_funct_info();
functions[18].def->libname=libname;
functions[18].next=&functions[19];
functions[19].def=toba_get_funct_info();
functions[19].def=to_tcpdump_get_funct_info();
functions[19].def->libname=libname;
functions[19].next=&functions[20];
functions[20].def=tobuffer_get_funct_info();
functions[20].def=toba_get_funct_info();
functions[20].def->libname=libname;
functions[20].next=NULL;
functions[20].next=&functions[21];
functions[21].def=tobuffer_get_funct_info();
functions[21].def->libname=libname;
functions[21].next=NULL;
return &functions[0];
}
......
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