News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Marcelo Gornstein's Blog:
Sniffing in PHP using libpcap Thank you SWIG!
February 21, 2012 @ 10:13:34

Marcelo Gornstein has posted a new article showing how to use SWIG and libpcap to sniff packets from the network directly from his PHP application.

I've been wanting to try SWIG for a long time, but never got the chance, for one thing or the other. So this weekend I've finally decided to give it a try by trying to create a php extension that access a small C++ wrapper for libpcap, so I can sniff packets directly from PHP. Just for fun (and actually because I couldn't find any active pecl extension to use libpcap, so it might as well be something useful). I've named it "SimplePcap".

He includes both the sample code showing the extension's usage and an example of the output from his local "eth0" device. His PHP script uses SWIG to interface with the pcap_t/Packet class structure via this interface file and typemap.

SWIG is really great. I just did some C++ code and then worried about how to integrate it to PHP. Althought it seems that you really need lots of experience with it to actually do more advanced things in the right way. [...] So I guess that sometimes it's more productive to just make the PHP extension than using SWIG. But if you want your code to be run in many languages, this is definitely an excellent library to try!
0 comments voice your opinion now!
libpcap sniff packet swig c extension tutorial library



Community Events





Don't see your event here?
Let us know!


library symfony framework composer opinion mvc voicesoftheelephpant security series introduction tool package podcast interview update language release version community laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework