]> git.ozlabs.org Git - ppp.git/blob - pppd/eui64.h
pppd man page: Update header to refer to pppd 2.5.x
[ppp.git] / pppd / eui64.h
1 /*
2  * eui64.h - EUI64 routines for IPv6CP.
3  *
4  * Copyright (c) 1999 Tommi Komulainen.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name(s) of the authors of this software must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission.
21  *
22  * 4. Redistributions of any form whatsoever must retain the following
23  *    acknowledgment:
24  *    "This product includes software developed by Tommi Komulainen
25  *     <Tommi.Komulainen@iki.fi>".
26  *
27  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34  *
35  */
36
37 #include "pppdconf.h"
38
39 #ifndef __EUI64_H__
40 #define __EUI64_H__
41
42 #if !defined(INET6)
43 #error  "this file should only be included when INET6 is defined"
44 #endif /* not defined(INET6) */
45
46 #if defined(SOL2)
47 #include <netinet/in.h>
48
49 typedef union {
50     uint8_t     e8[8];          /* lower 64-bit IPv6 address */
51     uint32_t    e32[2];         /* lower 64-bit IPv6 address */
52 } eui64_t;
53
54 /*
55  * Declare the two below, since in.h only defines them when _KERNEL
56  * is declared - which shouldn't be true when dealing with user-land programs
57  */
58 #define s6_addr8        _S6_un._S6_u8
59 #define s6_addr32       _S6_un._S6_u32
60
61 #else /* else if not defined(SOL2) */
62
63 /*
64  * TODO:
65  *
66  * Maybe this should be done by processing struct in6_addr directly...
67  */
68 typedef union
69 {
70     u_int8_t e8[8];
71     u_int16_t e16[4];
72     u_int32_t e32[2];
73 } eui64_t;
74
75 #endif /* defined(SOL2) */
76
77 #define eui64_iszero(e)         (((e).e32[0] | (e).e32[1]) == 0)
78 #define eui64_equals(e, o)      (((e).e32[0] == (o).e32[0]) && \
79                                 ((e).e32[1] == (o).e32[1]))
80 #define eui64_zero(e)           (e).e32[0] = (e).e32[1] = 0;
81
82 #define eui64_copy(s, d)        memcpy(&(d), &(s), sizeof(eui64_t))
83
84 #define eui64_magic(e)          do {                    \
85                                 (e).e32[0] = magic();   \
86                                 (e).e32[1] = magic();   \
87                                 (e).e8[0] &= ~2;        \
88                                 } while (0)
89 #define eui64_magic_nz(x)       do {                            \
90                                 eui64_magic(x);                 \
91                                 } while (eui64_iszero(x))
92 #define eui64_magic_ne(x, y)    do {                            \
93                                 eui64_magic(x);                 \
94                                 } while (eui64_equals(x, y))
95
96 #define eui64_get(ll, cp)       do {                            \
97                                 eui64_copy((*cp), (ll));        \
98                                 (cp) += sizeof(eui64_t);        \
99                                 } while (0)
100
101 #define eui64_put(ll, cp)       do {                            \
102                                 eui64_copy((ll), (*cp));        \
103                                 (cp) += sizeof(eui64_t);        \
104                                 } while (0)
105
106 #define eui64_set32(e, l)       do {                    \
107                                 (e).e32[0] = 0;         \
108                                 (e).e32[1] = htonl(l);  \
109                                 } while (0)
110 #define eui64_setlo32(e, l)     eui64_set32(e, l)
111
112 char *eui64_ntoa(eui64_t);      /* Returns ascii representation of id */
113
114 #endif /* __EUI64_H__ */
115