r4880 - in /packages/libnet-arp-perl/trunk: ./ _MTN/ debian/ t/

gwolf at users.alioth.debian.org gwolf at users.alioth.debian.org
Sat Feb 24 03:07:09 CET 2007


Author: gwolf
Date: Sat Feb 24 03:07:08 2007
New Revision: 4880

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=4880
Log:
New upstream version
Pending: Get debian/patches/10alignment-and-headers.dpatch to apply cleanly!

Added:
    packages/libnet-arp-perl/trunk/_MTN/
      - copied from r4879, packages/libnet-arp-perl/branches/upstream/current/_MTN/
    packages/libnet-arp-perl/trunk/t/arp_lookup.t
      - copied unchanged from r4879, packages/libnet-arp-perl/branches/upstream/current/t/arp_lookup.t
    packages/libnet-arp-perl/trunk/t/get_mac.t
      - copied unchanged from r4879, packages/libnet-arp-perl/branches/upstream/current/t/get_mac.t
    packages/libnet-arp-perl/trunk/t/send_packet.t
      - copied unchanged from r4879, packages/libnet-arp-perl/branches/upstream/current/t/send_packet.t
Modified:
    packages/libnet-arp-perl/trunk/ARP.pm
    packages/libnet-arp-perl/trunk/ARP.xs
    packages/libnet-arp-perl/trunk/Changes
    packages/libnet-arp-perl/trunk/MANIFEST
    packages/libnet-arp-perl/trunk/Makefile.PL
    packages/libnet-arp-perl/trunk/README
    packages/libnet-arp-perl/trunk/arp_lookup_bsd.c
    packages/libnet-arp-perl/trunk/arp_lookup_linux.c
    packages/libnet-arp-perl/trunk/debian/changelog
    packages/libnet-arp-perl/trunk/debian/control
    packages/libnet-arp-perl/trunk/get_mac_linux.c
    packages/libnet-arp-perl/trunk/send_packet_bsd.c
    packages/libnet-arp-perl/trunk/send_packet_linux.c
    packages/libnet-arp-perl/trunk/test.pl

Modified: packages/libnet-arp-perl/trunk/ARP.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/ARP.pm?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/ARP.pm (original)
+++ packages/libnet-arp-perl/trunk/ARP.pm Sat Feb 24 03:07:08 2007
@@ -2,7 +2,7 @@
 # Perl ARP Extension
 #
 # Programmed by Bastian Ballmann
-# Last update: 09.02.2006
+# Last update: 31.01.2007
 #
 # This program is free software; you can redistribute 
 # it and/or modify it under the terms of the 
@@ -41,7 +41,7 @@
 	
 );
 
-our $VERSION = '0.8';
+our $VERSION = '1.0';
 
 require XSLoader;
 XSLoader::load('Net::ARP', $VERSION);
@@ -65,11 +65,22 @@
 	                'aa:bb:cc:aa:bb:cc',  # Destinaton MAC
 	                'reply');             # ARP operation
 
-Net::ARP::get_mac("eth0",$mac);
+$mac = Net::ARP::get_mac("eth0");
+
 print "$mac\n";
 
-Net::ARP::arp_lookup($dev,"192.168.1.1",$mac);
+$mac = Net::ARP::arp_lookup($dev,"192.168.1.1");
+
 print "192.168.1.1 has got mac $mac\n";
+
+
+=head2 IMPORTANT
+
+Version 1.0 will break with the API of PRE-1.0 versions, 
+because the return value of arp_lookup() and get_mac()
+will no longer be passed as parameter, but returned!
+I hope this decision is ok as long as we get a cleaner and more perlish API.
+
 
 =head2 DESCRIPTION
 
@@ -94,7 +105,7 @@
 
 =item B<get_mac()>
 
-  Net::ARP::get_mac("eth0",$mac);
+  $mac = Net::ARP::get_mac("eth0");
 
   This gets the MAC address of the eth0 interface and stores 
   it in the variable $mac. The return value is "unknown" if
