net-tools/net-tools-1.60-hfi.patch

184 lines
4.9 KiB
Diff
Raw Normal View History

2010-09-16 17:29:16 +00:00
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