现在的位置: 首页 > 综合 > 正文

Libnet核心数据结构

2013年09月23日 ⁄ 综合 ⁄ 共 2138字 ⁄ 字号 评论关闭

linbnet是一个专业网络数据包构造和发送开发包,它主要提供了IP层和链路层构造网络数据包的功能.

核心数据结构(定义在libnet-structures.h文件中)

1.linbnet_plist_t:表示端口链表数据结构,定义如下

typedef struct libnet_port_list_chain libnet_plist_t;

struct libnet_port_list_chain

{

u_int16_t node; //链表结点个数

u_int16_t bport; //开始的端口

u_int16_t eport; //终止的端口

u_int8_t id;           //全局排列偏移量

libnet_plist_t *next; //链表的下一个结点

}//端口链表数据结构在构造UDP和TCP数据包时非常有用

2.libnet_stats:统计分析的数据结构

struct libnet_stats

{

#if(!defined(_WIN32_)||(_CYGWIN_))

u_int64_t packets_sent;//发送的数据包

u_int64_t packet_errors;//出错的数据包

u_int64_t bytes_writen;//已经写的字节数目

#else

__int64 packets_sent;

__int64 packet_errors;

__int664 bytes_writen;

#endif

};//主要是对当前的Libnet环境进行状态统计,调用函数libnet_stats()来获取此数据结构内容

3.libnet_ptag_t:表示一个Libnet协议标记,用来在链表中来识别一个特定的协议块

typedef int32_t libnet_ptag_t; //此协议标记其实是一个32位的整数

#define
LIBNET_PTAG_INITALIZER                        0

4.libnet_pblock_t:用来表示Libnet的协议块
的数据结构(一个数据块)

struct libnet_protocol_block

{

u_int8_t
*buf;//表示此协议块的协议数据,它指向一段内存,此内存存储的内容就是此协议块的实际协议数据

u_int32_t b_len;//表示buf存储的协议数据长度

u_int16_t h_len;//首部长度

u_int32_t ip_offset;//IP首部的偏移量

u_int32_t copied;//拷贝的字节数目

u_int8_t type;//协议块的类型,共63种协议块类型

u_int8_t flags;//控制标记

libnet_ptag_t ptag;//协议块标记

struct libnet_protocol_block
*next;//下一个pblock

struct libnet_protocol_block
*prev;//前一个pblock

};

5.libnet_t:表示Libnet句柄的数据结构,是
libnet开发包中最重要的一个数据结构(可以理解为一个数据包)

struct libnet_context

{

#if((_WIN32_)&&!(_CYGWIN_))

SOCKET fd;

#else

int fd;//数据包设备的文件描述符

#endif

int
injection_type;//表示libnet类型,libnet中共定义了7种类型

libnet_pblock_t
*protocol_blocks;//指向第一个协议块结点

libnet_pblock_t
*pblock_end;//指向链表的最后一个协议块结点

u_int32_t n_pblocks;//协议块的数目

int link_type;//链路层类型

int link_offset;//链路层首部偏移

int aligner;//用来排序数据包

char *device;//设备名字

struct libnet_stats stats;//统计分析

libnet_ptag_t
ptag_state;//pblock标记状态

char
label[LIBNET_LABEL_SIZE];//句柄队列的文本标记

char
err_buf[LIBNET_ERRBUF_SIZE];//错误信息

u_int32 total_size;//数据包整体大小

}

6.libnet_cqd_t表示Libnet句柄队列数据结构

typedef struct _libnet_context_queue libnet_cq_t;

struct _libnet_context_queue

{

libnet_t *context;//指向libnet句柄的指针

libnet_cq_t *next;//队列的下一个结点

libnet_cq_t *prev;//队列的前一个结点

};

struct _libnet_context_queue_descriptor

{

u_int32_t node;//队列的结点个数

u_int32_t cq_lock;//锁的状态 如果上锁就不能改写

libnet_cq_t *current;//当前句柄

};

typedef struct _libnet_context_queue_descruptor libnet_cqd_t;

主要用于构造多个数据包

抱歉!评论已关闭.