perlusr193 has asked for the wisdom of the Perl Monks concerning the following question:

Net::Libdnet (a wrapper module for libdnet API) is a prerequisite for other framework modules like Net::Packet and Net::Frame. The only version of Net::Libdnet available in PPM repository for Windows (MSWin32) is the very first and obsolete version 0.01. Because it is painful to install a newer Net::Libdnet (e.g. v0.98) via CPAN or manually under Windows (too many error messages), one has to rely on the obsolete Net::Libdnet 0.01.

Net::Libdnet 0.01 does properly work under WinXP, but does NOT work under Win7.

With a following sample code, the config structures of the installed network interfaces can be normally accessed under WinXP:

use warnings; use strict; use Data::Dumper; use Net::Libdnet; my $addr; # IP address my $interf_ref; # hash reference to the NIC interface structure my %interf_hash; # hash with the interface structure referenced as +$interf_ref $addr = '10.100.20.1'; # gateway IP addr $interf_ref = Net::Libdnet::intf_get_dst($addr); # Net::Libdnet: +:intf_get_dst() -- retrieves the configuration for the best interface + with which to reach the specified destination IP address print Data::Dumper->Dump([\$interf_ref], [qw(interface)]); $addr = '10.100.20.69'; # my IP addr $interf_ref = Net::Libdnet::intf_get_src($addr); # Net::Libdnet: +:intf_get_src() -- retrieves the configuration for the interface with + the specified source IP address. print Data::Dumper->Dump([\$interf_ref], [qw(interface)]); $interf_ref = Net::Libdnet::intf_get('eth0'); # Net::Libdnet::in +tf_get() -- retrieves an interface configuration entry, keyed on name %interf_hash = %{$interf_ref}; print Data::Dumper->Dump([\%interf_hash], [qw(interface_eth0)]); print "Key value: ", $interf_hash{'mtu'}, "\n"; print "Key value: ", ${$interf_ref}{'link_addr'}, "\n"; $interf_ref = Net::Libdnet::intf_get('eth1'); print Data::Dumper->Dump([\$interf_ref], [qw(interface_eth1)]); $interf_ref = Net::Libdnet::intf_get('eth2'); print Data::Dumper->Dump([\$interf_ref], [qw(interface_eth2)]); system('pause'); exit(0);

A similar snippet code does not work (crashes) under Win7.

After installation of the Bundle::Net::Frame 1.02 and Net::Libdnet 0.01 via PPM, I always get following critical error messages from Net::Frame::Device under Win7:

Net::Frame::Device: updateFromDefault: unable to get dnet - or - Net::Frame::Device: updateFromDev: unable to get dnet - or - Net::Frame::Device: updateFromTarget: unable to get dnet

It is the issue with the module Net::Libdnet 0.01 which function intf_get() is called from _getDevWin32() in Net::Frame::Device (the error messages are shown above). intf_get() does not work as expected for ethernet interfaces under Windows 7.

The situation is as follows:

1. Net::Libdnet 0.01 works under WinXP, but does NOT work under Win7.

2. WinXP is not supported any more by Microsoft. But for a newer Windows OS like Win7, there is no real support, bugfixes, or maintenance of Net::Libdnet for current Windows platforms (Win 7/8/10).

3. Under Win7, I could not manage to install Net::Libdnet 0.98 via CPAN (Cygwin+MinGW) or manually - too many error messages as shown below.

