pktinfo.c 2.21 KB
Newer Older
Arne Øslebø's avatar
Arne Øslebø committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#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 "pktinfo.h"

static int pktinfo_instance(mapidflib_function_instance_t *instance,
14
15
			    MAPI_UNUSED int fd,
			    MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
Arne Øslebø's avatar
Arne Øslebø committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{
  int type;
  mapiFunctArg* fargs;

  //Check argument and get pointer to other function instance
  fargs=instance->args;

  type = getargint(&fargs);

  if(type!=PKT_TS && type!=PKT_SIZE)
    return MFUNCT_INVALID_ARGUMENT_2;

  return 0;
};

static int pktinfo_process_size(mapidflib_function_instance_t *instance,
's avatar
committed
32
33
			MAPI_UNUSED unsigned char* dev_pkt,
			MAPI_UNUSED unsigned char* link_pkt,
Arne Øslebø's avatar
Arne Øslebø committed
34
35
36
37
38
39
40
			mapid_pkthdr_t* pkt_head)  
{
  (*(unsigned long long*)instance->result.data)=(unsigned long long)pkt_head->wlen;
  return 1;
}

static int pktinfo_init(mapidflib_function_instance_t *instance,
41
			MAPI_UNUSED int fd)
Arne Øslebø's avatar
Arne Øslebø committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
  int type;
  mapiFunctArg* fargs;

  //Check argument and get pointer to other function instance
  fargs=instance->args;

  type = getargint(&fargs);

  if(type==PKT_SIZE)
    instance->def->process=pktinfo_process_size;
  else if(type!=PKT_TS)
    return MFUNCT_INVALID_ARGUMENT_2;

  return 0;
}

static int pktinfo_process_ts(mapidflib_function_instance_t *instance,
's avatar
committed
60
61
			MAPI_UNUSED unsigned char* dev_pkt,
			MAPI_UNUSED unsigned char* link_pkt,
Arne Øslebø's avatar
Arne Øslebø committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
			mapid_pkthdr_t* pkt_head)  
{
  (*(unsigned long long*)instance->result.data)=(unsigned long long)pkt_head->ts;
  return 1;
}

static mapidflib_function_def_t finfo={
  "", //libname
  "PKTINFO", //name
  "Returns information about a packet as unsigned long long",
  "i", //argdescr
  MAPI_DEVICE_ALL, //devoid
  MAPIRES_SHM, //Method for returning results
  sizeof(unsigned long long), //shm size
  0, //modifies_pkts
77
78
  0, //filters packets
  MAPIOPT_AUTO, //Optimization
Arne Øslebø's avatar
Arne Øslebø committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  pktinfo_instance,
  pktinfo_init,
  pktinfo_process_ts,
  NULL, //get_result,
  NULL, //change_args
  NULL, //reset
  NULL, //cleanup
  NULL, //client_init
  NULL, //client_read_result
  NULL  //client_cleanup
};

mapidflib_function_def_t* pktinfo_get_funct_info();

mapidflib_function_def_t* pktinfo_get_funct_info() {
  return &finfo;
};