第6章 Libnet和Libnids编程技术.pptVIP

  • 12
  • 0
  • 约4.32千字
  • 约 24页
  • 2016-08-04 发布于河南
  • 举报
第6章 Libnet和Libnids编程技术

第六章 Libnet和Libnids编程技术 内容 Libnet Libnids 一、Libnet 概述 Libnet是一个小型的接口函数库,主要用C语言写成,提供了底层网络数据报的构造、处理和发送功能。 Libnet的开发目的是:建立一个简单统一的网络编程接口以屏蔽不同操作系统底层网络编程的差别。 Libnet的主要特点: 高层接口 可移植性 数据报构造 数据报的处理 数据报发送 Libnet库提供的接口函数包含15种数据包生成器和两种数据包发送器(IP层和数据链路层)。 提供的接口函数包括: 内存管理(分配和释放)函数 地址解析函数 各种协议类型的数据包构造函数 数据包发送函数(IP层和链路层) 一些辅助函数,如产生随机数、错误报告、端口列表管理等 Libnet函数 1、内存管理函数 2、地址解析函数 3、数据包构造函数 4、数据包发送函数 5、相关支持函数 6、数据常量 ARP协议数据包 int libnet_build_arp(u_short hrdw, u_short prot, u_short h_len,u_short p_len, u_short op, u_char *s_ha, u_char *s_pa, u_char *t_ha, u_char *t_pa, const u_char *payload, int payload_len, u_char *packet_buf); 构造ARP协议数据包 libnet_build_arp( ARPHRD_ETHER, /* 硬件地址 */ ETHERTYPE_IP, /* IP地址 */ 6, /* 硬件地址长度 */ 4, /* IP地址长度 */ ARPOP_REPLY, /* 操作类型 */ enet_src, /* 源硬件地址 */ ip_src, /* 源IP地址 */ enet_dst, /* 目的硬件地址 */ ip_dst, /* 目的IP地址 */ NULL, /* 有效载荷 */ 0, /* 有效载荷大小 */ packet); /* 包缓冲 */ IP协议数据包 int libnet_build_ip(u_short len, u_char tos, u_short ip_id, u_short frag, u_char ttl, u_char protocol, u_long saddr, u_long daddr, const u_char *payload, int payload_len,u_char *packet_buf); 构造IP协议数据包 libnet_build_ip(LIBNET_IP_H, /* 首部大小 */ IPTOS_LOWDELAY, /* 服务类型 */ 242, /* 标识 */ 0, /* 标志 */ 48, /* 生存时间 */ IPPROTO_TCP, /* 协议 */ src_ip, /* 源IP 地址 */ dst_ip, /* 目的IP 地址 */ NULL, /* 有效载荷 */ 0, /* 有效载荷大小 */ packet); /* 包缓冲 */ TCP协议数据包 int libnet_build_tcp(u_short th_sport, u_short th_dport, u_long th_seq, u_long th_ack, u_char th_flags, u_short th_win, u_short th_urg, const u_char *payload, int payload_len, u_char *packet_buf); 构造TCP协议数据包 libnet_build_tcp(src_prt, /* 源端口 */ dst_prt, /* 目的端口 */ 0xa1d95, /* 序号 */ 0x53, /* 确认号 */

文档评论(0)

1亿VIP精品文档

相关文档