r36406 - in /trunk/libnet-arp-perl: ARP.xs Changes arp.h.orig arp_lookup_linux.c debian/changelog get_mac_linux.c

thialme-guest at users.alioth.debian.org thialme-guest at users.alioth.debian.org
Mon May 25 18:59:34 UTC 2009


Author: thialme-guest
Date: Mon May 25 18:59:29 2009
New Revision: 36406

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=36406
Log:
Updated changelog to follow new release

Removed:
    trunk/libnet-arp-perl/arp.h.orig
Modified:
    trunk/libnet-arp-perl/ARP.xs
    trunk/libnet-arp-perl/Changes
    trunk/libnet-arp-perl/arp_lookup_linux.c
    trunk/libnet-arp-perl/debian/changelog
    trunk/libnet-arp-perl/get_mac_linux.c

Modified: trunk/libnet-arp-perl/ARP.xs
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-arp-perl/ARP.xs?rev=36406&op=diff
==============================================================================
--- trunk/libnet-arp-perl/ARP.xs (original)
+++ trunk/libnet-arp-perl/ARP.xs Mon May 25 18:59:29 2009
@@ -192,7 +192,7 @@
 get_mac(dev)
 	const char *dev;
 	CODE:
-          char tmp[HEX_HW_ADDR_LEN];
+          char tmp[HEX_HW_ADDR_LEN] = "unknown";
 
 	  if(SOCK_TYPE == SOCK_RAW)
 	  {
@@ -215,7 +215,7 @@
 	const char *ip;
 
 	CODE:
-	  char tmp[HEX_HW_ADDR_LEN];
+	  char tmp[HEX_HW_ADDR_LEN] = "unknown";
 
 	  if(SOCK_TYPE == SOCK_RAW)
 	  {

Modified: trunk/libnet-arp-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-arp-perl/Changes?rev=36406&op=diff
==============================================================================
--- trunk/libnet-arp-perl/Changes (original)
+++ trunk/libnet-arp-perl/Changes Mon May 25 18:59:29 2009
@@ -1,3 +1,9 @@
+Changes between 1.0.3 and 1.0.5
+
+new linux arp lookup via ioctl by Franck Joncourt <franck.mail at dthconnex.com>
+
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
 Changes between 1.0.3 and 1.0.5
 
 buffer overflow patch by Franck Joncourt <franck.mail at dthconnex.com>

Modified: trunk/libnet-arp-perl/arp_lookup_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-arp-perl/arp_lookup_linux.c?rev=36406&op=diff
==============================================================================
--- trunk/libnet-arp-perl/arp_lookup_linux.c (original)
+++ trunk/libnet-arp-perl/arp_lookup_linux.c Mon May 25 18:59:29 2009
@@ -6,67 +6,100 @@
 Programmed by Bastian Ballmann and Alexander Mueller
 Last update: 20.09.2006
 
-This program is free software; you can redistribute 
-it and/or modify it under the terms of the 
-GNU General Public License version 2 as published 
+This program is free software; you can redistribute
+it and/or modify it under the terms of the
+GNU General Public License version 2 as published
 by the Free Software Foundation.
 
-This program is distributed in the hope that it will 
-be useful, but WITHOUT ANY WARRANTY; without even 
-the implied warranty of MERCHANTABILITY or FITNESS 
-FOR A PARTICULAR PURPOSE. 
-See the GNU General Public License for more details. 
+This program is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even
+the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
 */
 
+#include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
-#include "arp.h"
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <net/if_arp.h>
 
-#define _PATH_PROCNET_ARP "/proc/net/arp"
+/*
+ * Search for a hardware address linked to an IP address on a device
+ *
+ * @device:  network interface name we are going to query
+ * @ip:      ip address (IPv4 numbers-and-dots notation) whose hardware address
+ *           is going to be looked for
+ * @hw_addr: buffer containing the hardware mac_address
+ *
+ * \returns 0 if a hardware address has been found. @mac is set accordingly as
+ *            a null terminated string.
+ *          1 if an error occured
+ */
+int
+arp_lookup_linux (
+        const char *device, const char *ip, char *hw_addr)
+{
+    int                 s;
+    unsigned char       err;
+    struct in_addr      ipaddr;
+    struct arpreq       areq;
+    struct sockaddr_in *sin;
 
-int arp_lookup_linux(const char *dev, const char *ip, char *mac)
-{
-  FILE *fp;
-  char ipaddr[100];
-  char line[200];
-  char hwa[100];
-  char mask[100];
-  char device[100];
-  int num, type, flags;
+    err = 1;
 
-  if ( (mac == NULL) || (dev == NULL) || (ip == NULL) )
-    return -1;
+    /* A device name must be a null terminated string whose length is less
+     * than 16 bytes */
+    if ( !strlen(device) || (strlen(device) >= 16) )
+        fprintf(stderr, "No valid device name found.\n");
 
-  strncpy(mac,"unknown", HEX_HW_ADDR_LEN);
-  mac[HEX_HW_ADDR_LEN-1] = '\0';
+    /* Is there a buffer allocated to store the hardware address? */
+    else if (hw_addr == NULL)
+        fprintf(stderr, "No memory allocated to store the hardware address.\n");
 
-  if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
-    perror(_PATH_PROCNET_ARP);
-    return -1;
-  }
-  
-  /* Bypass header -- read until newline */
-  if (fgets(line, sizeof(line), fp) != (char *) NULL)
-    {
-      /* Read the ARP cache entries. */
-      while (fgets(line, sizeof(line), fp))
-	{
-	  num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", ipaddr, &type, &flags, hwa, mask, device);
-	  
-	  if (num < 4)
-	    break;
+    /* Make sure the ip address is valid */
+    else if ( !strlen(ip) || (inet_aton(ip, &ipaddr) == 0) )
+        fprintf(stderr, "Invalid ip address.\n");
 
-	  else if ( ((strlen(dev) == 0) || (strcmp(dev, device) == 0))
-	      && (strcmp(ip, ipaddr) == 0) )
-	    {
-	      strncpy(mac, hwa, HEX_HW_ADDR_LEN);
-	      mac[HEX_HW_ADDR_LEN-1] = '\0';
-	      break;
-	    }
-	}
+    /* Create the socket */
+    else if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+        perror("Socket");
+
+    else {
+
+        /* Set up the protocol address */
+        memset(&areq, 0, sizeof(areq));
+        sin = (struct sockaddr_in *) &areq.arp_pa;
+        sin->sin_family = AF_INET;
+        sin->sin_addr = ipaddr;
+
+        /* Set up the hardware address */
+        sin = (struct sockaddr_in *) &areq.arp_ha;
+        sin->sin_family = ARPHRD_ETHER;
+        strcpy(areq.arp_dev, device);
+
+        /* Carry out the request */
+        if (ioctl(s, SIOCGARP, &areq) == -1)
+            perror("SIOCGARP");
+
+        else {
+            sprintf(hw_addr, "%02x:%02x:%02x:%02x:%02x:%02x",
+                        areq.arp_ha.sa_data[0] & 0xFF,
+                        areq.arp_ha.sa_data[1] & 0xFF,
+                        areq.arp_ha.sa_data[2] & 0xFF,
+                        areq.arp_ha.sa_data[3] & 0xFF,
+                        areq.arp_ha.sa_data[4] & 0xFF,
+                        areq.arp_ha.sa_data[5] & 0xFF);
+            err = 0;
+        }
+
+	/* Close the current socket */
+	close(s);
     }
 
-    fclose(fp);
-    return 0;
+    return err;
 }

Modified: trunk/libnet-arp-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-arp-perl/debian/changelog?rev=36406&op=diff
==============================================================================
--- trunk/libnet-arp-perl/debian/changelog (original)
+++ trunk/libnet-arp-perl/debian/changelog Mon May 25 18:59:29 2009
@@ -1,19 +1,11 @@
-libnet-arp-perl (1.0.5-1) UNRELEASED; urgency=low
+libnet-arp-perl (1.0.6-1) unstable; urgency=low
 
-  [Franck Joncourt]
-  * Back to UNRELEASED:
-    - possible bugs due to uninitialised variable
-    - main changes are against #528675 and remove warnings during the build
-    - possible new upstream release for arp_lookup_linux soon
-    - 1.0.6 should be ok
-
-  [Ryan Niebur]
   * New upstream release
   * Add myself to Uploaders
   * remove buffer_overflows.patch, prototypes.patch, and
     return-value.patch, that are applied upstream
 
- -- Ryan Niebur <ryanryan52 at gmail.com>  Sat, 23 May 2009 22:16:44 -0700
+ -- Ryan Niebur <ryanryan52 at gmail.com>  Mon, 25 May 2009 20:57:52 +0200
 
 libnet-arp-perl (1.0.4-1) unstable; urgency=low
 

Modified: trunk/libnet-arp-perl/get_mac_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-arp-perl/get_mac_linux.c?rev=36406&op=diff
==============================================================================
--- trunk/libnet-arp-perl/get_mac_linux.c (original)
+++ trunk/libnet-arp-perl/get_mac_linux.c Mon May 25 18:59:29 2009
@@ -32,7 +32,7 @@
   int    sock;
   struct ifreq iface;
 
-  if ( (mac == NULL) || (dev == NULL) )
+  if ( !strlen(mac) || !strlen(dev) )
     return -1;
 
   /* Set hardware address as unknown */




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