@@ -102,7 +113,7 @@
 
 =item B<arp_lookup()>
 
-  Net::ARP::arp_lookup($dev,"192.168.1.1",$mac);
+  $mac = Net::ARP::arp_lookup($dev,"192.168.1.1");
 
   This looks up the MAC address for the ip address 192.168.1.1
   and stores it in the variable $mac. The return value is 
@@ -122,10 +133,12 @@
 
 =head1 AUTHOR
 
- Bastian Ballmann [ Crazydj at chaostal.de ]
+ Bastian Ballmann [ Balle at chaostal.de ]
  http://www.datenterrorist.de
 
 =head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2004-2007 by Bastian Ballmann
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself, either Perl version 5.8.1 or,

Modified: packages/libnet-arp-perl/trunk/ARP.xs
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/ARP.xs?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/ARP.xs (original)
+++ packages/libnet-arp-perl/trunk/ARP.xs Sat Feb 24 03:07:08 2007
@@ -1,9 +1,9 @@
 /*
 Perl ARP Extension
-Create and send an arp packet
+Create and send an arp packets, lookup mac addresses
 
 Programmed by Bastian Ballmann
-Last update: 09.02.2006
+Last update: 31.01.2007
 
 This program is free software; you can redistribute 
 it and/or modify it under the terms of the 
@@ -50,12 +50,14 @@
 	  struct arphdr *arp = (struct arphdr *)(packet + sizeof(struct ether_header));
 	  u_short op;	
 
+          RETVAL = 1;
+
 	  // Are you root?
 	  uid = getuid();
 	  if(uid != 0) 
 	  { 
 	    printf("You must have UID 0 instead of %d.\n",uid); 
-	    exit(1); 
+	    exit(0);
 	  }
 
 	  // Initialize packet buffer 
@@ -94,65 +96,97 @@
 	  if(smac == NULL)
 	  {
 	    printf("Parameter smac is NULL! Terminating.\n");
-	    exit(1);
+	    RETVAL = 0;
 	  }
 
 	  if(dmac == NULL)
 	  {
 	    printf("Parameter dmac is NULL! Terminating.\n");
-	    exit(1);
+	    RETVAL = 0;
 	  }
 
           // Found a dollar sign?
 	  if(strchr(smac,36))
 	  {
 	    printf("Found a $ char in smac! Terminating.\n");
-	    exit(1);
+	    RETVAL = 0;
 	  }
 
 	  if(strchr(dmac,36))
 	  {
 	    printf("Found a $ char in dmac! Terminating.\n");
-	    exit(1);
-	  }
-
-	  // Ethernet header
-	  memcpy(ethhdr->ether_dhost,(u_char *)ether_aton(dmac),ETHER_ADDR_LEN); // Destination MAC
-	  memcpy(ethhdr->ether_shost,(u_char *)ether_aton(smac),ETHER_ADDR_LEN); // Source MAC
-	  ethhdr->ether_type = htons(ETHERTYPE_ARP);                             // ARP protocol
-
-	  // ARP header
-	  arp->hw_type = htons(ARPHDR_ETHER);                                    // Hardware address type
-	  arp->proto_type = htons(ETH_P_IP);                                     // Protocol address type
-	  arp->ha_len = ETH_ALEN;                                                // Hardware address length
-	  arp->pa_len = IP_ALEN;                                                 // Protocol address length
-	  arp->opcode = htons(op);                                               // ARP operation
-	  memcpy(arp->source_add,(u_char *)ether_aton(smac),ETH_ALEN);           // Source MAC
-	  *(u_long *)arp->source_ip = inet_addr(sip);                            // Source IP
-
-	  if(strcmp(dmac,"ff:ff:ff:ff:ff:ff"))
-          	memcpy(arp->dest_add,(u_char *)ether_aton(dmac),ETH_ALEN);       // Destination MAC
-
-	  *(u_long *)arp->dest_ip = inet_addr(dip);                              // Destination IP
-
-
-	  // Run packet!! Run!
-	  // FreeBSD code
-	  if(SOCK_TYPE == SOCK_RAW)
-	  {
-	     send_packet_bsd(dev,packet,packetsize);	
-	  }
-
-	  // Linux code
-	  else
-	  {
-	     send_packet_linux(dev,packet,packetsize);
-	  }
+	    RETVAL = 0;
+	  }
+
+          if(ether_aton(smac) == NULL)
+          {
+            printf("Invalid source mac address! Terminating.\n");
+            RETVAL = 0;
+          }
+
+          if(ether_aton(dmac) == NULL)
+          {
+            printf("Invalid destination mac address! Terminating.\n");
+            RETVAL = 0;
+          }
+
+          // Check ips
+          if(inet_addr(sip) == INADDR_NONE)
+          {
+            printf("Invalid source ip address! Terminating.\n");
+            RETVAL = 0;
+          }
+
+          if(inet_addr(dip) == INADDR_NONE)
+          {
+            printf("Invalid destination ip address! Terminating.\n");
+            RETVAL = 0;
+          }
+
+          // Construct and send packet
+          if(RETVAL != 0)
+          {
+	  	// Ethernet header
+	        memcpy(ethhdr->ether_dhost,(u_char *)ether_aton(dmac),ETHER_ADDR_LEN); // Destination MAC
+	        memcpy(ethhdr->ether_shost,(u_char *)ether_aton(smac),ETHER_ADDR_LEN); // Source MAC
+	        ethhdr->ether_type = htons(ETHERTYPE_ARP);                             // ARP protocol
+
+	        // ARP header
+	        arp->hw_type = htons(ARPHDR_ETHER);                                    // Hardware address type
+	        arp->proto_type = htons(ETH_P_IP);                                     // Protocol address type
+	        arp->ha_len = ETH_ALEN;                                                // Hardware address length
+	        arp->pa_len = IP_ALEN;                                                 // Protocol address length
+	        arp->opcode = htons(op);                                               // ARP operation
+	        memcpy(arp->source_add,(u_char *)ether_aton(smac),ETH_ALEN);           // Source MAC
+	        *(u_long *)arp->source_ip = inet_addr(sip);                            // Source IP
+
+	        if(strcmp(dmac,"ff:ff:ff:ff:ff:ff"))
+          		memcpy(arp->dest_add,(u_char *)ether_aton(dmac),ETH_ALEN);       // Destination MAC
+
+	         *(u_long *)arp->dest_ip = inet_addr(dip);                              // Destination IP
+
+
+	         // Run packet!! Run!
+	         // FreeBSD code
+	         if(SOCK_TYPE == SOCK_RAW)
+	         {
+	           RETVAL = send_packet_bsd(dev,packet,packetsize);	
+	         }
+
+	         // Linux code
+	         else
+	         {
+	           RETVAL = send_packet_linux(dev,packet,packetsize);
+	         }
+          }
+
+          OUTPUT:
+          RETVAL
 
 char *
-get_mac(dev, mac)
+get_mac(dev)
 	unsigned char *dev;
-	unsigned char *mac;
+
 	CODE:
           char tmp[20] = "unknown";
 
@@ -165,17 +199,17 @@
 	    get_mac_linux(dev,tmp);
 	  }
 
-	  mac = tmp;
+	  RETVAL = tmp;
 
 	OUTPUT:
-	mac
+	RETVAL
 
 
 char *
-arp_lookup(dev, ip, mac)
+arp_lookup(dev, ip)
 	unsigned char *dev;
 	unsigned char *ip;
-	unsigned char *mac;
+
 	CODE:
 	  char tmp[20] = "unknown";
 
@@ -188,7 +222,8 @@
 	    arp_lookup_linux(dev,ip,tmp);
 	  }
 
-	  mac = tmp;
-
-	OUTPUT:
-	mac
+	  RETVAL = tmp;
+
+          OUTPUT:
+          RETVAL
+

Modified: packages/libnet-arp-perl/trunk/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/Changes?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/Changes (original)
+++ packages/libnet-arp-perl/trunk/Changes Sat Feb 24 03:07:08 2007
@@ -1,3 +1,15 @@
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+Changes between 0.8 and 1.0
+
+API Change for get_mac() and arp_lookup() - see perldoc
+
+Updated test script (Net::Pcap not needed if unavailable)
+New test suite to test for unwanted input.
+
+Fixed possible segfault in send_packet() because of not
+checking src / dst ip values
+
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
 Changes between 0.7 and 0.8

Modified: packages/libnet-arp-perl/trunk/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/MANIFEST?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/MANIFEST (original)
+++ packages/libnet-arp-perl/trunk/MANIFEST Sat Feb 24 03:07:08 2007
@@ -7,3 +7,9 @@
 README
 t/ARP.t
 ARP.pm
+arp_lookup_bsd.c
+arp_lookup_linux.c
+get_mac_bsd.c
+get_mac_linux.c
+send_packet_bsd.c
+send_packet_linux.c

Modified: packages/libnet-arp-perl/trunk/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/Makefile.PL?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/Makefile.PL (original)
+++ packages/libnet-arp-perl/trunk/Makefile.PL Sat Feb 24 03:07:08 2007
@@ -2,7 +2,7 @@
 # Perl ARP Extension makefile
 #
 # Programmed by Bastian Ballmann
-# Last update: 23.11.2005
+# Last update: 31.01.2007
 #
 # This program is free software; you can redistribute 
 # it and/or modify it under the terms of the 
@@ -45,7 +45,7 @@
 
 WriteMakefile(
     NAME              => 'Net::ARP',
-    VERSION           => '0.8',
+    VERSION           => '1.0',
     AUTHOR            => 'Bastian Ballmann',
     DEFINE            => $flags, 
     OBJECT            => $objects	      

Modified: packages/libnet-arp-perl/trunk/README
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/README?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/README (original)
+++ packages/libnet-arp-perl/trunk/README Sat Feb 24 03:07:08 2007
@@ -3,15 +3,27 @@
 Net::ARP
 
 Programmed by Bastian Ballmann
-Last Update: 13.01.2006
+Web: http://www.datenterrorist.de
+Mail: balle at chaostal.de
+
+Last Update: 31.01.2007
 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
 ---:[ Description
 
-This module is a Perl extension to create and send ARP packets.
-You do not need to install any additionally libraries like Libnet to compile 
+This module is a Perl extension to create and send ARP packets and lookup
+local or remote mac addresses.
+You do not need to install any additional libraries like Libnet to compile 
 this extension. It uses kernel header files to create the packets.
+
+
+---:[ IMPORTANT NOTICE
+
+Version 1.0 will break with the API of PRE-1.0 versions, 
+because the return value of arp_lookup() and get_mac()
+will no longer be passed as parameter, but returned!
+I hope this decision is ok as long as we get a cleaner and more perlish API.
 
 
 ---:[ Installation
@@ -27,11 +39,21 @@
 ---:[ Usage
 
 Please read the POD documentation: perldoc Net::ARP.
+If you've still any questions feel free to ask.
 
 
-COPYRIGHT AND LICENCE
+---:[ Want to contribute?
 
-Copyright (C) 2004 by Bastian Ballmann
+Please drop me a mail and if you want to submit patches please
+generate them using "diff -Nru" on the latest version. 
+There's also the possibility to exchange changes using the 
+distributed version control system monotone.
+Last but not least new code should be commented and I like test code ;)
+
+
+---:[ COPYRIGHT AND LICENCE
+
+Copyright (C) 2004-2007 by Bastian Ballmann
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself, either Perl version 5.8.1 or,

Modified: packages/libnet-arp-perl/trunk/arp_lookup_bsd.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/arp_lookup_bsd.c?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/arp_lookup_bsd.c (original)
+++ packages/libnet-arp-perl/trunk/arp_lookup_bsd.c Sat Feb 24 03:07:08 2007
@@ -4,7 +4,7 @@
 BSD code
 
 Programmed by Bastian Ballmann
-Last update: 09.02.2006
+Last update: 20.09.2006
 
 This program is free software; you can redistribute 
 it and/or modify it under the terms of the 
@@ -43,8 +43,7 @@
   else
     return -1;
 
-  if( (strlen(dev) == 0) ||
-      (strlen(ip) == 0) )
+  if(strlen(ip) == 0)
     return -1;
 
   strcpy(mac,"unknown");

Modified: packages/libnet-arp-perl/trunk/arp_lookup_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/arp_lookup_linux.c?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/arp_lookup_linux.c (original)
+++ packages/libnet-arp-perl/trunk/arp_lookup_linux.c Sat Feb 24 03:07:08 2007
@@ -4,7 +4,7 @@
 Linux code
 
 Programmed by Bastian Ballmann and Alexander Mueller
-Last update: 09.02.2006
+Last update: 20.09.2006
 
 This program is free software; you can redistribute 
 it and/or modify it under the terms of the 
@@ -37,8 +37,7 @@
   else
     return -1;
 
-  if( (strlen(dev) == 0) ||
-      (strlen(ip) == 0) )
+  if(strlen(ip) == 0)
     return -1;
   
   if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
@@ -56,7 +55,8 @@
 	  
 	  if (num < 4)
 	    break;
-	  if (strcmp(dev, device) == 0 && strcmp(ip, ipaddr) == 0)
+
+          if ((strlen(dev) == 0 || strcmp(dev, device) == 0) && strcmp(ip, ipaddr) == 0)
 	    {
 	      strcpy(mac, hwa);
 	      break;

Modified: packages/libnet-arp-perl/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/debian/changelog?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/debian/changelog (original)
+++ packages/libnet-arp-perl/trunk/debian/changelog Sat Feb 24 03:07:08 2007
@@ -1,3 +1,10 @@
+libnet-arp-perl (1.0-1) unstable; urgency=low
+
+  * New upstream release
+  * Now recommends libnet-pcap-perl
+
+ -- Gunnar Wolf <gwolf at debian.org>  Fri, 23 Feb 2007 19:57:09 -0600
+
 libnet-arp-perl (0.8-2) unstable; urgency=low
 
   * Add dpatch framework.

Modified: packages/libnet-arp-perl/trunk/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/debian/control?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/debian/control (original)
+++ packages/libnet-arp-perl/trunk/debian/control Sat Feb 24 03:07:08 2007
@@ -10,6 +10,7 @@
 Package: libnet-arp-perl
 Architecture: any
 Depends: ${perl:Depends}, ${shlibs:Depends}, ${misc:Depends}, 
+Recommends: libnet-pcap-perl
 Description:  Create ARP packets and lookup for ARP information
  This module allows for creating arbitrary ARP packages from within
  your Perl code, as well as for looking up the ARP information for

Modified: packages/libnet-arp-perl/trunk/get_mac_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/get_mac_linux.c?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/get_mac_linux.c (original)
+++ packages/libnet-arp-perl/trunk/get_mac_linux.c Sat Feb 24 03:07:08 2007
@@ -18,6 +18,9 @@
 See the GNU General Public License for more details. 
 */
 
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <sys/ioctl.h>
 #include <net/ethernet.h>    
 #include <net/if.h>
