//sockopt.c
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/netfilter.h>
#include"sockopt.h"
static int my_set(struct sock *sk, int optval, void *user, unsigned int len)
{
printk("my set: sk=%d, optval=%d, user=%s, len=%d\n", (int)sk, optval, (char *)user, len);
return 0;
}
static int my_get(struct sock *sk, int optval, void *user, int *len)
{
printk("my get: sk=%d, optval=%d\n", (int)sk, optval);
strcpy((char *)user, "hahaha");
*len = 7;
return 0;
}
static struct nf_sockopt_ops my_sockopt=
{
{NULL, NULL},
PF_INET,
MY_SOCKOPT, MY_SOCKOPT + 1, my_set,
MY_SOCKOPT, MY_SOCKOPT + 1, my_get,
0,
NULL
};
static int __init init(void)
{
int ret;
ret = nf_register_sockopt(&my_sockopt);
if(ret !=0 )
{
printk("Can not register\n");
}
return ret;
}
static void __exit tini(void)
{
nf_unregister_sockopt(&my_sockopt);
}
module_init( init );
module_exit( tini );
MODULE_LICENSE( "GPL" );
|