Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Sep 1998 14:39:46 -0300 (EST)
From:      Joao Carlos Mendes Luis <jonny@jonny.eng.br>
To:        luigi@labinfo.iet.unipi.it (Luigi Rizzo)
Cc:        hackers@FreeBSD.ORG
Subject:   Re: bcmp abuse in networking code ?
Message-ID:  <199809041739.OAA20958@roma.coe.ufrj.br>
In-Reply-To: <199809021506.RAA10910@labinfo.iet.unipi.it> from Luigi Rizzo at "Sep 2, 98 05:06:30 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
#define quoting(Luigi Rizzo)
// poking around in /sys/net and /sys/netinet, i frequently see bcmp() being
// used to compare ethernet addresses (but not only those). In some cases,
// even against the ethernet broadcast address.
// 
// In my revised bridge code i have the following macros
// 
// #define ETH_MATCH(a,b) ( \
//     ((unsigned short *)(a))[2] == ((unsigned short *)(b))[2] && \
//     *((unsigned int *)(a)) == *((unsigned int *)(b)) )

Indeed very good, but why not adhere to older interfaces ?  SunOS and
Solaris have defined this as ether_cmp() for a long time.

Here's a extract from Solaris 2.4's /usr/include/netinet/if_ether.h:

...
/*
 * Compare two Ethernet addresses - assumes that the two given
 * pointers can be referenced as shorts.  On architectures
 * where this is not the case, use bcmp instead.  Note that like
 * bcmp, we return zero if they are the SAME.
 */
#if defined(mc68000)
/*
 * On 680x0 machines, we can do a longword compare that is NOT
 * longword aligned, as long as it is even aligned.
 */
#define ether_cmp(a, b) (((short *)a)[2] != ((short *)b)[2] || \
        *((long *)a) != *((long *)b))
#endif

#if defined(sparc)
#define ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \
        ((short *)b)[1] != ((short *)a)[1] || \
        ((short *)b)[0] != ((short *)a)[0])
#endif

#ifndef ether_cmp
#define ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6))
#endif
...

There are similars for ether_copy() also.

					Jonny

--
Joao Carlos Mendes Luis            M.Sc. Student
jonny@jonny.eng.br                 Universidade Federal do Rio de Janeiro
"There are two major products that come out of Berkeley: LSD and Unix.
 We don't believe this to be a coincidence." -- Jeremy  S. Anderson

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809041739.OAA20958>