@@ -43,7 +46,7 @@
   if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
     {
       perror("socket");
-      exit(1);
+      return -1;
     }
   else
     {
@@ -51,7 +54,7 @@
       if((ioctl(sock, SIOCGIFHWADDR, &iface)) < 0)
 	{
 	  perror("ioctl SIOCGIFHWADDR");
-	  exit(1);
+	  return -1;
 	}
       else
 	{

Modified: packages/libnet-arp-perl/trunk/send_packet_bsd.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/send_packet_bsd.c?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/send_packet_bsd.c (original)
+++ packages/libnet-arp-perl/trunk/send_packet_bsd.c Sat Feb 24 03:07:08 2007
@@ -33,7 +33,7 @@
 
   if( (strlen(dev) == 0) ||
       (packetsize == 0) )
-    return -1;
+    return 0;
 
   // Open a bpf device
   for(i = 0; i < 9; i++)
@@ -48,6 +48,7 @@
   if(bpffd < 0)
     {
       perror("open bpf");
+      return 0;
     }
   else
     {
@@ -63,5 +64,5 @@
       close(bpffd);
     }
 
-  return 0;
+  return 1;
 }

Modified: packages/libnet-arp-perl/trunk/send_packet_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/send_packet_linux.c?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/send_packet_linux.c (original)
+++ packages/libnet-arp-perl/trunk/send_packet_linux.c Sat Feb 24 03:07:08 2007
@@ -18,6 +18,8 @@
 See the GNU General Public License for more details. 
 */
 
+#include <string.h>
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/socket.h>      
 #include "arp.h"
@@ -27,25 +29,34 @@
   struct sockaddr addr;
   int sock;
 
-  if( (strlen(dev) == 0) ||
-      (packetsize == 0) )
-    return -1;
+  if(strlen(dev) == 0)
+  {
+    printf("dev is undefined. Terminating.\n");
+    return 0;
+  }
+
+  if(packetsize == 0)
+  {
+    printf("packetsize is zero. Terminating.\n");
+    return 0;
+  }
 
   // Create socket descriptor
   if( ( sock = socket(AF_INET,SOCK_TYPE,htons(ETH_P_ALL))) < 0 ) 
     { 
       perror("socket"); 
-      exit(1); 
+      return 0;
     }
 
   // Set dev and send the packet
   strncpy(addr.sa_data,dev,sizeof(addr.sa_data));
+
   if( (sendto(sock,packet,packetsize,0,&addr,sizeof(struct sockaddr))) < 0 )
     {
       perror("send");
-      exit(1);
+      return 0;
     }
 
   close(sock);
-  return 0;
+  return 1;
 }

