An error occurred while compiling the firewall on books.

Source: Internet
Author: User
An error occurred while compiling the firewall in the book-Linux general technology-Linux programming and kernel information. The following is a detailed description. // User_firewall.c
# Ifndef _ KERNEL __
# Define _ KERNEL __
# Endif
# Ifndef MODULE
# Define MODULE
# Endif
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Static unsigned int user_firewall (unsigned int hooknum, struct sk_buff ** skb, const struct net_device * in,
Const struct net_device * out, int (* okfn) (struct sk_buff *))
{
Struct iphdr * iph;
Struct tcphdr * tcph;
Struct udphdr * udph;

_ U32 sip;
_ U32 dip;
_ 2010sport;
_ B2dport;

Iph = (* skb)-> nh. iph;
Sip = iph-> saddr;
Dip = iph-> daddr;

If (iph-> ihl! = 5)
{// Check the checksum
Printk ("IP packet with packet from % d. % d. % d. % d to % d. % d. % d. % d \ n ", NIPQUAD (sip), NIPQUAD (dip ));
}

If (iph-> protocol = 6)
{Tcp protocol
Tcph = (struct tcphdr *) (_ u32 *) iph + iph-> ihl );
Sport = tcph-> source;
Dport = tcph-> dest;
Printk ("Source port: % d \ n", ntohs (tcph-> source ));
Printk ("Dest port: % d \ n", ntohs (tcph-> dest ));
If (tcph-> syn) & (sport = dport) & (sip = dip ))
{
Printk ("maybe land attack \ n ");
}
If (ntohs (tcph-> dest) = 139 & tcph-> urg)
{
Printk ("maybe winnuke a from % d. % d. % d. % d to % d. % d. % d. % d \ n ", NIPQUAD (sip), NIPQUAD (dip ));
}

}

Else if (iph-> protocol = 17)
{// Udp protocol
Udph = (struct udphdr *) (_ u32 *) iph + iph-> ihl );
Sport = udph-> source;
Dport = udph-> dest;
Printk ("Source port: % d \ n", ntohs (udph-> source ));
Printk ("Dest port: % d \ n", ntohs (udph-> dest ));
//...................................... ..
}

Else
{
Printk ("unknown protocol % d packet from % d. % d. % d. % d to % d. % d. % d. % d \ n ", iph-> protocol, NIPQUAD (sip), NIPQUAD (dip ));
}
Return NF_ACCETR;
}
Static struct nf_hook_ops iplimitfilter =
{
{NULL, NULL },
User_firewall,
PF_INET,
NF_IP_PRE_ROUTING,
NF_IP_PRI_FILTER-1
};
Int init_module (void)
{
Return nf_register_hook (& iplimitfilter );
}
Void cleanup_module (void)
{
Nf_unregister_hook (& iplimitfilter );
}


The book says: gcc-O-c-Wall user_firewall.c
But there are many header file errors. My kernel version is 2.4
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.