]> git.ozlabs.org Git - ppp.git/blob - pppd/eui64.h
IPV6 update from Tommi Komulainen
[ppp.git] / pppd / eui64.h
1 /*
2     eui64.h - EUI64 routines for IPv6CP.
3     Copyright (C) 1999  Tommi Komulainen <Tommi.Komulainen@iki.fi>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19     
20     $Id: eui64.h,v 1.2 1999/08/25 04:15:51 paulus Exp $
21 */
22
23 /*
24  * TODO:
25  *
26  * Maybe this should be done by processing struct in6_addr directly...
27  */
28 typedef union
29 {
30     u_int8_t e8[8];
31     u_int16_t e16[4];
32     u_int32_t e32[2];
33 } eui64_t;
34
35 #define eui64_iszero(e)         (((e).e32[0] | (e).e32[1]) == 0)
36 #define eui64_equals(e, o)      (((e).e32[0] == (o).e32[0]) && \
37                                 ((e).e32[1] == (o).e32[1]))
38 #define eui64_zero(e)           (e).e32[0] = (e).e32[1] = 0;
39
40 #define eui64_copy(s, d)        memcpy(&(d), &(s), sizeof(eui64_t))
41
42 #define eui64_magic(e)          do {                    \
43                                 (e).e32[0] = magic();   \
44                                 (e).e32[1] = magic();   \
45                                 (e).e8[0] &= ~2;        \
46                                 } while (0)
47 #define eui64_magic_nz(x)       do {                            \
48                                 eui64_magic(x);                 \
49                                 } while (eui64_iszero(x))
50 #define eui64_magic_ne(x, y)    do {                            \
51                                 eui64_magic(x);                 \
52                                 } while (eui64_equals(x, y))
53
54 #define eui64_get(ll, cp)       do {                            \
55                                 eui64_copy((*cp), (ll));        \
56                                 (cp) += sizeof(eui64_t);        \
57                                 } while (0)
58
59 #define eui64_put(ll, cp)       do {                            \
60                                 eui64_copy((ll), (*cp));        \
61                                 (cp) += sizeof(eui64_t);        \
62                                 } while (0)
63
64 #define eui64_set32(e, l)       do {                    \
65                                 (e).e32[0] = 0;         \
66                                 (e).e32[1] = htonl(l);  \
67                                 } while (0)
68 #define eui64_setlo32(e, l)     eui64_set32(e, l)
69
70 char *eui64_ntoa __P((eui64_t));        /* Returns ascii representation of id */