Modified: packages/libnet-arp-perl/trunk/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/trunk/test.pl?rev=4880&op=diff
==============================================================================
--- packages/libnet-arp-perl/trunk/test.pl (original)
+++ packages/libnet-arp-perl/trunk/test.pl Sat Feb 24 03:07:08 2007
@@ -3,7 +3,7 @@
 # Perl ARP Extension test file
 #
 # Programmed by Bastian Ballmann
-# Last update: 23.11.2005
+# Last update: 31.01.2007
 #
 # This program is free software; you can redistribute 
 # it and/or modify it under the terms of the 
@@ -18,20 +18,36 @@
 
 use ExtUtils::testlib;
 use Net::ARP;
-use Net::Pcap;
 
-my $errbuf;
-my $dev = Net::Pcap::lookupdev(\$errbuf);
+BEGIN
+{
+    eval{ require Net::Pcap; };
+              
+    if($@ =~ /^Can\'t\slocate/)
+    {
+        $dev = "eth0";
+    }
+    else
+    {
+   	import Net::Pcap;
+        $dev = Net::Pcap::lookupdev(\$errbuf);
+    }
+}
 
-Net::ARP::send_packet($dev,                           # network interface
+print "Sending ARP reply packet via dev $dev... ";
+
+$ret = Net::ARP::send_packet($dev,                           # network interface
 		      '127.0.0.1',                    # source ip
 	              '127.0.0.1',                    # destination ip
 		      'aa:bb:cc:aa:bb:cc',            # source mac
 	              'ff:ff:ff:ff:ff:ff',            # destination mac
 	              'reply');                       # ARP operation 
 
-Net::ARP::get_mac($dev,$mac);
+print $ret ? "ok\n" : "failed\n";
+
+$mac = Net::ARP::get_mac($dev);
 print "MAC $mac\n";
-Net::ARP::arp_lookup($dev,"192.168.1.1",$mac);
-print "192.168.2.1 has got mac $mac\n";
 
+$mac = Net::ARP::arp_lookup($dev,"192.168.1.1");
+print "192.168.1.1 has got mac $mac\n";
+




More information about the Pkg-perl-cvs-commits mailing list