首页 > 其他分享 >libnet 函数列表

libnet 函数列表

时间:2022-09-28 20:02:11浏览次数:80  
标签:libnet short 函数 int 列表 char 数据包 payload


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


转自:​​底层网络开发库之libnet​​ 

标签:libnet,short,函数,int,列表,char,数据包,payload
From: https://blog.51cto.com/u_3002289/5720766

相关文章

  • golang之Time时间函数
    总结常用time包下的方法1)获取前一天的时间packagemainimport"time"nowTime:=time.Now()yesterdayTime:=nowTime.AddDate(0,0,-1);//年,月,日获取前一......
  • python-函数的参数与返回值
    Python函数4.1、函数初识在编写程序的过程中,有某一功能代码块出现多次,但是为了提高编写的效率以及代码的重用,所以把具有独立功能的代码块组织为一个小模块,这就是函数就......
  • python-面向过程与函数式
    面向过程与函数式面向过程”面向过程“核心是“过程”二字,“过程”指的是解决问题的步骤,即先干什么再干什么......,基于面向过程开发程序就好比在设计一条流水线,是一种机......
  • Go基础编程:自定义函数
    定义格式函数构成代码执行的逻辑结构。在Go语言中,函数的基本组成为:关键字func、函数名、参数列表、返回值、函数体和返回语句。Go语言函数定义格式如下:funcFuncName(/*参......
  • Go基础编程:递归函数、函数类型、匿名函数与闭包
    1.递归函数递归指函数可以直接或间接的调用自身。递归函数通常有相同的结构:一个跳出条件和一个递归体。所谓跳出条件就是根据传入的参数判断是否需要停止递归,而递归体则是......
  • qt的基本控件——列表控件
    列表控件1、listWIdgetQListWidget类列表框控件用来加载并显示多个列表项。QListWidgetItem类就是列表项类双击可以直接修改,添加多少行,也有属性可以修改字体颜色大小等......
  • #打卡不停更# OpenHarmony-ArkUI(TS)声明式开发之列表拖动排列
    作者:梁青松项目介绍本项目基于OpenHarmony的ArkUI框架:TS扩展的声明式开发范式,关于语法和概念直接看官网官方文档地址:基于TS扩展的声明式开发范式,因为OpenHarmony的API相对......
  • 攻防世界ics-05(PHP伪协议读取文件+preg_replace函数任意代码执行)
    第一步通过index.php?page=php://filter/convert.base64-encode/resource=index.php来获取源码,第二步审计源代码发现了  这里进入if只需在http请求头中加入X-Forwar......
  • 【PE806】Nim on Towers of Hanoi(DP)(生成函数)
    NimonTowersofHanoi题目链接:PE806题目大意一个有n个盘子的汉诺塔,在第i个状态的时候如果三个柱子的盘子个数的异或和是0,就会给i的贡献。求n=100000时候的......
  • java8实战三:函数式数据处理--流
    函数式数据处理(一)–流引入流集合是Java中使用最多的API。要是没有集合,还能做什么呢?几乎每个Java应用程序都会制造和处理集合。集合对于很多编程任务来说都是非常基本的:......