I want to use methods in tshark in my program. So I want to build tshark as a library. How can I do this? Thank you for anyone's help in advance. more detalis:
asked 24 Jun '15, 02:46 David Zhou edited 25 Jun '15, 19:58 |
2 Answers:
To make tshark a library you'll have to hack whatever build system you're using, e.g. autotools, CMake or nmake. However I still question the usefulness of this. A library is a collection of functions that allows library users to achieve some result. tshark doesn't have any of this, its a command line parser that then calls the real libraries, libwireshark and libwiretap to do some work. I think you should reconsider either using tshark as a spawned process, providing it the required command line options to do what you want and parsing the output, or use libwireshark and libwiretap directly, which isn't very easy at all as they're not designed to be general purpose libraries. You also haven't indicated exactly what you wish to achieve, if you do that we may be able to suggest a better approach. answered 25 Jun '15, 09:15 grahamb ♦
...and hack the code as well. It was written to be a program, not a library. (25 Jun '15, 13:14) Guy Harris ♦♦ @grahamb, Thank you for the information. I've provided more details, appending to my question. Please check that. I appreciate your help. Thank you. (25 Jun '15, 19:46) David Zhou @David Zhou
Are you aware that tshark is a console application printing to STDOUT? It's by far not enough to rename main() to get a library. Large parts of the code structure would have to be changed for that. Why don't you call the tshark binary from your code (execve) and parse the output. Way less trouble for you. Plus, you would have to do the parsing part anyway, even if you (somehow) manage to press the tshark functionality into a library, because tshark would then still do the same as the console application, outputting a text representation of the dissected frames. (26 Jun '15, 00:04) Kurt Knochner ♦ @Kurt Knochner, Thank you for your attention. To execute tshark from my program as a spawn process is an option that I've already considered and abandoned. In this case, If the pcap file is extremely large(big chance), the spawn process will last a long time without output in STDOUT and my father program has no idea what's going on. This will lead to chaos. I've also hacked tshark. I made some changes based on tshark code and now, when I run command "tshark -r xxx.pcap", nothing will be output on STDOUT but it will do some test analysis on dissected frames. So if you have more information on how to generate libtshark.so/libtshark.a, I appreciate it you could share with me. Thank you. (26 Jun '15, 01:57) David Zhou |
After weeks of torture, I've made libtshark.so for my tool and they work well together. Here I share the process for people wanting tshark library. summary
detailstshark.c
1.modify: main() => tshark() ./Makefile.am 5.modify "if ENABLE_STATIC" macro 6.add libtshark.a and libtshark.la to CLEANFILES 7.add libtshark_la_LIBADD like this
./Makefile.common
./ui/Makefile.am
./ui/cli/Makefile.am
./ui/gtk/Makefile.am
./ui/gtk/Makefile.common
automake under ./#./configure --disable-dftest --disable-rawshark#make (after this,you have your libtshark.so)to use it up, you need to do more. remember to copy this header file under your libtshark directory before you build it.2.link libtshark.so to your program 3.call tshark function like this, for example: 4.when you build your program with libtshark.so, there might be some undefined reference err when it went with link command. Just comment related lines in your libtshark codes and rebuild. 5.before you execute your program, make sure your LD_LIBRARY_PATH have the path to the libtshark.so. 6.Now you should see your program can output like tshark does.After all above, you can do your business with libtshark.so, like if you want to get the contents above TCP layer in each packets and replay them, just save the contents in a linked-list where it prints the protocol tree in tshark and return the list back to your program. Then you can do your replay logic in your program.I will be happy if this help anyone else. If you have trouble with the process, please send me email:[email protected]answered 07 Jul '15, 06:23 David Zhou edited 07 Jul '15, 06:27 |
Do you actually mean tshark, or the wireshark dissection engine in libwireshark or the capture file reading\writing tools in libwiretap?
The tshark executable basically parses command line options and then calls into libwireshark\libwiretap as required.
@grahamb, Thank you for your reply. yes, I mean tshark. I know tshark implement some methods like "process_packet()" to deal with *.pcap files, spliting ethernet layer/IP layer/TCP layer, etc. And I know these methods in tshark are based on some interfaces from libwireshark and libwiretap.
So I need to use the functions in tshark in my program and I'm trying to make tshark as a shared library. Could you please help me on this? Thank you.