热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

libnet函数列表

nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd

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);


推荐阅读
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • Python语法上的区别及注意事项
    本文介绍了Python2x和Python3x在语法上的区别,包括print语句的变化、除法运算结果的不同、raw_input函数的替代、class写法的变化等。同时还介绍了Python脚本的解释程序的指定方法,以及在不同版本的Python中如何执行脚本。对于想要学习Python的人来说,本文提供了一些注意事项和技巧。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • Linux磁盘的分区、格式化的观察和操作步骤
    本文介绍了如何观察Linux磁盘的分区状态,使用lsblk命令列出系统上的所有磁盘列表,并解释了列表中各个字段的含义。同时,还介绍了使用parted命令列出磁盘的分区表类型和分区信息的方法。在进行磁盘分区操作时,根据分区表类型选择使用fdisk或gdisk命令,并提供了具体的分区步骤。通过本文,读者可以了解到Linux磁盘分区和格式化的基本知识和操作步骤。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
author-avatar
寒时凝结公寓_264
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有