Can anyone walk me through how, for example, the binding between
libpcap-ruby and libpcap? If I look at pcaplet and pcap_misc, I notice
that ‘pcap’ is required. Is this another Ruby file (that I can’t find)
or is this referencing the libpcap C library directly?
If anyone can explain to me how this works I’d greatly appreciate it.
There’s a good chance I’ll need to be binding to C code from Ruby in the
near future and I’d like to understand the best way to go about doing
so.
Kernel#require can load both another Ruby file or a Ruby extension.
Ruby extensions are shared libraries that are required to have at
least one certain method in them:
extension.c
void Init_extension() {
… initialization code here …
}
builds into extension.so (on Linux, extension.dll on Windows)
Then you can
require ‘extension’
and start using whatever the library has made available. In the case
of libpcap-ruby, there’s a pcap.so file somewhere in your system (I’m
assuming you apt-get installed it, or the related on your system)
that’s accessible by Ruby.