多平台网络编程库libnet

libnet

求助编辑百科名片

libnet是一个小型的接口函数库,主要用C语言写成,提供了低层网络数据包的构造、处理和发送功能。libnet的开发目的是:建立一个简单统一的网络编程接口以屏蔽不同操作系统底层网络编程的差别,使得程序员将精力集中在解决关键问题上。

编辑本段libnet

   它的主要特点是:
  高层接口:libnet主要用C语言写成
   可移植性:libnet目前可以在Linux、FreeBSD、Solaris、WindowsNT等操作系统上运行,并且提供了统一的接口
   数据包构造:libnet提供了一系列的TCP/IP数据 报文构造函数以方便用户使用
   数据包的处理:libnet提供了一系列的辅助函数,利用这些辅助函数,帮助用户简化那些烦琐的事务性的编程工作
   数据包发送:libnet允许用户在两种不同的数据包发送方法中选择。
  另外libnet允许程序获得对 数据包的绝对的控制,其中一些是传统的网络 程序接口所不提供的。这也是
  libnet的魅力之一。
  libnet支持TCP/IP协议族中的多种协议,
  比如其上一个版本libnet1.0支持了10种协议,
  一些新的协议,比如对IPV6的支持还在开发之中。
  libnet目前最新的版本是1.1.2.1版本,
  在该版本中,作者将这些函数做了进一步的封装,
  用户的使用步骤也得到了进一步的简化。
  内存的初始化、管理、释放等以及校验和的计算等函数,
  在默认情况下,都无须用户直接干预,使得libnet的使用更为方便。
  作者还提供了基于老版本的应用程序移植到新版本上的方法指导。
  -----------------------------------------------------------------------------------------------------------------------------
  libnet库的1.0.0版本,共约7600行C 源代码,33个 源程序文件,12个C头文件
  ,50余个自定义函数,提供的 接口函数包含15种数据包生成器和两种数据包发送器(IP层
  和 数据链路层)。目前只支持IPv4,不支持IPv6。已经过测试的系统平台包括:
  * OpenBSD 2.6snap, 2.5, 2.4, 2.3, 2.2 (i386)
  * FreeBSD 4.0-STABLE, 3.3-STABLE, 3.2-RELEASE, 3.1-CURRENT, 3.0, 2.2 (i386)
  * NetBSD 1.3.2 (i386)
  * BSD/OS 3.x (i386)
  * BSDi 3.0 (i386)
  * Linux 2.2.x, 2.0.3x, 2.1.124 (i386, alpha) (libc: 2.4.x, glibc: 2.0.x)
  * Solaris 7 (SPARC, gcc 2.7.2[13], 2.8.2), 2.6 (SPARC, gcc 2.8.2),
  2.5.x (SPARC, gcc 2.7.2[13])
  * IRIX 6.2
  * MacOS 5.3rhapsody (powerpc)
  libnet提供的 接口函数按其作用可分为四类:
   * 内存管理(分配和释放)函数  *地址解析函数  * 数据包构造函数  * 数据包发送函数

编辑本段接口函数及其功能

  以下分别列出这些接口函数及其功能(其参数含义简单易懂,不再解释):

内存管理函数

  单数据包内存初始化:
  int libnet_init_packet(u_short packet_size, u_char **buf);
  单数据包内存释放:
  void libnet_destroy_packet(u_char **buf);
  多数据包内存初始化:
  int libnet_init_packet_arena(struct libnet_arena **arena,
  u_short packet_num, u_short packet_size);
  访问多数据包内存中的下一个数据包:
  u_char *libnet_next_packet_from_arena(struct libnet_arena **arena,
  u_short packet_size);
  多数据包内存释放:
  void libnet_destroy_packet_arena(struct libnet_arena **arena);

地址解析函数

  解析 主机名
  u_char *libnet_host_lookup(u_long ip, u_short use_name);
  解析 主机名( 可重入函数):
  void libnet_host_lookup_r(u_long ip, u_short use_name, u_char *buf);
  域名解析:
  u_long libnet_name_resolve(u_char *ip, u_short use_name);
  获取接口设备IP地址:
  u_long libnet_get_ipaddr(struct libnet_link_int *l,
  const u_char *device, const u_char *ebuf);
  获取接口设备硬件地址:
  struct ether_addr *libnet_get_hwaddr(struct libnet_link_int *l,
  const u_char *device,
  const u_char *ebuf);

