HFI support

This commit is contained in:
Jiri Popelka 2010-09-16 19:29:16 +02:00
parent 3385b91258
commit d7ac37c5b5
2 changed files with 191 additions and 1 deletions

183
net-tools-1.60-hfi.patch Normal file
View File

@ -0,0 +1,183 @@
diff -up net-tools-1.60/config.in.hfi net-tools-1.60/config.in
--- net-tools-1.60/config.in.hfi 2010-09-16 17:20:04.000000000 +0200
+++ net-tools-1.60/config.in 2010-09-16 19:17:35.000000000 +0200
@@ -83,6 +83,7 @@ bool '(Cisco)-HDLC/LAPB support' HAVE_HW
bool 'IrDA support' HAVE_HWIRDA y
bool 'Econet hardware support' HAVE_HWEC n
bool 'InfiniBand hardware support' HAVE_HWIB y
+bool 'HFI support' HAVE_HWHFI y
*
*
* Other Features.
diff -up net-tools-1.60/lib/hfi.c.hfi net-tools-1.60/lib/hfi.c
--- net-tools-1.60/lib/hfi.c.hfi 2010-09-16 19:17:58.000000000 +0200
+++ net-tools-1.60/lib/hfi.c 2010-09-16 19:19:49.000000000 +0200
@@ -0,0 +1,125 @@
+#include "config.h"
+
+#if HAVE_HWHFI
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if_arp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+#include "net-support.h"
+#include "pathnames.h"
+#include "intl.h"
+#include "util.h"
+
+extern struct hwtype hfi_hwtype;
+
+#define HF_ALEN 6 /* from hf_if.h */
+
+/* Display an HFI address in readable format. */
+static char *pr_hfi(unsigned char *ptr)
+{
+ static char buff[64];
+
+ snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
+ (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
+ (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
+ );
+ return (buff);
+}
+
+
+/* Input an HFI address and convert to binary. */
+static int in_hfi(char *bufp, struct sockaddr *sap)
+{
+ unsigned char *ptr;
+ char c, *orig;
+ int i;
+ unsigned val;
+
+ sap->sa_family = hfi_hwtype.type;
+ ptr = sap->sa_data;
+
+ i = 0;
+ orig = bufp;
+ while ((*bufp != '\0') && (i < HF_ALEN)) {
+ val = 0;
+ c = *bufp++;
+ if (isdigit(c))
+ val = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = c - 'A' + 10;
+ else {
+#ifdef DEBUG
+ fprintf(stderr, _("in_hfi(%s): invalid hfi address!\n"), orig);
+#endif
+ errno = EINVAL;
+ return (-1);
+ }
+ val <<= 4;
+ c = *bufp;
+ if (isdigit(c))
+ val |= c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val |= c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val |= c - 'A' + 10;
+ else if (c == ':' || c == 0)
+ val >>= 4;
+ else {
+#ifdef DEBUG
+ fprintf(stderr, _("in_hfi(%s): invalid hfi address!\n"), orig);
+#endif
+ errno = EINVAL;
+ return (-1);
+ }
+ if (c != 0)
+ bufp++;
+ *ptr++ = (unsigned char) (val & 0377);
+ i++;
+
+ /* We might get a semicolon here - not required. */
+ if (*bufp == ':') {
+ if (i == HF_ALEN) {
+#ifdef DEBUG
+ fprintf(stderr, _("in_hfi(%s): trailing : ignored!\n"),
+ orig)
+#endif
+ ; /* nothing */
+ }
+ bufp++;
+ }
+ }
+
+ /* That's it. Any trailing junk? */
+ if ((i == HF_ALEN) && (*bufp != '\0')) {
+#ifdef DEBUG
+ fprintf(stderr, _("in_hfi(%s): trailing junk!\n"), orig);
+ errno = EINVAL;
+ return (-1);
+#endif
+ }
+#ifdef DEBUG
+ fprintf(stderr, "in_hfi(%s): %s\n", orig, pr_hfi(sap->sa_data));
+#endif
+
+ return (0);
+}
+
+#if !defined(ARPHRD_HFI)
+#define ARPHRD_HFI 37 /* goes into if_arp.h */
+#endif
+
+struct hwtype hfi_hwtype =
+{
+ "hfi", NULL, /*"HFI", */ ARPHRD_HFI, HF_ALEN,
+ pr_hfi, in_hfi, NULL
+};
+
+
+#endif /* HAVE_HWHFI */
diff -up net-tools-1.60/lib/hw.c.hfi net-tools-1.60/lib/hw.c
--- net-tools-1.60/lib/hw.c.hfi 2010-09-16 17:20:04.000000000 +0200
+++ net-tools-1.60/lib/hw.c 2010-09-16 19:21:28.000000000 +0200
@@ -42,6 +42,7 @@ extern struct hwtype adaptive_hwtype;
extern struct hwtype strip_hwtype;
extern struct hwtype ether_hwtype;
+extern struct hwtype hfi_hwtype;
extern struct hwtype fddi_hwtype;
extern struct hwtype hippi_hwtype;
extern struct hwtype tr_hwtype;
@@ -146,6 +147,9 @@ static struct hwtype *hwtypes[] =
#if HAVE_HWX25
&x25_hwtype,
#endif
+#if HAVE_HWHFI
+ &hfi_hwtype,
+#endif
#if HAVE_HWIB
&ib_hwtype,
#endif
@@ -222,6 +226,9 @@ void hwinit()
#if HAVE_HWEC
ec_hwtype.title = _("Econet");
#endif
+#if HAVE_HWHFI
+ hfi_hwtype.title = _("HFI");
+#endif
#if HAVE_HWIB
ib_hwtype.title = _("InfiniBand");
#endif
diff -up net-tools-1.60/lib/Makefile.hfi net-tools-1.60/lib/Makefile
--- net-tools-1.60/lib/Makefile.hfi 2010-09-16 17:20:04.000000000 +0200
+++ net-tools-1.60/lib/Makefile 2010-09-16 19:22:34.000000000 +0200
@@ -16,7 +16,7 @@
#
-HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o strip.o irda.o ec_hw.o x25.o ib.o
+HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o strip.o irda.o ec_hw.o x25.o ib.o hfi.o
AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o econet.o x25.o
AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o x25_gr.o
AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o x25_sr.o

View File

@ -1,7 +1,7 @@
Summary: Basic networking tools
Name: net-tools
Version: 1.60
Release: 105%{?dist}
Release: 106%{?dist}
License: GPL+
Group: System Environment/Base
URL: http://net-tools.berlios.de/
@ -133,6 +133,9 @@ Patch87: net-tools-1.60-mii-gigabit.patch
# fix memory leak in netstat when run with -c option
Patch88: net-tools-1.60-netstat-leak.patch
# HFI support
Patch89: net-tools-1.60-hfi.patch
BuildRequires: gettext, libselinux
BuildRequires: libselinux-devel
Requires: hostname
@ -226,6 +229,7 @@ Most of them are obsolete. For replacement check iproute package.
%patch86 -p1 -b .doubleword
%patch87 -p1 -b .mii-gigabit
%patch88 -p1 -b .netstat-leak
%patch89 -p1 -b .hfi
cp %SOURCE1 ./config.h
cp %SOURCE2 ./config.make
@ -325,6 +329,9 @@ rm -rf %{buildroot}
%config(noreplace) %{_sysconfdir}/ethers
%changelog
* Thu Sep 16 2010 Jiri Popelka <jpopelka@redhat.com> - 1.60-106
- HFI support
* Thu Sep 16 2010 Jiri Popelka <jpopelka@redhat.com> - 1.60-105
- fixed memory leak in netstat when run with -c option