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;
 
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
MEMCACHED安装
一、服务端。先安装libevent,再安装memcached。(注:libevent是一套跨平台的事件处理接口的封装,能够兼容包括:Windows/Linux/BSD/Solaris等操作系统的事件处理)
1、下载最新版本的libevent和memcached,笔者的安装目录为/soft
>cd /soft
>wget http://www.dange.com/memcached/dist/memcach ......
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。 ......
在我们在写程序的过程中,有些时候需要知道一些电脑的硬件信息,比如我们写一些需要注册的程序的时候,就需要得到某个电脑特定的信息,一般来说,网卡的物理地址是不会重复的,我们正好可以用它来做为我们识别一台电脑的标志.那如何得到网卡的物理地址呢?我们可以借助于ProcessBuilder这个类,这个类是JDK1.5新加的,以前也可以用Ru ......
linux系统root用户可强制踢制其它登录用户,
首先以root登录以便查看全部的在线用户信息,可用w命令查看登录用户信息
强制踢人命令格式:pkill -kill -t tty
解释:
pkill -kill -t 踢人命令
tty 所踢用户的TTY
如上踢出liu用户的命令为: pkill -kill -t pts/1
......