1 /*
2  * $Source: /cvs/src/sasl/mac/kerberos_includes/lsb_addr_comp.h,v $
3  * $Author: rjs3 $
4  * $Header: /cvs/src/sasl/mac/kerberos_includes/lsb_addr_comp.h,v 1.2 2001/12/04 02:06:05 rjs3 Exp $
5  *
6  * Copyright 1988 by the Massachusetts Institute of Technology.
7  *
8  * For copying and distribution information, please see the file
9  * <mit-copyright.h>.
10  *
11  * Comparison macros to emulate LSBFIRST comparison results of network
12  * byte-order quantities
13  */
14 
15 #ifndef	_KERBEROS_LSB_ADDR_COMP_H
16 #define	_KERBEROS_LSB_ADDR_COMP_H
17 
18 #pragma ident	"@(#)lsb_addr_comp.h	1.4	93/02/04 SMI"
19 
20 #include <kerberos/mit-copyright.h>
21 #include <kerberos/osconf.h>
22 
23 #ifdef	__cplusplus
24 extern "C" {
25 #endif
26 
27 #ifdef LSBFIRST
28 #define	lsb_net_ulong_less(x, y)	((x < y) ? -1 : ((x > y) ? 1 : 0))
29 #define	lsb_net_ushort_less(x, y)	((x < y) ? -1 : ((x > y) ? 1 : 0))
30 #else
31 /* MSBFIRST */
32 #define	u_char_comp(x, y) \
33 	(((x) > (y)) ? (1) : (((x) == (y)) ? (0) : (-1)))
34 /* This is gross, but... */
35 #define	lsb_net_ulong_less(x, y) long_less_than((u_char *)&x, (u_char *)&y)
36 #define	lsb_net_ushort_less(x, y) short_less_than((u_char *)&x, (u_char *)&y)
37 
38 #define	long_less_than(x, y) \
39 	(u_char_comp((x)[3], (y)[3]) ? u_char_comp((x)[3], (y)[3]) : \
40 	    (u_char_comp((x)[2], (y)[2]) ? u_char_comp((x)[2], (y)[2]) : \
41 	    (u_char_comp((x)[1], (y)[1]) ? u_char_comp((x)[1], (y)[1]) : \
42 	    (u_char_comp((x)[0], (y)[0])))))
43 #define	short_less_than(x, y) \
44 	(u_char_comp((x)[1], (y)[1]) ? u_char_comp((x)[1], (y)[1]) : \
45 	    (u_char_comp((x)[0], (y)[0])))
46 
47 #endif /* LSBFIRST */
48 
49 #ifdef	__cplusplus
50 }
51 #endif
52 
53 #endif	/* _KERBEROS_LSB_ADDR_COMP_H */
54