Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net In ether_output(), don't bother calling memcpy() to ...



details:   https://anonhg.NetBSD.org/src/rev/4d1c43b2f3a8
branches:  trunk
changeset: 535464:4d1c43b2f3a8
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Aug 19 18:58:50 2002 +0000

description:
In ether_output(), don't bother calling memcpy() to plop the ethertype
into the packet: On system with no strict alignment constraints, just
assign the value, and on others, do an inline 2 byte copy.

diffstat:

 sys/net/if_ethersubr.c |  21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 2ef62ef2e862 -r 4d1c43b2f3a8 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Mon Aug 19 18:58:26 2002 +0000
+++ b/sys/net/if_ethersubr.c    Mon Aug 19 18:58:50 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.95 2002/05/18 22:52:44 itojun Exp $ */
+/*     $NetBSD: if_ethersubr.c,v 1.96 2002/08/19 18:58:50 thorpej Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.95 2002/05/18 22:52:44 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.96 2002/08/19 18:58:50 thorpej Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -479,8 +479,21 @@
        if (m == 0)
                senderr(ENOBUFS);
        eh = mtod(m, struct ether_header *);
-       bcopy((caddr_t)&etype,(caddr_t)&eh->ether_type,
-               sizeof(eh->ether_type));
+       /* Note: etype is already in network byte order. */
+#ifdef __NO_STRICT_ALIGNMENT
+       eh->ether_type = type;
+#else
+       {
+               uint8_t *dstp = (uint8_t *) &eh->ether_type;
+#if BYTE_ORDER == BIG_ENDIAN
+               dstp[0] = etype >> 8;
+               dstp[1] = etype; 
+#else
+               dstp[0] = etype;
+               dstp[1] = etype >> 8;
+#endif /* BYTE_ORDER == BIG_ENDIAN */
+       }
+#endif /* __NO_STRICT_ALIGNMENT */
        bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
        if (hdrcmplt)
                bcopy((caddr_t)esrc, (caddr_t)eh->ether_shost,



Home | Main Index | Thread Index | Old Index