From 606d516e967d8cd0a34e291e8528cd67dea2cc67 Mon Sep 17 00:00:00 2001
From: Mike Hibler <mike@flux.utah.edu>
Date: Tue, 20 Aug 2002 21:05:56 +0000
Subject: [PATCH] Hack to compensate for Linux driver bug: the tulip driver
 reports the MAC incorrectly (byte-swapped) for at least one type of Lite-on
 card (the ones that UK has).  BSD reports it correctly.  "Correctly" is
 defined by the vendor ID having the value assigned to that vendor.

---
 tmcd/findif.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tmcd/findif.c b/tmcd/findif.c
index 7fb035466e..433bb10e0f 100644
--- a/tmcd/findif.c
+++ b/tmcd/findif.c
@@ -182,6 +182,24 @@ find_iface(char *macaddr)
 		if (ioctl(sock, SIOCGIFHWADDR, ifr) < 0)
 			continue;
 
+		/*
+		 * Great, the tulip driver mis-reports the MAC address
+		 * on at least one type of lite-on card.  Looks like it
+		 * byte-swaps pairs of octets.  We recognize the offending
+		 * vendor ID (as reported, it is not a valid ID, so there
+		 * is no ambiguity)
+		 */
+		if ((unsigned char)ifr->ifr_addr.sa_data[1] == 0x00 &&
+		    (unsigned char)ifr->ifr_addr.sa_data[0] == 0x02 &&
+		    (unsigned char)ifr->ifr_addr.sa_data[3] == 0xE3) {
+			unsigned short *usp;
+
+			usp = (unsigned short *)ifr->ifr_addr.sa_data;
+			usp[0] = ntohs(usp[0]);
+			usp[1] = ntohs(usp[1]);
+			usp[2] = ntohs(usp[2]);
+		}
+
 		sprintf(enet, "%02x%02x%02x%02x%02x%02x",
 			(unsigned char) ifr->ifr_addr.sa_data[0],
 			(unsigned char) ifr->ifr_addr.sa_data[1],
-- 
GitLab