LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2012, 04:55 AM   #1
snakeholder
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
can't send packet


friends I'm using this
Code:
#include <linux/module.h> 
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
 
 
#include <linux/skbuff.h>
#include <linux/inet.h>
#include <linux/ip.h>
#include <net/ip.h>
#include <linux/tcp.h>
#include <linux/icmp.h>
#include <asm/uaccess.h>
 

 
MODULE_LICENSE ("GPL v2");
MODULE_AUTHOR ("ill");
MODULE_DESCRIPTION ("Firewall");
 
struct nf_hook_ops nf_incoming;
struct nf_hook_ops nf_outgoing;
struct sk_buff *skbf;
struct sk_buff *mskbf;
struct sk_buff_head *mlist;

struct tcphdr *th;
struct icmphdr *icmph;
struct iphdr *iph;
/*struct ipad;*/
int i=1; 
unsigned int hook_in (unsigned int hooknum, 
            struct sk_buff **skb,
            const struct net_device *in, 
            const struct net_device *out,
            int (*okfn)(struct sk_buff*))
            


{

skbf=*skb;
mskbf=kmalloc(skbf->truesize,GFP_ATOMIC);
mskbf=skb_copy(skbf,GFP_ATOMIC);
printk("addrpoint in=%d ICMP_inm%d Packet_len=%d ADDR=%x Buf_size=%u\n",skbf->pkt_type,mskbf->pkt_type,mskbf->len,mskbf->nh.iph->saddr,mskbf->truesize);
 
return NF_DROP;
}

unsigned int hook_out (unsigned int hooknum, 
            struct sk_buff **skb,
            const struct net_device *in,
            const struct net_device *out,
            int (*okfn)(struct sk_buff*))
{
    
    skbf=*skb;
     
if (skbf->protocol != htons(ETH_P_IP))
        return NF_ACCEPT;

    if (skbf->nh.iph->protocol != IPPROTO_TCP
	&&  skbf->nh.iph->protocol != IPPROTO_ICMP 
        && skbf->nh.iph->protocol != IPPROTO_UDP)
	return NF_DROP;
 
    if (skbf->nh.iph->protocol==IPPROTO_ICMP)
    {
	printk("ICMP_out Packet_len=%d ADDR=%x Buf_size=%u\n",skbf->len,skbf->nh.iph->saddr,skbf->truesize);

        skbf->h.icmph=(struct icmphdr *)(skbf->data+(skbf->nh.iph->ihl*4));

	if (skbf->h.icmph->type==ICMP_ECHOREPLY && skbf->h.icmph->code==0)
    	    return NF_ACCEPT;

        if (skbf->h.icmph->type==ICMP_DEST_UNREACH)
	    return NF_ACCEPT;

        if (skbf->h.icmph->type==ICMP_ECHO && skbf->h.icmph->code==0)
	    return NF_ACCEPT;
    
	return NF_DROP;
    }

return NF_ACCEPT;
    
}    
    
    
int init_module(void)
{
 
    nf_incoming.hook     = hook_in;
    nf_incoming.pf       = PF_INET;
    nf_incoming.hooknum  = NF_IP_PRE_ROUTING;
    nf_incoming.priority = NF_IP_PRI_FIRST;
 
    nf_outgoing.hook     = hook_out;
    nf_outgoing.pf       = PF_INET;
    nf_outgoing.hooknum  = NF_IP_POST_ROUTING;
    nf_outgoing.priority = NF_IP_PRI_FIRST;


    nf_register_hook(&nf_incoming);
    nf_register_hook(&nf_outgoing);

    printk ("FireWall loaded\n");
    
    return 0;
}
 
void cleanup_module(void)
{
nf_unregister_hook(&nf_incoming);
nf_unregister_hook(&nf_outgoing);

printk ("FireWall unload\n");
}
and I need to seend my packet mskbf instead of skbf.
but I can't find how!!
pls help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to send a ping packet karan2386 Linux - Kernel 1 02-18-2012 03:36 AM
send a packet through sockets c++ vbx_wx Programming 6 02-04-2011 06:40 PM
how to send a tcp packet using libpcap? kalps Programming 3 05-07-2009 04:53 PM
IP layer send packet shuperb Linux - Kernel 2 06-27-2008 11:19 PM
send packet at network Jamesminh Programming 1 10-01-2004 10:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration