99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

Linux中生成testtcp.ko模塊代碼怎么寫-創新互聯

這期內容當中小編將會給大家帶來有關Linux中生成testtcp.ko模塊代碼怎么寫,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創新互聯公司主要業務有網站營銷策劃、網站制作、網站建設、微信公眾號開發、重慶小程序開發H5網站設計、程序開發等業務。一次合作終身朋友,是我們奉行的宗旨;我們不僅僅把客戶當客戶,還把客戶視為我們的合作伙伴,在開展業務的過程中,公司還積累了豐富的行業經驗、營銷型網站建設資源和合作伙伴關系資源,并逐漸建立起規范的客戶服務和保障體系。 

生成testtcp.ko模塊,添加到內核。

添加該模塊后,每個由該機器發出的數據包,如果是TCP協議,且源端口為81,將其改為RST包發出。

一、代碼

1.1 文件:testtcp_main.c

#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/inetdevice.h>
#include <linux/string.h>
#include <net/route.h>
#include <linux/inet.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <net/checksum.h>
#include <net/tcp.h>
#include <net/ip.h>

unsigned int hook_mark1(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 sk_buff *sk = skb;

    u16 src_port,dst_port;
    u16 datalen;

    iph = ip_hdr(sk);
    tcph = (struct udphdr*)((u_int8_t*)iph + (iph->ihl << 2));
    src_port = ntohs(tcph->source);
    dst_port = ntohs(tcph->dest);
    
    if(src_port == 81 || dst_port == 81)
    	printk("<0>""src_port:%d, dst_port:%d, protocol:%d, rst:%d\n",src_port, dst_port, iph->protocol, tcph->rst);

    if (iph->protocol == 6 && src_port == 81)
    {  
        printk("<0>""---000---src_port:%d, dst_port:%d, protocol:%d, rst:%d\n",src_port, dst_port, iph->protocol, tcph->rst);

	tcph->rst = 1;

        iph->check = 0;
        iph->check = ip_fast_csum((unsigned char*)iph, iph->ihl);

        datalen = ntohs(iph->tot_len) - (iph->ihl << 2);
        tcph->check = 0;
        tcph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, datalen,
                                            iph->protocol, csum_partial((unsigned char*)tcph,  datalen, 0));
        skb->ip_summed = CHECKSUM_NONE;
        
        return NF_ACCEPT;
    }

    return NF_ACCEPT;
}


static struct nf_hook_ops nfho_marker1;

static int init_marker(void)
{    
    nfho_marker1.hook=hook_mark1;
    nfho_marker1.hooknum=NF_INET_LOCAL_OUT;
    nfho_marker1.pf=PF_INET;
    nfho_marker1.priority=NF_IP_PRI_LAST;
    nf_register_hook(&nfho_marker1);

    return 0;
}

static void exit_marker(void)
{
    nf_unregister_hook(&nfho_marker1);       
}


module_init(init_marker);
module_exit(exit_marker);

1.2 文件Makefile:

obj-m := testtcp.o
testtcp-objs := testtcp_main.o

KERNELDIR = /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
      $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:  
      $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
install:
      cp inerdns.ko ../

注意事項:

     1. 第一行的testtcp.o 與第二行的testtcp_main.o  不能重復。

      2. 第一行的testtcp.o 與第二行的testtcp-objs  前綴必須相同。

      3. “default:”、“clean:  ”、“install:” 下一行的內容,行前面必須有tab鍵。

二、編譯、添加模塊到內核

2.1 編譯

      執行make,即可編譯代碼,并生產模塊testtcp.ko。

2.2 添加模塊到內核

      lsmod                          查看linux內核模塊。

      insmod testtcp.ko     將testtcp.ko模塊添加到內核。

      (rmmod testtcp           從內核中刪除testtcp.ko模塊。)

三、測試模塊功能

3.1 測試代碼

     可以參照以下文章代碼修改:http://blog.csdn.net/guowenyan001/article/details/11742621

3.2 linux下訪問URL

      curl 192.168.9.200:81

3.3 抓包查看

      用tcpdump抓包查看,相關數據包是否已經被修改為RST包。

四、注意事項

      內核模塊代碼,可能會造成系統崩潰,需要重啟,所以好在測試機上測試內核代碼。

上述就是小編為大家分享的Linux中生成testtcp.ko模塊代碼怎么寫了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創新互聯行業資訊頻道。

分享標題:Linux中生成testtcp.ko模塊代碼怎么寫-創新互聯
本文來源:http://www.yijiale78.com/article48/dpceep.html

成都網站建設公司_創新互聯,為您提供做網站關鍵詞優化全網營銷推廣外貿建站網站排名用戶體驗

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

小程序開發