Lazarus

Free Pascal => General => Topic started by: RegNatarajan on March 23, 2017, 04:41:24 am

Title: PCAP/libpcap Programming with FPC/Lazarus
Post by: RegNatarajan on March 23, 2017, 04:41:24 am
Hello,

There are a couple of old threads mentioning PCAP programming on this forum but there doesn't seem to be anything recent.  I wonder if any of you can point me to some recent information.  Right now, on Ubuntu with Lazarus, I've just tried to do a hello world application with pcap in the uses clause and it fails to link.

TIA
Reg

Title: Re: PCAP/libpcap Programming with FPC/Lazarus
Post by: Thaddy on March 23, 2017, 07:43:43 am
Those examples simply work. Just checked that.
I think you do not have libpcap-dev installed. apt-get update && apt-get install libpcap libpcap-dev
Title: Re: PCAP/libpcap Programming with FPC/Lazarus
Post by: eMko on March 23, 2017, 07:47:03 am
Hi, this can be million and one thing. The FP pcap looks like just a wrapper around the unix pcap library (or WinPcap on windows). Do you have this library on your computer? On Ubuntu there can be a package named something like libpcap-devel.

If it hasn't changed recently, FPC doesn't support linking a static library (libpcap.a), you must compile it as a dynamic library (.so/.dll). If you have the .so or .dll on your computer, check whether it's in $PATH or the pcap unit tries to load it under correct name. If you do have the library on your computer and just can't make it work with FPC, it's often easier to write the needed functionality in C++, make a nice interface around it and compile it as dll. Then you can use it from Lazarus.

Sorry to say it so openly, but many libraries are just undermaintained, underdocumented and a pain to use.
Title: Re: PCAP/libpcap Programming with FPC/Lazarus
Post by: Thaddy on March 23, 2017, 12:24:30 pm
On Ubuntu there can be a package named something like libpcap-devel.
No it isn't. It is called libpcap-dev on Ubuntu.
Quote
If it hasn't changed recently, FPC doesn't support linking a static library (libpcap.a),
FPC supports it. Why do you think otherwise? Have you looked at FPC since version 1.9 or so?
It takes some more effort but it works with the proper headers.
I would recommend to use a shared library, though. You're messing with the TCP/IP stack.
Quote
Sorry to say it so openly, but many libraries are just undermaintained, underdocumented and a pain to use.
Shut up and first try. PCAP is fully documented, but it is not for beginners. Never has been.

Ignore him. Do what I suggested and you are fine. I can post a small example if you want, but the existing examples work just fine.
Title: Re: PCAP/libpcap Programming with FPC/Lazarus
Post by: RegNatarajan on March 28, 2017, 05:44:35 am
Thanks, Thaddy.  It was as simple as apt-get install libpcap-dev

Really appreciate all the help.

If someone could point me to the examples, I'd appreciate that, too. 

Best,
Reg
Title: Re: PCAP/libpcap Programming with FPC/Lazarus
Post by: Thaddy on March 28, 2017, 06:45:15 am
You can make most Delphi examples cross-platform, but I will post some small examples later.
TinyPortal © 2005-2018