r4878 - in /packages/libnet-arp-perl/branches/upstream/current: ./ _MTN/ t/

gwolf at users.alioth.debian.org gwolf at users.alioth.debian.org
Sat Feb 24 02:53:51 CET 2007


Author: gwolf
Date: Sat Feb 24 02:53:50 2007
New Revision: 4878

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=4878
Log:
[svn-upgrade] Integrating new upstream version, libnet-arp-perl (1.0)

Added:
    packages/libnet-arp-perl/branches/upstream/current/_MTN/
    packages/libnet-arp-perl/branches/upstream/current/_MTN/format
    packages/libnet-arp-perl/branches/upstream/current/_MTN/log
    packages/libnet-arp-perl/branches/upstream/current/_MTN/options
    packages/libnet-arp-perl/branches/upstream/current/_MTN/revision
    packages/libnet-arp-perl/branches/upstream/current/t/arp_lookup.t
    packages/libnet-arp-perl/branches/upstream/current/t/get_mac.t
    packages/libnet-arp-perl/branches/upstream/current/t/send_packet.t
Modified:
    packages/libnet-arp-perl/branches/upstream/current/ARP.pm
    packages/libnet-arp-perl/branches/upstream/current/ARP.xs
    packages/libnet-arp-perl/branches/upstream/current/Changes
    packages/libnet-arp-perl/branches/upstream/current/MANIFEST
    packages/libnet-arp-perl/branches/upstream/current/Makefile.PL
    packages/libnet-arp-perl/branches/upstream/current/README
    packages/libnet-arp-perl/branches/upstream/current/arp_lookup_bsd.c
    packages/libnet-arp-perl/branches/upstream/current/arp_lookup_linux.c
    packages/libnet-arp-perl/branches/upstream/current/get_mac_linux.c
    packages/libnet-arp-perl/branches/upstream/current/send_packet_bsd.c
    packages/libnet-arp-perl/branches/upstream/current/send_packet_linux.c
    packages/libnet-arp-perl/branches/upstream/current/test.pl

Modified: packages/libnet-arp-perl/branches/upstream/current/ARP.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/ARP.pm?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/ARP.pm (original)
+++ packages/libnet-arp-perl/branches/upstream/current/ARP.pm Sat Feb 24 02:53:50 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
 
@@ -92,7 +103,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
@@ -100,7 +111,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 
@@ -112,10 +123,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/branches/upstream/current/ARP.xs
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/ARP.xs?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/ARP.xs (original)
+++ packages/libnet-arp-perl/branches/upstream/current/ARP.xs Sat Feb 24 02:53:50 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/branches/upstream/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/Changes?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/Changes (original)
+++ packages/libnet-arp-perl/branches/upstream/current/Changes Sat Feb 24 02:53:50 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/branches/upstream/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/MANIFEST?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/MANIFEST (original)
+++ packages/libnet-arp-perl/branches/upstream/current/MANIFEST Sat Feb 24 02:53:50 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/branches/upstream/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/Makefile.PL?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/Makefile.PL (original)
+++ packages/libnet-arp-perl/branches/upstream/current/Makefile.PL Sat Feb 24 02:53:50 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/branches/upstream/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/README?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/README (original)
+++ packages/libnet-arp-perl/branches/upstream/current/README Sat Feb 24 02:53:50 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,

Added: packages/libnet-arp-perl/branches/upstream/current/_MTN/format
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/_MTN/format?rev=4878&op=file
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/_MTN/format (added)
+++ packages/libnet-arp-perl/branches/upstream/current/_MTN/format Sat Feb 24 02:53:50 2007
@@ -1,0 +1,1 @@
+2

Added: packages/libnet-arp-perl/branches/upstream/current/_MTN/log
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/_MTN/log?rev=4878&op=file
==============================================================================
    (empty)

Added: packages/libnet-arp-perl/branches/upstream/current/_MTN/options
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/_MTN/options?rev=4878&op=file
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/_MTN/options (added)
+++ packages/libnet-arp-perl/branches/upstream/current/_MTN/options Sat Feb 24 02:53:50 2007
@@ -1,0 +1,3 @@
+database "/data/develop/perl/Modules/libnet-arp-perl.mtn"
+  branch "stable"
+  keydir "/home/basti/.monotone/keys"

Added: packages/libnet-arp-perl/branches/upstream/current/_MTN/revision
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/_MTN/revision?rev=4878&op=file
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/_MTN/revision (added)
+++ packages/libnet-arp-perl/branches/upstream/current/_MTN/revision Sat Feb 24 02:53:50 2007
@@ -1,0 +1,5 @@
+format_version "1"
+
+new_manifest [0000000000000000000000000000000000000001]
+
+old_revision [25f20d3f099896f7001178f7fb60cabc759f831d]

Modified: packages/libnet-arp-perl/branches/upstream/current/arp_lookup_bsd.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/arp_lookup_bsd.c?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/arp_lookup_bsd.c (original)
+++ packages/libnet-arp-perl/branches/upstream/current/arp_lookup_bsd.c Sat Feb 24 02:53:50 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/branches/upstream/current/arp_lookup_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/arp_lookup_linux.c?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/arp_lookup_linux.c (original)
+++ packages/libnet-arp-perl/branches/upstream/current/arp_lookup_linux.c Sat Feb 24 02:53:50 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 
@@ -19,6 +19,7 @@
 */
 
 #include <stdio.h>
+#include <string.h>
 
 #define _PATH_PROCNET_ARP "/proc/net/arp"
 
