1 | /* |
---|
2 | * Copyright 1988 by the Massachusetts Institute of Technology. |
---|
3 | * |
---|
4 | * For copying and distribution information, please see the file |
---|
5 | * <mit-copyright.h>. |
---|
6 | * |
---|
7 | * Comparison macros to emulate LSBFIRST comparison results of network |
---|
8 | * byte-order quantities |
---|
9 | */ |
---|
10 | |
---|
11 | #include "mit-copyright.h" |
---|
12 | #ifndef LSB_ADDR_COMP_DEFS |
---|
13 | #define LSB_ADDR_COMP_DEFS |
---|
14 | |
---|
15 | #include "osconf.h" |
---|
16 | |
---|
17 | #ifdef LSBFIRST |
---|
18 | #define lsb_net_ulong_less(x,y) ((x < y) ? -1 : ((x > y) ? 1 : 0)) |
---|
19 | #define lsb_net_ushort_less(x,y) ((x < y) ? -1 : ((x > y) ? 1 : 0)) |
---|
20 | #else |
---|
21 | /* MSBFIRST */ |
---|
22 | #define u_char_comp(x,y) \ |
---|
23 | (((x)>(y))?(1):(((x)==(y))?(0):(-1))) |
---|
24 | /* This is gross, but... */ |
---|
25 | #define lsb_net_ulong_less(x, y) long_less_than((u_char *)&x, (u_char *)&y) |
---|
26 | #define lsb_net_ushort_less(x, y) short_less_than((u_char *)&x, (u_char *)&y) |
---|
27 | |
---|
28 | #define long_less_than(x,y) \ |
---|
29 | (u_char_comp((x)[3],(y)[3])?u_char_comp((x)[3],(y)[3]): \ |
---|
30 | (u_char_comp((x)[2],(y)[2])?u_char_comp((x)[2],(y)[2]): \ |
---|
31 | (u_char_comp((x)[1],(y)[1])?u_char_comp((x)[1],(y)[1]): \ |
---|
32 | (u_char_comp((x)[0],(y)[0]))))) |
---|
33 | #define short_less_than(x,y) \ |
---|
34 | (u_char_comp((x)[1],(y)[1])?u_char_comp((x)[1],(y)[1]): \ |
---|
35 | (u_char_comp((x)[0],(y)[0]))) |
---|
36 | |
---|
37 | #endif /* LSBFIRST */ |
---|
38 | |
---|
39 | #endif /* LSB_ADDR_COMP_DEFS */ |
---|