From 13211293b56c5a2ce7ee7cc76d22039420a3e6fa Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Sun, 16 Apr 2006 16:32:09 +0000 Subject: Correctly computed the mac address checksum on big-endian platforms. --- sys/dev/ic/lemac.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sys') diff --git a/sys/dev/ic/lemac.c b/sys/dev/ic/lemac.c index 38acec88274..4fb409dc208 100644 --- a/sys/dev/ic/lemac.c +++ b/sys/dev/ic/lemac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lemac.c,v 1.9 2006/03/25 22:41:43 djm Exp $ */ +/* $OpenBSD: lemac.c,v 1.10 2006/04/16 16:32:08 miod Exp $ */ /* $NetBSD: lemac.c,v 1.20 2001/06/13 10:46:02 wiz Exp $ */ /*- @@ -413,14 +413,22 @@ lemac_read_macaddr(unsigned char *hwaddr, const bus_space_tag_t iot, if (hwaddr[0] & 1) return (-1); +#if BYTE_ORDER == LITTLE_ENDIAN cksum = *(u_short *)&hwaddr[0]; +#else + cksum = ((u_short)hwaddr[1] << 8) | (u_short)hwaddr[0]; +#endif hwaddr[2] = bus_space_read_1(iot, ioh, ioreg); hwaddr[3] = bus_space_read_1(iot, ioh, ioreg); cksum *= 2; if (cksum > 65535) cksum -= 65535; +#if BYTE_ORDER == LITTLE_ENDIAN cksum += *(u_short *)&hwaddr[2]; +#else + cksum += ((u_short)hwaddr[3] << 8) | (u_short)hwaddr[2]; +#endif if (cksum > 65535) cksum -= 65535; @@ -429,7 +437,11 @@ lemac_read_macaddr(unsigned char *hwaddr, const bus_space_tag_t iot, cksum *= 2; if (cksum > 65535) cksum -= 65535; +#if BYTE_ORDER == LITTLE_ENDIAN cksum += *(u_short *)&hwaddr[4]; +#else + cksum += ((u_short)hwaddr[5] << 8) | (u_short)hwaddr[4]; +#endif if (cksum >= 65535) cksum -= 65535; -- cgit v1.2.3