linux 内核模块发送udp,在内核模块级缓冲UDP的问题(当然不是SOCKET编程了。)
毕设在写LINUX内核模块。现在碰到一个问题。
总目标:在一个截包函数中缓冲所有UDP包。
截包函数如下。
tatic unsigned int mipv6_intercept(//一个截包的函数
unsigned int hooknum,
struct sk_buff **p_skb,//在/usr/src/linux-2.4.20的linux目录下skbuff.h里定义,很好的一结构。在这里主要用它,具体结构见最后
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *skb = (p_skb) ? *p_skb : NULL;
struct ipv6hdr *ipv6h;
struct in6_addr *daddr, *saddr;
__u8 nexthdr;
int nhoff;
if(skb == NULL) return NF_ACCEPT;
ipv6h = skb->nh.ipv6h;
daddr = &ipv6h->daddr;
saddr = &ipv6h->saddr;
nexthdr = ipv6h->nexthdr;//第一个是IP6包头,nexthdr是下一个包头的类型。
//---------以下----有关ICMPV6包的----------可不管---------
if (ipv6_ext_hdr(nexthdr))
nhoff = ipv6_skip_exthdr(skb, nhoff, &nexthdr,
skb->len - sizeof(*ipv6h));
/*
* Possible ICMP packets are checked to ensure that all neighbor
* solicitations to MNs home address are handled by the HA.
*/
if (nexthdr == IPPROTO_ICMPV6) {
struct icmp6hdr *icmp6h;
int dest_type;
if (nhoff nh.raw[nhoff];
/* HA has to capture all unicast 单播neighbour solicitations in
order to check if it is acting as a proxy for the target
address. */
if ((dest_type & IPV6_ADDR_UNICAST) &&
icmp6h->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
ip6_input(skb);
return NF_STOLEN;
}
}
//---------以上----有关ICMPV6包的----可不管---------------
//---------以下为UDP包的外理-----------------------
if (nexthdr == 17)//17=0x11就是说这个是UDP包,我要缓冲它
{
printk("this is a udp packet n");
//之后我想打出这个UDP包的内容,缓冲这个UDP包等。
//怎么写???
我想随便打几个结构里的信息出来看看都说错。(模仿系统里UDP.c中的写法)
struct udphdr *uh;
printk("udphdr's source=%dn",uh->source);//在编译模块时说错:dereference pointer to incomplete type
//------------------以上为UDP包处理--------没完成-不会写了------
}
以下为SK_BUFF的结构,含有传输层,网络层,链路层 3层中各种协议的结构,巨好。
struct sk_buff {
/* These two members must be first. */
struct sk_buff* next;/* Next buffer in list */
struct sk_buff* prev;/* Previous buffer in list */
struct sk_buff_head * list;/* List we are on*/
struct sock*sk;/* Socket we are owned by */
struct timevalstamp;/* Time we arrived*/
struct net_device*dev;/* Device we arrived on/are leaving by*/
/* Transport layer header */
union
{
struct tcphdr*th;
struct udphdr *uh;
struct icmphdr*icmph;
struct igmphdr*igmph;
struct iphdr*ipiph;
struct spxhdr*spxh;
unsigned char*raw;
} h;
/* Network layer header */
union
{
struct iphdr*iph;
struct ipv6hdr*ipv6h;
struct arphdr*arph;
struct ipxhdr*ipxh;
unsigned char*raw;
} nh;
/* Link layer header */
union
{
struct ethhdr*ethernet;
unsigned char *raw;
} mac;
struct dst_entry *dst;
/*
* This is the control buffer. It is free to use for every
* layer. Please put your private variables there. If you
* want to keep them across layers you have to do a skb_clone()
* first. This is owned by whoever has the skb queued ATM.
*/
charcb[48];
unsigned int len;/* Length of actual data*/
unsigned int data_len;
unsigned intcsum;/* Checksum */
unsigned char __unused,/* Dead field, may be reused*/
cloned, /* head may be cloned (check refcnt to be sure). */
pkt_type,/* Packet class*/
ip_summed;/* Driver fed us an IP checksum*/
__u32priority;/* Packet queueing priority*/
atomic_tusers;/* User count - see datagram.c,tcp.c */
unsigned shortprotocol;/* Packet protocol from driver. */
unsigned shortsecurity;/* Security level of packet*/
unsigned inttruesize;/* Buffer size */
unsigned char*head;/* Head of buffer */
unsigned char*data;/* Data head pointer*/
unsigned char*tail;/* Tail pointer*/
unsigned char *end;/* End pointer*/
void (*destructor)(struct sk_buff *);/* Destruct function*/
#ifdef CONFIG_NETFILTER
/* Can be used for communication between hooks. */
unsigned longnfmark;
/* Cache info */
__u32nfcache;
/* Associated connection, if any */
struct nf_ct_info *nfct;
#ifdef CONFIG_NETFILTER_DEBUG
unsigned int nf_debug;
#endif
#endif /*CONFIG_NETFILTER*/
#if defined(CONFIG_HIPPI)
union{
__u32ifield;
} private;
#endif
#ifdef CONFIG_NET_SCHED
__u32 tc_index; /* traffic control index */
#endif
};
|
else if (nexthdr==17)
{
printk("tzh UDP :nexthdr=%d ",nexthdr);
printk("tzhbuf=%dn",tzhbuf);
//failed
//u32 ulen=0;
struct udphdr *udp6h;
int dest_type;
printk(" ##3#%d###",nhoff);
if (nhoff nh.raw[nhoff];
printk(" ##4#%d###",nhoff);
//printk("dup6h%dn",udp6h);
printk("tzh udphdr's source port =%un",ntohs(udp6h->source));
printk("tzh udphdr's dest port=%un",ntohs(udp6h->dest));
printk("tzh udphdr's length=%un",ntohs(udp6h->len));
printk("tzh udphdr's check=%un",ntohs(udp6h->check));
//__u16 * data=(__u16*)&skb->h.raw[sizeof(struct udphdr)];
__u16 * data=((__u16*)udp6h+sizeof(struct udphdr)/2);
int haha=sizeof(struct udphdr);
printk("data%dn",haha);
//data[14]='';
int i;
for(i=0;i
linux 内核模块发送udp,在内核模块级缓冲UDP的问题(当然不是SOCKET编程了。)相关推荐
- Linux系统下一切皆文件,socket编程浅析
"一切皆Socket!" 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. --有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信 ...
- 向Linux增加一个系统调用或内核模块
向Linux增加一个系统调用或内核模块 配置环境 获取root权限 sudo su 更新系统 sudo apt-get update 安装相关编译程序包 sudo apt-get install li ...
- 从零开始学Linux内核驱动--(二)简单内核模块驱动程序
Linux驱动–(二)简单的内核模块驱动程序 一.概述 Linux中所有的驱动都是以内核模块的形式来实现的,他们与其他所有的内核编译在一起形成一个单独的内核镜像文件(所以说Linux是一个宏内核).当 ...
- Linux内核编译(通过内核模块显示进程控制块信息)
Linux内核编译(通过内核模块显示进程控制块信息) 实验说明 在内核中,所有进程控制块都被一个双向链表连接起来,该链表中的第一个进程控制块为init_task.编写一个内核模块,模块接收用户传递的一 ...
- 《嵌入式Linux驱动开发教程》--内核模块
内核模块 绝大多数的驱动都是以内核模块的形式实现. 宏内核和微内核 宏内核(Linux):所有的内核功能都被整体编译在一起,形成单独的内核镜像文件,内核中各功能模块的交互通过直接的函数调用进行. 微内 ...
- Linux网络编程 | Socket编程(一):Socket的介绍、UDPSocket的封装、UDP服务器/客户端的实现
目录 套接字编程 Sockaddr结构 字节序 地址转换 常用套接字接口 UDP的通信流程 UDPSocket的封装 UDP服务器 UDP客户端 套接字编程 所谓套接字(Socket),就是对网络中不 ...
- _Linux内核分析(二)-内核模块简介和简单内核模块实现
一.Linux内核模块简介 1. 何为内核模块 在上一篇博文中我们先通过内核配置,在配置的过程中我们对内核的组件进行了选择(当然这个选择决定了我们内核的大小),然后才生成了我们最终的内核,那么我们如果 ...
- 分析udp数据报_Linux内核网络udp数据包发送(二)——UDP协议层分析
1. 前言 本文分享了Linux内核网络数据包发送在UDP协议层的处理,主要分析了udp_sendmsg和udp_send_skb函数,并分享了UDP层的数据统计和监控以及socket发送队列大小的调 ...
- asp.core api 通过socket和服务器通信发送udp_详解Linux的SOCKET编程
文章来自于 https://www.zhangshengrong.com/p/9Oabd95XdK/ PHP进阶学习交流QQ群:983229225 本篇文章对Linux的SOCKET编程进行了详细解释 ...
最新文章
- 使用FiddlerCore来截取替换Http请求中的网页内容
- 【转载】WINCE物理和虚拟地址的问题
- 小红书去水印代码_小红书关键词排名如何进行优化
- 29 Python - 字符与编码
- Windows重装Anaconda3失败解决方案【重装失败10来次首次成功的案例!】
- php无刷新跳转,用#号实现web页面的无刷新跳转
- Flutter进阶第3篇:下拉刷新 上拉分页加载更多
- Hadoop学习笔记—5.自定义类型处理手机上网日志
- 鸿蒙系统翻车了,鸿蒙“翻车”? 网友发现鸿蒙系统居然是安卓9.0
- Dreamweaver/Flash CS4安装后打开时提示此产品的许可已停止工作
- Ken Thompson 的经典 C 程序
- 小尺寸 GPS 北斗 GNSS 全向内置天线方案 CA-G01 CrossAir贴片天线
- set的用法及短语_set的用法和例句
- php网页制作代码_如何制作一个简单的HTML登录页面(附代码)
- 所见即所得的开源Flex设计工具:flexible
- Nginx 防止被域名恶意解析的方法
- 单片机——点阵1(Proteus和KeilC51)
- Tomcat 9 下载与安装【个人总结】
- 与人合伙做生意,每人出资20万,一方只出资不出力,另一方出资又出力股份如何分配??...
- 优思学院|Minitab是什么软件?有什么用?
热门文章
- 中国企业借东博会“走出去”将打造马来西亚首个智慧城市
- SQL server 2005的复制(四)
- Microsoft SQL server 2005的基本操作
- Asp调用函数是否会影响性能?
- 错误提示:error LNK2001: unresolved external symbol public: static int person::weight (?weight@person@@
- ARMLINUX学习笔记(6)------启动代码分析
- Oracle 11g xe版本---总结1
- [转]调整 VirtualBox 虚拟机的磁盘大小
- SQL Server时间粒度系列----第9节时间粒度示例演示
- C++ Traits技术