首页 > 编程知识 正文

tshark性能,编码器解码器神经网络

时间:2023-05-04 11:49:56 阅读:18874 作者:3373

在网上找不到好的tshark源代码解析资源,自己摆弄做笔记吧。

本文基于tshark.c,来源于wirshark 3.2.4。

tshark介绍了tshark是wireshark的命令行版本。 安装wireshark后,tshark -h将提供完整的参数说明。 安装目录下的tshark.html提供了更详细的说明。 本文不关注tshark的使用,而是为改造tshark准备源代码。

本文tshark源代码分析的热点tshark源代码在当前版本中已达4000行。 出于个人原因,本文只关注脱机文件分析的部分,而不是tshark的完整分析。

tshark的总体结构tshark包括全局变量、辅助函数和main函数三个主要部分,main函数包括初始化、命令行参数分析、数据包获取、数据包分析、协议分析结果打印的几个主要部分。

main初始化setlocale(LC_all,''); cmd arg _ err _ init (failure _ warning _ message,failure_message_cont ); init_process_policies (; relinquish_special_privs_perm (; print_current_user (; err _ msg=init _ progfile _ dir (argv [0]; initialize_funnel_ops (; timestamp_set_type(ts_relative; timestamp _ set _ precision (ts _ prec _ auto; timestamp _ set _ seconds _ type (ts _ seconds _ default; wtap_init(true;/*注册器all dissector s; wemustdothisbeforecheckingforthe '-g ' flag,as the '-g ' flagdumpsinformationregisteredbythedisssectors,andwemustdoitbefefefytors Epan_init(NULL、null、TRUE ) { exit_status=INIT_FAILED; goto clean_exit; (}/*注册所有标签监听器; wedothisbeforeweparsethearguments, as the '-z ' argumentcanspecifyaregisteredtap.*//* weregistertheplugintapsbeforetheothertapsbecausestats _ treetapspluginswillberegisteredastaplistenersbystats _ tree _ start # endifextcap _ register _ preferences (;/*注册ltaplisteners.*/for (tap _ reg _ t * t=tap _ reg _ listener; t-cb_func!=NULL; t(t-CB_func ); }转换_ table _ set _ GUI _ info (init _ io users ); 主机列表_ table _ set _ GUI _ info (init _ host lists ); SRT _ table _ iterate _ tables (register _ SRT _ tables,NULL ); RTD _ table _ iterate _ tables (register _ RTD _ tables,NULL ); stat _ tap _ iterate _ tables (register _ simple _ stat _ tables,NULL );/* loadlibwiresharksettingsfromthecurrentprofile.*/prefs _ p=epan _ load _ settings (; prefs_loaded=TRUE; read_filter_list(cfilter_list; CAP_file_init(cfile; 命令行分析命令行参数的分析与pcap分析相关联的参数如-r、-Y和-J,与输出相关联的参数如-T和-e,这些参数在分析过程中设置一些控制变量或编译为内部状态

/* nowgetourargs */while ((opt=getopt _ long ) argv、argv、optstring、long_options、NULL ) )!=-1 )数据包的获取和分析pcap数据的获取和分析通过以下代码进行。 cf_name是通过-r参数获取的pcap文件路径,cf_open函数位于tshark.c中,用于打开cf_name指向的文件并将相关信息写入cfile。 cfile是capture_file结构,包含许多信息,如RF代码

if(cf_name ) tshark _ debug (tshark : openingcapturefile : % s ',cf_name );/* * we ' rereadingacapturefile.*/if (cf _ open (cfile,cf_name,in_file_type,FALSE,err )!=cf_ok(Epan_cleanup ); extcap_cleanup (; exit_status=INVALID_FILE; goto clean_exit; (}/*开始状态类型; wedosoaftersuccessfullyopeningthecapturefile,soweknowwehavesomethingtocomputestatson,andafterregisteringallldissectors, sothatmatewillhaveregistereditsfieldarraysowecanhaveatapfilterwithoneofmate ' slate-registeredfieldsaspartofthefilter.*//That depends on,among other things,what taps are listening, sodeterminethatafterstartingthestatisticstaps.*/do _ dissection/* processthepacketsinthefile */tshark _ debug () try { status=process _ cap _ file (cfile,output_file_name,out_file_type,out_file_name_res,ma 此函数的主要逻辑代码如下: epan_dissect_new初始化协议解析器,wtap_read逐个读取包,并将处理传递给process_packet_single_pass。

EDT=EPAN_dissect_new(cf-EPAN,create_proto_tree,print_packet_info print_details ); while (wtap _ read (cf-provider.wth,rec,buf,err,err_info,data_offset ) ) { framenum; tshark _ debug (tshark :处理包# % d ',framenum ); reset_Epan_mem(cf,edt,create_proto_tree,print_packet_info print_details ); if (process _ packet _ single _ pass (cf,edt,data_offset,rec,buf,tap_flags ) )是process _ packet _ flags

epan _ dissect _ file _ run _ with _ taps (EDT,rec,frame_TVbuff_new ) cf-provider,fdata,pd ),fdata,CD

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。