@@ -37,8 +38,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 +56,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/branches/upstream/current/get_mac_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/get_mac_linux.c?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/get_mac_linux.c (original)
+++ packages/libnet-arp-perl/branches/upstream/current/get_mac_linux.c Sat Feb 24 02:53:50 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/branches/upstream/current/send_packet_bsd.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/send_packet_bsd.c?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/send_packet_bsd.c (original)
+++ packages/libnet-arp-perl/branches/upstream/current/send_packet_bsd.c Sat Feb 24 02:53:50 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/branches/upstream/current/send_packet_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/send_packet_linux.c?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/send_packet_linux.c (original)
+++ packages/libnet-arp-perl/branches/upstream/current/send_packet_linux.c Sat Feb 24 02:53:50 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;
 }

Added: packages/libnet-arp-perl/branches/upstream/current/t/arp_lookup.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/t/arp_lookup.t?rev=4878&op=file
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/t/arp_lookup.t (added)
+++ packages/libnet-arp-perl/branches/upstream/current/t/arp_lookup.t Sat Feb 24 02:53:50 2007
@@ -1,0 +1,20 @@
+#
+# Test arp_lookup function
+#
+# Programmed by Bastian Ballmann
+# Last update: 31.01.2007
+
+use Net::ARP;
+use Test::More qw( no_plan );
+
+$mac = Net::ARP::arp_lookup("strange_dev_value","127.0.0.1");
+ok( $mac eq "unknown", "unkown mac on strange dev value -> $mac" );
+
+$mac = Net::ARP::arp_lookup("$fu","127.0.0.1");
+ok( $mac eq "unknown", "unkown mac on strange dev value 2 -> $mac" );
+
+$mac = Net::ARP::arp_lookup("eth0","this_is_not_an_ip_address");
+ok( $mac eq "unknown", "unkown mac on strange ip value -> $mac" );
+
+#Net::ARP::arp_lookup("eth0","192.168.1.1","fu");
+#ok( $mac eq "unknown", "unkown mac on strange mac value" );

Added: packages/libnet-arp-perl/branches/upstream/current/t/get_mac.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/t/get_mac.t?rev=4878&op=file
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/t/get_mac.t (added)
+++ packages/libnet-arp-perl/branches/upstream/current/t/get_mac.t Sat Feb 24 02:53:50 2007
@@ -1,0 +1,12 @@
+#
+# Test get_mac function
+#
+# Programmed by Bastian Ballmann
+# Last update: 31.01.2007
+
+use Net::ARP;
+use Test::More qw( no_plan );
+
+$mac = Net::ARP::get_mac("strange_dev_value");
+ok( $mac eq "unknown", "unkown mac on strange dev value -> $mac" );
+

Added: packages/libnet-arp-perl/branches/upstream/current/t/send_packet.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/t/send_packet.t?rev=4878&op=file
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/t/send_packet.t (added)
+++ packages/libnet-arp-perl/branches/upstream/current/t/send_packet.t Sat Feb 24 02:53:50 2007
@@ -1,0 +1,85 @@
+#
+# Test send_packet function
+#
+# Programmed by Bastian Ballmann
+# Last update: 31.01.2007
+
+use Net::ARP;
+use Test::More qw( no_plan );
+
+BEGIN
+{
+    eval{ require Net::Pcap; };
+              
+    if($@ =~ /^Can\'t\slocate/)
+    {
+        $dev = "eth0";
+    }
+    else
+    {
+   	import Net::Pcap;
+        $dev = Net::Pcap::lookupdev(\$errbuf);
+    }
+}
+
+print "Using device $dev to test send_packet()\n";
+
+$ret = Net::ARP::send_packet("strange_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 
+
+ok( $ret == 0, "abort on strange dev value -> $ret" );
+
+
+$ret = Net::ARP::send_packet($dev,            # network interface
+	      	      'strange_src_ip',       # 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 
+
+ok( $ret == 0, "abort on strange source ip value -> $ret" );
+
+
+$ret = Net::ARP::send_packet($dev,            # network interface
+	      	      '127.0.0.1',            # source ip
+	              'strange_dst_ip',       # destination ip
+		      'aa:bb:cc:aa:bb:cc',    # source mac
+	              'ff:ff:ff:ff:ff:ff',    # destination mac
+	              'reply');               # ARP operation 
+
+ok( $ret == 0, "abort on strange destination ip value -> $ret" );
+
+
+$ret = Net::ARP::send_packet($dev,            # network interface
+	      	      '127.0.0.1',            # source ip
+	              '127.0.0.1',            # destination ip
+		      'strange_src_mac',      # source mac
+	              'ff:ff:ff:ff:ff:ff',    # destination mac
+	              'reply');               # ARP operation 
+
+ok( $ret == 0, "abort on strange source mac value -> $ret" );
+
+
+$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
+	              'strange_dst_mac',      # destination mac
+	              'reply');               # ARP operation 
+
+ok( $ret == 0, "abort on strange destination mac value -> $ret" );
+
+$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
+	              'my_happy_arp_opcode'); # ARP operation 
+
+ok( $ret == 1, "do not abort on strange arp op value -> $ret" );
+
+

Modified: packages/libnet-arp-perl/branches/upstream/current/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnet-arp-perl/branches/upstream/current/test.pl?rev=4878&op=diff
==============================================================================
--- packages/libnet-arp-perl/branches/upstream/current/test.pl (original)
+++ packages/libnet-arp-perl/branches/upstream/current/test.pl Sat Feb 24 02:53:50 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