From owner-freebsd-hackers Fri Sep 4 10:42:18 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA27076 for freebsd-hackers-outgoing; Fri, 4 Sep 1998 10:42:18 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from roma.coe.ufrj.br (roma.coe.ufrj.br [146.164.53.65]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA27064 for ; Fri, 4 Sep 1998 10:42:07 -0700 (PDT) (envelope-from jonny@jonny.eng.br) Received: (from jonny@localhost) by roma.coe.ufrj.br (8.8.8/8.8.8) id OAA20958; Fri, 4 Sep 1998 14:39:46 -0300 (EST) (envelope-from jonny) From: Joao Carlos Mendes Luis Message-Id: <199809041739.OAA20958@roma.coe.ufrj.br> Subject: Re: bcmp abuse in networking code ? In-Reply-To: <199809021506.RAA10910@labinfo.iet.unipi.it> from Luigi Rizzo at "Sep 2, 98 05:06:30 pm" To: luigi@labinfo.iet.unipi.it (Luigi Rizzo) Date: Fri, 4 Sep 1998 14:39:46 -0300 (EST) Cc: hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG #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