diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2006-04-16 16:32:09 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2006-04-16 16:32:09 +0000 |
commit | 13211293b56c5a2ce7ee7cc76d22039420a3e6fa (patch) | |
tree | b79dfc43493e216a1cc661567c1727683732b2a9 /sys | |
parent | a716d24079738b3f7e47bec9ac88fdaae2186578 (diff) |
Correctly computed the mac address checksum on big-endian platforms.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ic/lemac.c | 14 |
1 files changed, 13 insertions, 1 deletions
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; |