I've got a GPS tracker which is sending two packets to my server. First of them contains OBD data, in the second one we can find coordinates. I have an application which is listening on specific port (Traccar) however it is capturing only the second packet (support for packets without coordinates is not implemented yet). I'd like to capture these packets, read the OBD data and insert them to an SQL database. I can do that manually by using tcpdump, but of course this is not the solution. What is the best and most efficient way to solve this problem? Should I use popen() to open a pipe to tcpdump? Is there any other way?
1 Answers
Piping' tcpdump: in my experience it's always risky to parse the output of a command/program. Output format may change depending on the version of the program, the platform it's running on, and the LOCALE used. These surprises come out when you're deploying the software.
For a bit more of coding, the second option would be to embed the gut of tcpdump, that is to says libpcap. It's not that hard, a quick introduction here:
http://www.tcpdump.org/pcap.html
...it would be cleaner, but still, like with tcpdump, you will be "naked on the wire", just seeing Ethernet frames, without the IP, TCP, UDP etc layers that you may need.
But these (tcpdump or libpcap) are workaround.
Since Traccar is open source, did you investigate the amount of work to add the feature you require? In this situation, I'd spend a couple of hours investigating that.

- 3,063
- 1
- 16
- 25
-
I don't have enough experience to work with an open source software such as Traccar. But I'm going to use the pcap library. Thanks for the suggestions. – Tomasz Kasperczyk Aug 24 '15 at 14:48