]> git.ozlabs.org Git - ppp.git/blob - pppd/eui64.h
Patches from Frank Cusack:
[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     Redistribution and use in source and binary forms are permitted
6     provided that the above copyright notice and this paragraph are
7     duplicated in all such forms and that any documentation,
8     advertising materials, and other materials related to such
9     distribution and use acknowledge that the software was developed
10     by Tommi Komulainen.  The name of the author may not be used
11     to endorse or promote products derived from this software without
12     specific prior written permission.
13     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14     IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15     WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
17     
18     $Id: eui64.h,v 1.5 2000/08/05 06:46:47 paulus Exp $
19 */
20
21 #ifndef __EUI64_H__
22 #define __EUI64_H__
23
24 #if !defined(INET6)
25 #error  "this file should only be included when INET6 is defined"
26 #endif /* not defined(INET6) */
27
28 #if defined(SOL2)
29 #include <netinet/in.h>
30
31 typedef union {
32     uint8_t     e8[8];          /* lower 64-bit IPv6 address */
33     uint32_t    e32[2];         /* lower 64-bit IPv6 address */
34 } eui64_t;
35
36 /*
37  * Declare the two below, since in.h only defines them when _KERNEL
38  * is declared - which shouldn't be true when dealing with user-land programs
39  */
40 #define s6_addr8        _S6_un._S6_u8
41 #define s6_addr32       _S6_un._S6_u32
42
43 #else /* else if not defined(SOL2) */
44
45 /*
46  * TODO:
47  *
48  * Maybe this should be done by processing struct in6_addr directly...
49  */
50 typedef union
51 {
52     u_int8_t e8[8];
53     u_int16_t e16[4];
54     u_int32_t e32[2];
55 } eui64_t;
56
57 #endif /* defined(SOL2) */
58
59 #define eui64_iszero(e)         (((e).e32[0] | (e).e32[1]) == 0)
60 #define eui64_equals(e, o)      (((e).e32[0] == (o).e32[0]) && \
61                                 ((e).e32[1] == (o).e32[1]))
62 #define eui64_zero(e)           (e).e32[0] = (e).e32[1] = 0;
63
64 #define eui64_copy(s, d)        memcpy(&(d), &(s), sizeof(eui64_t))
65
66 #define eui64_magic(e)          do {                    \
67                                 (e).e32[0] = magic();   \
68                                 (e).e32[1] = magic();   \
69                                 (e).e8[0] &= ~2;        \
70                                 } while (0)
71 #define eui64_magic_nz(x)       do {                            \
72                                 eui64_magic(x);                 \
73                                 } while (eui64_iszero(x))
74 #define eui64_magic_ne(x, y)    do {                            \
75                                 eui64_magic(x);                 \
76                                 } while (eui64_equals(x, y))
77
78 #define eui64_get(ll, cp)       do {                            \
79                                 eui64_copy((*cp), (ll));        \
80                                 (cp) += sizeof(eui64_t);        \
81                                 } while (0)
82
83 #define eui64_put(ll, cp)       do {                            \
84                                 eui64_copy((ll), (*cp));        \
85                                 (cp) += sizeof(eui64_t);        \
86                                 } while (0)
87
88 #define eui64_set32(e, l)       do {                    \
89                                 (e).e32[0] = 0;         \
90                                 (e).e32[1] = htonl(l);  \
91                                 } while (0)
92 #define eui64_setlo32(e, l)     eui64_set32(e, l)
93
94 char *eui64_ntoa __P((eui64_t));        /* Returns ascii representation of id */
95
96 #endif /* __EUI64_H__ */
97