我在C中为Wireshark创建一个解剖器,用于UDP之上的协议。由于我使用启发式解剖但是另一个协议与我的同一端口的标准解剖器存在,我的数据包正在被解析为其他协议。为了让我的解剖器工作,我需要先启用"尝试启发式解剖器" UDP首选项,但我希望在我的插件注册时(在代码中)更改该属性,因此用户无需手动更改它。 我注意到在epan / prefs.h上,函数 prefs_set_pref 存在!但是当我在我的插件上使用它时,Wireshark在启动时因总线错误10而崩溃。 我想做的事情/正确吗?
所以我试过这个:
G_MODULE_EXPORT void plugin_register(void){
prefs_set_pref("udp.try_heuristic_first:true");
// My proto_register goes here
}
因为epan / prefs.h有:
/*
* Given a string of the form "<pref name>:<pref value>", as might appear
* as an argument to a "-o" option, parse it and set the preference in
* question. Return an indication of whether it succeeded or failed
* in some fashion.
*
* XXX - should supply, for syntax errors, a detailed explanation of
* the syntax error.
*/
WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg);
由于
答案 0 :(得分:0)
在测试Wireshark插件中调用prefs_set_pref("udp.try_heuristic_first:true");
对我有用。
好的:假设没有其他问题,我预计问题是prefs_set_pref()
修改了传递给它的字符串。
如果传递了字符串文字(的地址),代码将尝试修改通常不允许的文字。我怀疑这是你的原因 总线错误10。
(我必须深入了解为什么我在Windows上的测试确实有效)。
所以:我建议尝试类似的事情:
char foo[] = {"udp.try_heuristic_first:true"};
...
prefs_set_pref(foo);
看看是否有效; 或者:对本地数组执行文字的strcpy。
==============
(早期原始评论)
一些意见/问题:
G_MODULE_EXPORT
的内容是什么?
现有的Wireshark插件解剖器都没有使用它。
(请参阅解剖器Wireshark源代码树中plugins
下的任何解剖器)。
插件注册函数需要命名为proto_register_???
???
是你的插件解剖器的名称。
所以:我不明白整个G_MODULE_EXPORT void plugin_register(void){
&amp;等
对prefs_set_prefs()
的调用应该在proto_reg_handoff_???()
函数中(而不是在proto_register_???
函数中)。