]> git.ozlabs.org Git - ppp.git/blob - pppd/eui64.h
added files for IPV6
[ppp.git] / pppd / eui64.h
1 /*
2  * eui64.h - EUI64 routines for IPv6CP.
3  *
4  * (c) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that the above copyright notice and this paragraph are
8  * duplicated in all such forms and that any documentation,
9  * advertising materials, and other materials related to such
10  * distribution and use acknowledge that the software was developed
11  * by Carnegie Mellon University.  The name of the
12  * University may not be used to endorse or promote products derived
13  * from this software without specific prior written permission.
14  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  * $Id: eui64.h,v 1.1 1999/08/13 01:58:43 paulus Exp $
19  */
20
21 /*
22  * TODO:
23  *
24  * Maybe this should be done by processing struct in6_addr directly...
25  */
26 typedef union
27 {
28     u_int8_t e8[8];
29     u_int16_t e16[4];
30     u_int32_t e32[2];
31 } eui64_t;
32
33 #define eui64_iszero(e)         (((e).e32[0] | (e).e32[1]) == 0)
34 #define eui64_equals(e, o)      (((e).e32[0] == (o).e32[0]) && \
35                                 ((e).e32[1] == (o).e32[1]))
36 #define eui64_zero(e)           (e).e32[0] = (e).e32[1] = 0;
37
38 #define eui64_copy(s, d)        memcpy(&(d), &(s), sizeof(eui64_t))
39
40 #define eui64_magic(e)          do {                    \
41                                 (e).e32[0] = magic();   \
42                                 (e).e32[1] = magic();   \
43                                 (e).e8[0] &= ~2;        \
44                                 } while (0)
45 #define eui64_magic_nz(x)       do {                            \
46                                 eui64_magic(x);                 \
47                                 } while (eui64_iszero(x))
48 #define eui64_magic_ne(x, y)    do {                            \
49                                 eui64_magic(x);                 \
50                                 } while (eui64_equals(x, y))
51
52 #define eui64_get(ll, cp)       do {                            \
53                                 eui64_copy((*cp), (ll));        \
54                                 (cp) += sizeof(eui64_t);        \
55                                 } while (0)
56
57 #define eui64_put(ll, cp)       do {                            \
58                                 eui64_copy((ll), (*cp));        \
59                                 (cp) += sizeof(eui64_t);        \
60                                 } while (0)
61
62 #define eui64_set32(e, l)       do {                    \
63                                 (e).e32[0] = 0;         \
64                                 (e).e32[1] = htonl(l);  \
65                                 } while (0)
66 #define eui64_setlo32(e, l)     eui64_set32(e, l)
67
68 char *eui64_ntoa __P((eui64_t));        /* Returns ascii representation of id */