r36404 - in /branches/upstream/libnet-arp-perl/current: ARP.xs Changes arp.h.orig arp_lookup_linux.c get_mac_linux.c
thialme-guest at users.alioth.debian.org
thialme-guest at users.alioth.debian.org
Mon May 25 18:53:09 UTC 2009
Author: thialme-guest
Date: Mon May 25 18:53:04 2009
New Revision: 36404
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=36404
Log:
[svn-upgrade] Integrating new upstream version, libnet-arp-perl (1.0.6)
Removed:
branches/upstream/libnet-arp-perl/current/arp.h.orig
Modified:
branches/upstream/libnet-arp-perl/current/ARP.xs
branches/upstream/libnet-arp-perl/current/Changes
branches/upstream/libnet-arp-perl/current/arp_lookup_linux.c
branches/upstream/libnet-arp-perl/current/get_mac_linux.c
Modified: branches/upstream/libnet-arp-perl/current/ARP.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-arp-perl/current/ARP.xs?rev=36404&op=diff
==============================================================================
--- branches/upstream/libnet-arp-perl/current/ARP.xs (original)
+++ branches/upstream/libnet-arp-perl/current/ARP.xs Mon May 25 18:53:04 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: branches/upstream/libnet-arp-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-arp-perl/current/Changes?rev=36404&op=diff
==============================================================================
--- branches/upstream/libnet-arp-perl/current/Changes (original)
+++ branches/upstream/libnet-arp-perl/current/Changes Mon May 25 18:53:04 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: branches/upstream/libnet-arp-perl/current/arp_lookup_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-arp-perl/current/arp_lookup_linux.c?rev=36404&op=diff
==============================================================================
--- branches/upstream/libnet-arp-perl/current/arp_lookup_linux.c (original)
+++ branches/upstream/libnet-arp-perl/current/arp_lookup_linux.c Mon May 25 18:53:04 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: branches/upstream/libnet-arp-perl/current/get_mac_linux.c
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-arp-perl/current/get_mac_linux.c?rev=36404&op=diff
==============================================================================
--- branches/upstream/libnet-arp-perl/current/get_mac_linux.c (original)
+++ branches/upstream/libnet-arp-perl/current/get_mac_linux.c Mon May 25 18:53:04 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