数据包构造函数

  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);
  DNS协议数据包:
  int libnet_build_dns(u_short id, u_short flags, u_short num_q,
  u_short num_answ_rr, u_short num_auth_rr,
  u_short num_add_rr, const u_char * payload,
  int payload_len, u_char *packet_buf);
   以太网协议数据包:
  int libnet_build_ethernet(u_char *daddr, u_char *saddr, u_short id,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  ICMP协议数据包(ICMP_ECHO / ICMP_ECHOREPLY):
  int libnet_build_icmp_echo(u_char type, u_char code, u_short id,
  u_short seq, const u_char *payload,
  int payload_len, u_char *packet_buf);
  ICMP协议数据包(ICMP_MASKREQ / ICMP_MASKREPLY):
  int libnet_build_icmp_mask(u_char type, u_char code, u_short id,
  u_short seq, u_long mask,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  ICMP协议数据包(ICMP_UNREACH):
  int libnet_build_icmp_unreach(u_char type, u_char code,
  u_short orig_len, u_char orig_tos,
  u_short orig_id, u_short orig_frag,
  u_char orig_ttl, u_char orig_prot,
  u_long orig_saddr, u_long orig_daddr,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  ICMP协议数据包(ICMP_TIMEXCEED):
  int libnet_build_icmp_timeexceed(u_char type, u_char code,
  u_short orig_len, u_char orig_tos,
  u_short orig_id, u_short orig_frag,
  u_char orig_ttl, u_char orig_prot,
  u_long orig_saddr, u_long orig_daddr,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  ICMP协议数据包(ICMP_REDIRECT):
  int libnet_build_icmp_redirect(u_char type, u_char code, u_long gateway,
  u_short orig_len, u_char orig_tos,
  u_short orig_id, u_short orig_frag,
  u_char orig_ttl, u_char orig_prot,
  u_long orig_saddr, u_long orig_daddr,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  ICMP协议数据包(ICMP_TSTAMP / ICMP_TSTAMPREPLY):
  int libnet_build_icmp_timestamp(u_char type, u_char code, u_short id,
  u_short seq, n_time otime, n_time rtime,
  n_time ttime, const u_char *payload,
  int payload_len, u_char *packet_buf);
  IGMP协议数据包:
  int libnet_build_igmp(u_char type, u_char code, u_long ip,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  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);
  OSPF路由协议数据包:
  int libnet_build_ospf(u_short len, u_char type, u_long router_id,
  u_long area_id, u_short auth_type,
  const char *payload, int payload_s, u_char *buf);
  OSPF路由协议数据包(Hello):
  int libnet_build_ospf_hello(u_long netmask, u_short interval,
  u_char options, u_char priority,
  u_int dead_interval, u_long des_router,
  u_long backup, u_long neighbor,
  const char *payload, int payload_s,
  u_char *buf);
  OSPF路由协议数据包(DataBase Description (DBD)):
  int libnet_build_ospf_dbd(u_short len, u_char options, u_char type,
  u_int sequence_num, const char *payload,
  int payload_s, u_char *buf);
  OSPF路由协议数据包(Link State Request (LSR)):
  int libnet_build_ospf_lsr(u_int type, u_int ls_id, u_long adv_router,
  const char *payload, int payload_s,
  u_char *buf);
  OSPF路由协议数据包(Link State Update (LSU)):
  int libnet_build_ospf_lsu(u_int num, const char *payload,
  int payload_s, u_char *buf);
  OSPF路由协议数据包(Link State Acknowledgement (LSA)):
  int libnet_build_ospf_lsa(u_short age, u_char options, u_char type,
  u_int ls_id, u_long adv_router,
  u_int sequence_num, u_short len,
  const char *payload, int payload_s,
  u_char *buf);
  OSPF路由协议数据包(OSPF Link Sate NetworkLink State Router):
  int libnet_build_ospf_lsa_net(u_long netmask, u_int router_id,
  const char *payload, int payload_s,
  u_char *buf);
  OSPF路由协议数据包(Link State Router):
  int libnet_build_ospf_lsa_rtr(u_short flags, u_short num, u_int id,
  u_int data, u_char type, u_char tos,
  u_short metric, const char *payload,
  int payload_s, u_char *buf);
  OSPF路由协议数据包(Link State Summary):
  int libnet_build_ospf_lsa_sum(u_long netmask, u_int metric, u_int tos,
  const char *payload, int payload_s,
  u_char *buf);
  OSPF路由协议数据包(Link State AS External):
  int libnet_build_ospf_lsa_as(u_long netmask, u_int metric,
  u_long fwd_addr, u_int tag,
  const char *payload, int payload_s,
  u_char *buf);
  RIP路由协议数据包:
  int libnet_build_rip(u_char cmd, u_char ver, u_short domain,
  u_short addr_fam, u_short route_tag, u_long ip,
  u_long mask, u_long next_hop, u_long metric,
  const u_char *payload, int payload_len,
  u_char *packet_buf);
  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);
  UDP协议数据包:
  int libnet_build_udp(u_short sport, u_short dport, const u_char *payload,
  int payload_len, u_char *packet_buf);
  IP协议数据包选项:
  int libnet_insert_ipo(struct ipoption *opt, u_char opt_len,
  u_char *packet_buf);
  TCP协议数据包选项:
  int libnet_insert_tcpo(struct tcpoption *opt, u_char opt_len,
  u_char *packet_buf);

数据包发送函数

  打开raw socket:
  int libnet_open_raw_sock(int protocol);
  关闭raw socket:
  int libnet_close_raw_sock(int socket);
  选择接口设备:
  int libnet_select_device(struct sockaddr_in *sin,
  u_char **device, u_char *ebuf);
  打开 链路层接口设备:
  struct libnet_link_int *libnet_open_link_interface(char *device,
  char *ebuf);
  关闭 链路层接口设备:
  int libnet_close_link_interface(struct libnet_link_int *l);
  发送IP数据包:
  int libnet_write_ip(int socket, u_char *packet, int packet_size);
  发送链路层 数据包
  int libnet_write_link_layer(struct libnet_link_int *l,
  const u_char *device, u_char *packet,
  int packet_size);
  检验和计算:
  int libnet_do_checksum(u_char *packet, int protocol, int packet_size);

相关的支持函数

  随机数种子生成器:
  int libnet_seed_prand();
  获取随机数:
  u_long libnet_get_prand(int modulus);
  16进制 数据输出
  void libnet_hex_dump(u_char * buf, int len, int swap, FILE *stream);
  端口列表链初始化:
  int libnet_plist_chain_new(struct libnet_plist_chain **plist,
  char *token_list);
  获取端口列表链的下一项(端口范围):
  int libnet_plist_chain_next_pair(struct libnet_plist_chain *plist,
  u_short *bport, u_short *eport);
  端口列表链输出显示:
  int libnet_plist_chain_dump(struct libnet_plist_chain *plist);
  获取端口列表链:
  u_char *libnet_plist_chain_dump_string(struct libnet_plist_chain *plist);
  端口列表链内存释放:
  void libnet_plist_chain_free(struct libnet_plist_chain *plist);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的记忆游戏(附源代码)   项目:JavaScript 记忆游戏(附源代码) 记忆检查游戏是一个使用 HTML5、CSS 和 JavaScript 开发的简单项目。这个游戏是关于测试你的短期 记忆技能。玩这个游戏 时,一系列图像会出现在一个盒子形状的区域中 。玩家必须找到两个相同的图像并单击它们以使它们消失。 如何运行游戏? 记忆游戏项目仅包含 HTML、CSS 和 JavaScript。谈到此游戏的功能,用户必须单击两个相同的图像才能使它们消失。 点击卡片或按下键盘键,通过 2 乘 2 旋转来重建鸟儿对,并发现隐藏在下面的图像! 如果翻开的牌面相同(一对),您就赢了,并且该对牌将从游戏中消失! 否则,卡片会自动翻面朝下,您需要重新尝试! 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,通过单击 memorygame-index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值