-
Notifications
You must be signed in to change notification settings - Fork 0
/
memcached.cc
56 lines (46 loc) · 1.18 KB
/
memcached.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <features.h>
#include <string>
#include <osv/types.h>
#include <memcached-udp.hh>
#include <bsd/sys/net/pfil.h>
using namespace std;
static inline void usage()
{
cout<<endl<<endl<<" Usage: osv-memcached"<<endl<<endl;
cout<<endl;
}
static inline int memcached_pf_hook(
void *argv, struct mbuf **m, struct ifnet *ifn, int dir, struct inpcb *inp)
{
osv_apps::memcached* memcached = static_cast<osv_apps::memcached*>(argv);
//printf("Called hook for mbuf %p dir %d\n", *m, dir);
bool res = memcached->filter(ifn, *m);
return (!res) ? 0 : 1;
}
int main(int argc, char* argv[])
{
#if 0
int i;
// Parse args
for (i = 1; i < argc; i++) {
cerr<<"Unknown parameter: "<<argv[i]<<endl;
usage();
return 1;
}
#endif
osv_apps::memcached memcached;
// Add a PF filter for the memcached
pfil_add_hook(memcached_pf_hook, (void*)&memcached, PFIL_IN | PFIL_WAITOK,
&V_inet_pfil_hook);
cout<<"Press 'e' + 'ENTER' to exit"<<endl;
char ch;
while (1) {
cin>>ch;
if (ch == 'e') {
break;
} else {
cout<<"Got: "<<ch<<endl;
}
}
return 0;
}