易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux内核如何接收不同类型以太帧

1. 前言
以太头中除了6字节目的MAC地址、6字节源MAC地址外,还有两字节的以太帧类型值,如IPv4为0x0800,ARP为0x0806等,网卡驱动收到以太帧后通过接口函数netif_receive_skb()(netif_rx实际最后也是调用netif_receive_skb)交到上层,而这个接口函数就完成对以太帧类型的区分,交到不同的协议处理程序。如果想自己编写某一以太类型帧的处理程序,需要自己添加相应的
以下Linux内核代码为2.6.17.11。
 
2. 数据结构
每种协议都要定义一个packet_type结构,引导进入相关的协议数据处理函数,所有节点组成一个链表(HASH链表)。
/* include/linux/netdevice.h */
struct packet_type {
 __be16   type; /* This is really htons(ether_type). */
 struct net_device *dev; /* NULL is wildcarded here      */
 int   (*func) (struct sk_buff *,
      struct net_device *,
      struct packet_type *,
      struct net_device *);
 void   *af_packet_priv;
 struct list_head list;
};
参数说明:
type:以太帧类型,16位
dev:所附着的网卡设备,如果为NULL则匹配全部网卡
func:协议入口接收处理函数
af_packet_priv:协议私有数据
list:链表扣
一般各协议的packet_type结构都是静态存在,初始化时只提供type和func两个参数就可以了,每个协议在初始化时都要将此结构加入到系统类型链表中。
3. 处理函数
3.1 添加节点
/* net/core/dev.c */
/**
 * dev_add_pack - add packet handler
 * @pt: packet type declaration
 *
 * Add a protocol handler to the networking stack. The passed &packet_type
 * is linked into kernel lists and may not be freed until it has been
 * removed from the kernel lists.
 *
 * This call does not sleep therefore it can not
 * guarantee all CPU's that are in middle of receiving packets
 * will see the new packet type (until the next received packet).
 */
void dev_add_pack(struct packet_type *pt)
{
 int hash;
 


相关文档:

实战Linux Bluetooth编程(三) HCI层编程

1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI)  就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......

Linux设备模型之input子系统详解

一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......

linux 0.11 内核学习 console.c,控制台


参考《linux内核完全注释》和网上相关文章
/*
 * 控制台显示操作
 */
/*
 *  linux/kernel/console.c
 *
 *  (C) 1991  Linus Torvalds
 */
/*
 * console.c
 *
 * This module implements the console io functions
 * 'void con_init(v ......

Linux环境的AMP安装 MEMCACHED安装


MEMCACHED安装
一、服务端。先安装libevent,再安装memcached。(注:libevent是一套跨平台的事件处理接口的封装,能够兼容包括:Windows/Linux/BSD/Solaris等操作系统的事件处理)
1、下载最新版本的libevent和memcached,笔者的安装目录为/soft
>cd /soft
>wget http://www.dange.com/memcached/dist/memcach ......

Linux环境的AMP安装 MSSQL扩展安装


Linux要安装mssql扩展,必须首先安装freetds,安装过程如下:
1、假设源文件目录为/webServ,安装目录为/opt/freetds。
1) >cd /webServ
2) 下载, >wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
3) 解压, >tar -zxvf freetds-stable.tgz
4) 进入, >cd freetds-0。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号