套接字缓存区(sk_buff)结构是Linux 网络子系统(网卡)的核心内容,在<Linux/skbuff.h>中被定义
linux 套接字缓冲区支持分配,释放,指针的移动等功能函数
1>分配 struct sk_buff *dev_alloc_skb(unsigned int len);
2>释放 void dev_kfree_skb(struct sk_buff *skb);
3>指针的移动
a:put 操作
unsigned char *skb_put(strcut sk_buff *skb,unsigned int len);
b:push 操作
unsigned char *skb_push(struct sk_buff *skb,unsigned int len);
c:pull操作
unsigned char * skb_pull(struct sk_buff *skb,unsigned int len);
d:reserve 操作
void skb_reserve(struct sk_buff *skb,unsigned int len);
net_device结构在内核中指代一个网络设备,网络驱动程序只需通过填充net_device 的具体成员并注 册,net_device 即可实现硬件操作函数和内核的挂接
基本方法包括:
int (*open)(struct net_device *dev);
int (*stop)(strcut net_device *dev);
int (*hard_start_xmit)(struct sk_buff *skb,struct net_device *dev);
int (*hard_header)(struct sk_buff *skb,struct net_device *dev,unsigned short type,void *daddr,void *saddr,unsigned len);
int (*rebuild_header)(struct sk_buff *skb);
void(*tx_timeout)(strcut net_device *dev);
struct net_device_stats *(get_stats)(struct net_device *dev);
int (*set_config)(struct net_device *dev,struct ifmap *map);
int (*do_ioctl)(struct net_device *dev,struct ifreq *ifr,int cmd);
void (*set_multicast_list)(struct net_device *dev);
int (*set_mac_address)(strcut net_device *dev,void *adddr);
int (*change_mtu)(struct net_device *dev,int new_mtu);
int (*headerA_cache)(struct neighbour *neigh,struct hh_cache *hh);
int (*header_cache_update)(struct hh_cache *hh,struct net_device *dev,unsigned char*haddr);
int(*hard_header_parse)(struct sk_buff *skb,unsigned char *haddr);