cpan> install Net::Libdnet Net-Libdnet-0.98/ ... Configuring G/GO/GOMOR/Net-Libdnet-0.98.tar.gz with Makefile.PL Note (probably harmless): No library found for -ldnet ... Libdnet.xs:37:18: dnet.h: No such file or directory In file included from Libdnet.xs:77: c/intf_entry.c: In function `intf_c2sv': c/intf_entry.c:38: error: dereferencing pointer to incomplete type c/intf_entry.c:39: error: dereferencing pointer to incomplete type c/intf_entry.c:40: error: dereferencing pointer to incomplete type c/intf_entry.c:41: error: dereferencing pointer to incomplete type c/intf_entry.c:42: error: dereferencing pointer to incomplete type c/intf_entry.c:44: error: dereferencing pointer to incomplete type ... dmake.exe: Error code 129, while making 'Libdnet.o' GOMOR/Net-Libdnet-0.98.tar.gz C:\ACTIVE~1\site\bin\dmake.exe -- NOT OK Failed during this command: GOMOR/Net-Libdnet-0.98.tar.gz : make NO

Questions:

- How to get Net::Libdnet working under Win7?

- Can I encourage somebody to write a working and maintainable Net::Libdnet clone for current Windows platforms (Win 7/8/10)?

- Are there other options to get Net::Packet and Net::Frame working under Windows 7?

Replies are listed 'Best First'.
Re: Net::Libdnet 0.01 does not work under Window 7
by VinsWorldcom (Prior) on Jan 16, 2016 at 20:53 UTC

    Net::Frame doesn't require Net::Libdnet for *all* of it's uses, just Net::Frame::Device.

    Not sure what you're trying to do - if it's get Net::Libdnet working on Windows 7 x64 / Strawberry 5.18-, I can't help - I've tried unsuccessfully myself. If you're looking to do some packet creation / dissection (based on the Net::Frame mention), have a look at Perl Packet Crafter - an interactive shell for Net::Frame:

    https://github.com/vinsworldcom/PPC

      I really need Net::Frame::Device (Net::Frame). In my script, a following constuct cannot work with Net::Libdnet 0.01 :

      print "$^O\n"; my $oDevice = Net::Frame::Device->new(dev => '...');

      Error message with Net::Libdnet 0.01 under Win7:

      MSWin32 Net::Frame::Device: updateFromDev: unable to get dnet

      I need interfaces access in perl script with either Net::Frame::Device or Net::Packet. It's already clear that the interfaces concept (names and types of WiFi interfaces e.g.) is changed in Win7 compared to old WinXP. That is why Net::Libdnet 0.01 functions fine under WinXP, but cannot not work under Win7.

      I successfully used Net::Packet in WinXP and would like to migrate it to Win7. My central issue under Win7 is Libdnet and not really Net::Packet or Net::Frame. I know what is wrong with Net::Libdnet 0.01 under Win7, but this knowledge does not bring me to the needed solution. Aproved and straightforward howto's to solve the described Libdnet (Win7) problem are much appreciated.

        "I know what is wrong with Net::Libdnet 0.01 under Win7"

        If that's the case, either fix it, or test the advice of VinsWorldcom in Re: Net::Libdnet 0.01 does not work under Window 7, and see if that helps.

        The module you speak of seems to have had a history of test failures, so when someone gives you workable advice, why not test it instead of arguing?

        If it's a case of using another script within a script, there are options... system and backticks (see IO Operators in perlop).

        Again, I'll recommend PPC from my previous post. It accesses Windows interfaces using Net::Pcap and a custom module Win32::Interfaces which isn't on CPAN. Ive tried to emulate many of the accessor's from *nix only interface modules including Net::Libdnet, which I spent many a sleepless night and many conversations with the developer (Gomor, who is very responsive and helpful) trying to get working on Win7 x64 to no avail so just rolled my own (Win32::Interfaces) to work with the Net::Frame suite.

        https://github.com/vinsworldcom/PPC

        I know what is wrong with Net::Libdnet 0.01 under Win7, but this knowledge does not bring me to the needed solution. Aproved and straightforward howto's to solve the described Libdnet (Win7) problem are much appreciated.

        Can you tell me what is wrong with it under win7?

      Hi vin,

      first, thank you for your assistance regarding my PerlMonk question!
      I have "installed" and tried with your module W32::Interfaces. After some typos were corrected in the sample you kindly posted, that code can finally work on my Win7 PC (see output in my mail I have sent you).

      You wrote in the module's description:
      >> A better approach may be to use XS with GetAdaptersAddresses() and parse the
      >> IP_ADAPTER_ADDRESSES structure. Alas, that is proving difficult to do.

      With my sample get_adapters_info.pl attached in the mail, you can use IP Helper API and Windows Registry without need to base upon Windows system commands (without CLI interface currently used in your module interfaces.pm). I believe, it is an elegant solution you are looking for.

      Best regards,
      perlusr193 (a PerlMonk)

Re: Net::Libdnet 0.01 does not work under Window 7
by Anonymous Monk on Jan 16, 2016 at 18:41 UTC
    How to get Net::Libdnet working under Win7?

    install the prerequisites, namely libdnet.dll...

      As already said, the interfaces concept (names and types of WiFi interfaces e.g.) is critically changed in Win7 compared to old WinXP. That is why the old Net::Libdnet 0.01 works fine under WinXP, but cannot properly access and build interfaces structures (hashes) under Win7. In best case, null pointers are returned from Net::Libdnet 0.01 under Win7. In worst case, a memory access violation occurs resulting crash of the perl application.