#include <asm/atomic.h>
#include <asm/byteorder.h>
#include <asm/checksum.h>
#include <asm/unaligned.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/net.h>
#include <linux/in.h>
#include <linux/types.h>
#include <linux/kthread.h>
#include <linux/wait.h>
#include <linux/skbuff.h>
#include <linux/string.h>
#include <linux/sysctl.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/ip.h>
#include <linux/workqueue.h>
#include <linux/jiffies.h>
#include <linux/route.h>
#include <linux/if_arp.h>
#include <linux/inetdevice.h>
#include <linux/slab.h>
#include <linux/stddef.h>
#include <linux/mutex.h>
#include <linux/compiler.h>
#include <linux/icmp.h>
#include <linux/jhash.h>
#include <linux/list.h>
#include <linux/inet.h>
#include <linux/spinlock_types.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/route.h>
#include <net/inet_connection_sock.h>
#include <net/request_sock.h>
#include <net/icmp.h>
#include <net/ip.h>
#define err(msg) printk(KERN_ERR "%s failed.\n", msg)
#define SA struct sockaddr
static void transfer_data(struct socket *sock)
{
struct msghdr msg;
struct kvec vec;
char buff[576];
int len;
struct sockaddr_in saddr;
for (;;) {
memset(&msg, '\0', sizeof(msg));
vec.iov_base = (void *)buff;
vec.iov_len = sizeof(buff);
memset(&msg, '\0', sizeof(msg));
msg.msg_name = &saddr;
msg.msg_namelen = sizeof(saddr);
len = kernel_recvmsg(sock, &msg, &vec, 1, sizeof(buff), 0);
if (len <= 0)
break;
vec.iov_base = (void *)buff;
vec.iov_len = len;
kernel_sendmsg(sock, &msg, &vec, 1, len);
}
}
static int __init main_init(void)
{
struct socket *sock;
int rc;
struct sockaddr_in addr;
rc = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock);
if (rc < 0) {
err("sock_create_kern");
goto out;
}
memset(&addr, '\0', sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(7878);
addr.sin_addr.s_addr = in_aton("192.168.10.188");
if (kernel_bind(sock, (SA *)&addr, sizeof(addr)) != 0) {
err("kernel_bind");
goto err;
}
transfer_data(sock);
sock_release(sock);
return 0;
err:
sock_release(sock);
out:
return -1;
}
static void __exit main_exit(void)
{
}
module_init(main_init);
module_exit(main_exit);
MODULE_LICENSE("GPL");
|