* * *

Author Topic: PCAP/libpcap Programming with FPC/Lazarus  (Read 987 times)

RegNatarajan

  • New member
  • *
  • Posts: 28
PCAP/libpcap Programming with FPC/Lazarus
« 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

« Last Edit: March 23, 2017, 04:44:15 am by RegNatarajan »

Thaddy

  • Hero Member
  • *****
  • Posts: 4413
Re: PCAP/libpcap Programming with FPC/Lazarus
« Reply #1 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
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

eMko

  • New member
  • *
  • Posts: 13
Re: PCAP/libpcap Programming with FPC/Lazarus
« Reply #2 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.
« Last Edit: March 23, 2017, 07:48:35 am by eMko »

Thaddy

  • Hero Member
  • *****
  • Posts: 4413
Re: PCAP/libpcap Programming with FPC/Lazarus
« Reply #3 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.
« Last Edit: March 23, 2017, 12:27:19 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

RegNatarajan

  • New member
  • *
  • Posts: 28
Re: PCAP/libpcap Programming with FPC/Lazarus
« Reply #4 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

Thaddy

  • Hero Member
  • *****
  • Posts: 4413
Re: PCAP/libpcap Programming with FPC/Lazarus
« Reply #5 on: March 28, 2017, 06:45:15 am »
You can make most Delphi examples cross-platform, but I will post some small examples later.
« Last Edit: March 28, 2017, 07:00:30 am by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus