Installing PCAP

Hi everyone. I have been having issues installing a few gems. PCAP is
one of them. I'll admit that my troubleshooting abilities are probably
not as up to par as some of the other folks here. Programing and ruby
are a side hobby. I have much to learn.

Here is the error I get when installing pcap

C:\Ruby193\include\ruby-1.9.1\i386-mingw32>gem install pcap
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pcap:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
checking for socket() in -lsocket... no
checking for gethostbyname() in -lxnet... no
checking for hstrerror()... no
checking for pcap.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Clearly I am missing some libraries but I not know how to get these nor
do I know where they should be located when attempting to install pcap.

Even when trying to override the WinCap header and library locations it
fails. If I make a new extconf.rb, extconf_a.rb, and hardcode the Pcap
header and library folders the message, "checking for pcap.h" succeeds
but the other checks continue to fail and Make as well fails.

Does anyone have any thoughts?

···

--
Posted via http://www.ruby-forum.com/.

Hi everyone. I have been having issues installing a few gems. PCAP is
one of them. I'll admit that my troubleshooting abilities are probably
not as up to par as some of the other folks here. Programing and ruby
are a side hobby. I have much to learn.

Here is the error I get when installing pcap

C:\Ruby193\include\ruby-1.9.1\i386-mingw32>gem install pcap
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pcap:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
checking for socket() in -lsocket... no
checking for gethostbyname() in -lxnet... no
checking for hstrerror()... no
checking for pcap.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Clearly I am missing some libraries but I not know how to get these nor
do I know where they should be located when attempting to install pcap.

Looks like you need the Windows version of libpcap headers/lib for this
to have any chance to work.

Searching for 'libpcap' led to http://www.tcpdump.org/ which as a link
to http://www.tcpdump.org/wpcap.html and another search for 'winpcap'
leads to http://www.winpcap.org/install/default.htm which says the
installer includes driver + DLLs.

Downloading and extracting the gem via

  gem fetch pcap
  gem unpack pcap-0.7.0.gem

gives you a `pcap-0.7.0\ext\extconf.rb` file containing

  pcap_dir = with_config("pcap-dir", "/usr/local")
  pcap_includedir = with_config("pcap-includedir", pcap_dir +
"/include")
  pcap_libdir = with_config("pcap-libdir", pcap_dir + "/lib"

so once you've installed WinPcap you should be able to try to build the
pcap gem again using something similar to the following but using the
dirs from your WinPcap install:

  gem install pcap -- --with-pcap-includedir="c:/devlibs/pcap/include"
--with-pcap-libdir="c:/devlibs/pcap/lib"

I've not tried installing pcap on Win7 with 1.9.3 but I suspect none of
this will work for you because the pcap 0.7.0 version is from 12/2009
(project may be dead) and it's README says it requires ruby 1.4.x.

Have you searched rubygems.org for 'pcap' and tried things like
https://github.com/shadowbq/pcaprub

If you try all these ideas and still can't get things to work (and no
one responds with a solution here) join us over at the RubyInstaller
list http://groups.google.com/group/rubyinstaller as Luis and others may
be able to help.

Jon

···

--
Posted via http://www.ruby-forum.com/.

Thanks Jon. I actually did have the wincap libraries and headers
installed. I tried using the "--with-pcap-includedir" argument. You are
right that pcap is fairly old. I tried pcaprub and also and ran into
issues.

I have the wincap lib and headers in C:\WpdPack. That is exactly where
extconf.rb is looking.

···

~~~~~~~
  pcap_dir = with_config("pcap-dir", "C:/WpdPack")
  pcap_includedir = with_config("pcap-includedir", pcap_dir +
"/include")
  pcap_libdir = with_config("pcap-libdir", pcap_dir + "/lib")

  have_library("wpcap", "pcap_open_live")
  have_library("wpcap", "pcap_setnonblock")

elsif /i386-mswin32/ =~ RUBY_PLATFORM
  pcap_dir = with_config("pcap-dir", "C:\\WpdPack")
  pcap_includedir = with_config("pcap-includedir", pcap_dir +
"\\include")
  pcap_libdir = with_config("pcap-libdir", pcap_dir + "\\lib")

  $CFLAGS = "-DWIN32 -I#{pcap_includedir}"
  $LDFLAGS = "/link /LIBPATH:#{pcap_libdir}"
  have_library("wpcap", "pcap_open_live")
  have_library("wpcap", "pcap_setnonblock")
else

~~~~~~~
WheN I try to gem install pcaprub I still get....

C:\Users\user>gem install pcaprub
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pcaprub:
        ERROR: Failed to build gem native extension.

        C:/Ruby192/bin/ruby.exe extconf.rb

[*] Running checks for pcaprub code...
platform is i386-mingw32
checking for main() in -lws2_32... yes
checking for main() in -liphlpapi... yes
checking for windows.h... yes
checking for winsock2.h... yes
checking for iphlpapi.h... yes
checking for pcap_open_live() in -lwpcap... no
checking for pcap_setnonblock() in -lwpcap... no
creating Makefile

make
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32
-I/C/Ruby192/include/ruby-1
.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H
-DHAVE_W
INSOCK2_H -DHAVE_IPHLPAPI_H -O3 -g -Wextra -Wno-unused-parameter
-Wno-parenth
eses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers
-Wno-long-l
ong -o pcaprub.o -c pcaprub.c
pcaprub.c:8:18: fatal error: pcap.h: No such file or directory
compilation terminated.
make: *** [pcaprub.o] Error 1

Gem files will remain installed in
C:/Ruby192/lib/ruby/gems/1.9.1/gems/pcaprub-0
.11.2 for inspection.
Results logged to
C:/Ruby192/lib/ruby/gems/1.9.1/gems/pcaprub-0.11.2/ext/pcaprub
/gem_make.out

C:\Users\user>

--
Posted via http://www.ruby-forum.com/.

Weird. It is complaining about the pcap.h file.

./pcap.h:45:23: fatal error: pcap/pcap.h: No such file or directory

Line 45 is
#include <pcap/pcap.h>

And inside the pcap folder is pcap.h

It is stated in the first pcap.h file.

/*
* For backwards compatibility.

···

*
* Note to OS vendors: do NOT get rid of this file! Many applications
* expect to be able to include <pcap.h>, and at least some of them
* go through contortions in their configure scripts to try to detect
* OSes that have "helpfully" moved pcap.h to <pcap/pcap.h> without
* leaving behind a <pcap.h> file.
*/

This should work. Unfortunately pcaprub was last updated in 2010. Know
of any other good pcap libs for ruby?

--
Posted via http://www.ruby-forum.com/.

AWESOME! By chance I noticed our fix was looking in
c:\devlib\wincap\include. However extracting the devpack puts it in
c:\devlib\wincap\wpdpack\

I moved everything in wpdpack up into wincap and the build process went
flawlessly. Running tests now...

···

--
Posted via http://www.ruby-forum.com/.

Yes. Everything appears to work!

irb(main):008:0> Pcap.singleton_methods.sort
=> [:lookupdev, :lookupnet, :new, :open_dead, :open_live, :open_offline,
:versio
n]
irb(main):009:0> require 'packetfu'
=> true
irb(main):010:0> Packetfu::VERSION
NameError: uninitialized constant Object::Packetfu
        from (irb):10
        from C:/Ruby192/bin/irb:12:in `<main>'
irb(main):011:0> PacketFu::VERSION
=> "1.1.5"
irb(main):012:0> PacketFu.pcaprub_loaded
NoMethodError: undefined method `pcaprub_loaded' for PacketFu:Module
        from (irb):12
        from C:/Ruby192/bin/irb:12:in `<main>'
irb(main):013:0> PacketFu.pcaprub_loaded?
=> true
irb(main):014:0>

Can you help me what you did in these two statements:

    $CFLAGS << " -DWIN32 -I#{pcap_includedir}"
    $LDFLAGS << " -L#{pcap_libdir}"

Which I assume is what ultimately fixed the issue?

···

--
Posted via http://www.ruby-forum.com/.

This should work. Unfortunately pcaprub was last updated in 2010. Know
of any other good pcap libs for ruby?

Sadly my WinPcap experience is limited to what Wireshark hides from me.

That said, I've just downloaded the WinPcap dev pack from
http://www.winpcap.org/devel.htm and will hopefully find time this
weekend to get the `pcap` and `packetfu` gems to work on my Win7 32bit
w/1.9.3 system.

From the thread I notice your `pcap` errors were with 1.9.3 but your
`pcaprub` failures were with 1.9.2.

How about starting a gist with all your system details, PATH, and
failure logs?

Jon

···

--
Posted via http://www.ruby-forum.com/.

Can you help me what you did in these two statements:

    $CFLAGS << " -DWIN32 -I#{pcap_includedir}"
    $LDFLAGS << " -L#{pcap_libdir}"

Which I assume is what ultimately fixed the issue?

Glad to hear it's working so far and interested on whether it really
grabs works when grabbing packet info.

The `-I` and `-L` to `$CFLAGS` basically tells the DevKit toolchain
(MSYS/MinGW based) where to look for the WinPcap headers and libraries
when building the pcaprub extension. A nit, but the `-I` option probably
should have been appended to `$INCFLAGS`.

The `-DWIN32` is needed because both the pcaprub and WinPap source
(incorrectly) check for the `WIN32` pre-processor macro as a proxy for
building on a Windows platform. The source should really be check the
`_WIN32` macro so one doesn't need to define `WIN32` and things just
work when building with MinGW, VC++ IDE, or Windows SDK.

Jon

···

--
Posted via http://www.ruby-forum.com/.

Cliff Rosson wrote in post #1041942:

AWESOME! By chance I noticed our fix was looking in
c:\devlib\wincap\include. However extracting the devpack puts it in
c:\devlib\wincap\wpdpack\

I moved everything in wpdpack up into wincap and the build process went
flawlessly. Running tests now...

C:\Ruby193\lib\ruby\gems\1.9.1\gems\pcaprub-0.11.2>gem install
pcaprub-0.11.3.a
.gem -- --with-pcap-dir=c:/devlibs/winpcap/include
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pcaprub-0.11.3.a1.gem:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
--with-pcap-dir=c:/devlibs/winpcap/i
clude

[*] Running checks for pcaprub code...
platform is i386-mingw32
checking for main() in -lws2_32... yes
checking for main() in -liphlpapi... yes
checking for windows.h... yes
checking for winsock2.h... yes
checking for iphlpapi.h... yes
checking for pcap_open_live() in -lwpcap... no
checking for pcap_setnonblock() in -lwpcap... no
creating Makefile

make
generating pcaprub-i386-mingw32.def
compiling pcaprub.c
pcaprub.c:8:18: fatal error: pcap.h: No such file or directory
compilation terminated.
make: *** [pcaprub.o] Error 1

Gem files will remain installed in
C:/Ruby193/lib/ruby/gems/1.9.1/gems/pcaprub-
.11.3.a1 for inspection.
Results logged to
C:/Ruby193/lib/ruby/gems/1.9.1/gems/pcaprub-0.11.3.a1/ext/pca
rub/gem_make.out

···

--
Posted via http://www.ruby-forum.com/.

That said, I've just downloaded the WinPcap dev pack from
http://www.winpcap.org/devel.htm and will hopefully find time this
weekend to get the `pcap` and `packetfu` gems to work on my Win7 32bit
w/1.9.3 system.

See if this quick hack will get you up and running. The real solution
would be to update the project to use
https://github.com/luislavena/rake-compiler and a few other tweaks. I'd
love to hear if it really works beyond the simple IRB tests I did.

1) extract `WpdPack_4_1_2.zip` WpdPack directory to `c:\devlibs\winpcap`

2) unpack the current gem

C:\Users\Jon\Downloads\temp>gem unpack pcaprub-0.11.2.gem
Unpacked gem: 'C:/Users/Jon/Downloads/temp/pcaprub-0.11.2'

3) edit pcaprub.gemspec, lib\pcaprub\version.rb, and
ext\pcaprub\extconf.rb with the following mods.

https://github.com/shadowbq/pcaprub/blob/master/pcaprub.gemspec#L8
  change to "0.11.3.a1"


  change to...

    TINY = 3
    PATCH = 'a1'

    STRING = [MAJOR, MINOR, TINY, PATCH].join('.')

https://github.com/shadowbq/pcaprub/blob/master/ext/pcaprub/extconf.rb#L18-20
  add these two lines after those (note space after opening quote)...

    $CFLAGS << " -DWIN32 -I#{pcap_includedir}"
    $LDFLAGS << " -L#{pcap_libdir}"

4) build an updated gem, install it, and install `packetfu`

C:\Users\Jon\Downloads\temp\pcaprub-0.11.2>gem build pcaprub.gemspec
  Successfully built RubyGem
  Name: pcaprub
  Version: 0.11.3.a1
  File: pcaprub-0.11.3.a1.gem

C:\Users\Jon\Downloads\temp\pcaprub-0.11.2>gem install
pcaprub0.11.3.a1.gem -- --with-pcap-dir=c:/devlibs/winpcap
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed pcaprub-0.11.3.a1
1 gem installed

C:\Users\Jon\Downloads\temp>gem install packetfu-1.1.5.gem
Successfully installed packetfu-1.1.5
1 gem installed

5) simple tests

irb(main):001:0> RUBY_DESCRIPTION
=> "tcs-ruby 1.9.3p6 (2011-12-20, TCS patched 2011-12-23)
[i386-mingw32]"
irb(main):002:0> require 'pcaprub'
=> true
irb(main):003:0> PCAPRUB::VERSION::STRING
=> "0.11.3.a1"
irb(main):004:0> Pcap.singleton_methods.sort
=> [:lookupdev, :lookupnet, :new, :open_dead, :open_live, :open_offline,
:version]
irb(main):005:0> require 'packetfu'
=> true
irb(main):006:0> PacketFu::VERSION
=> "1.1.5"
irb(main):007:0> PacketFu.pcaprub_loaded?
=> true

Jon

···

---
Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums

--
Posted via http://www.ruby-forum.com/.

Hi Jon,

2) unpack the current gem

C:\Users\Jon\Downloads\temp>gem unpack pcaprub-0.11.2.gem
Unpacked gem: 'C:/Users/Jon/Downloads/temp/pcaprub-0.11.2'

I ran into a little problem on step 2. Since pcaprub never actually
installs I cannot unpack it. I tried to "gem fetch" followed by a gem
unpack. This worked except that the output dir was empty.

So instead I did a gem install pcaprub --install-dir
"C:\users\user\downloads\" and it placed it into the pcaprub-0.11.2
folder.

I then proceeded to make the changes you suggested.

When running the gem build command I got a new error.

C:\Users\user\Downloads\pcaprub-0.11.2>gem install pcaprub-0.11.3.a1.gem
-- w
ith-pcap-dir=c:/devlibs/wincap
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pcaprub-0.11.3.a1.gem:
        ERROR: Failed to build gem native extension.

        C:/Ruby192/bin/ruby.exe extconf.rb
with-pcap-dir=c:/devlibs/wincap

[*] Running checks for pcaprub code...
platform is i386-mingw32
checking for main() in -lws2_32... yes
checking for main() in -liphlpapi... yes
checking for windows.h... yes
checking for winsock2.h... yes
checking for iphlpapi.h... yes
checking for pcap_open_live() in -lwpcap... no
checking for pcap_setnonblock() in -lwpcap... no
creating Makefile

make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_pcaprub'" >
pcaprub-i386-mingw32.
def
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32
-I/C/Ruby192/include/ruby-1
.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H
-DHAVE_W
INSOCK2_H -DHAVE_IPHLPAPI_H -O3 -g -Wextra -Wno-unused-parameter
-Wno-parenth
eses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers
-Wno-long-l
ong -DWIN32 -Ic:/devlibs/wincap/include -o pcaprub.o -c pcaprub.c
pcaprub.c:8:18: fatal error: pcap.h: No such file or directory
compilation terminated.
make: *** [pcaprub.o] Error 1

Gem files will remain installed in
C:/Ruby192/lib/ruby/gems/1.9.1/gems/pcaprub-0
.11.3.a1 for inspection.
Results logged to
C:/Ruby192/lib/ruby/gems/1.9.1/gems/pcaprub-0.11.3.a1/ext/pcap
rub/gem_make.out

C:\Users\user\Downloads\pcaprub-0.11.2>

The error being

pcaprub.c:8:18: fatal error: pcap.h: No such file or directory

Any thoughts? Thanks so much for your help!

···

--
Posted via http://www.ruby-forum.com/.