2 eui64.h - EUI64 routines for IPv6CP.
3 Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
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.
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.
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.
20 $Id: eui64.h,v 1.3 1999/09/30 19:56:37 masputra Exp $
27 #error "this file should only be included when INET6 is defined"
28 #endif /* not defined(INET6) */
31 #include <netinet/in.h>
34 uint8_t e8[8]; /* lower 64-bit IPv6 address */
35 uint32_t e32[2]; /* lower 64-bit IPv6 address */
39 * Declare the two below, since in.h only defines them when _KERNEL
40 * is declared - which shouldn't be true when dealing with user-land programs
42 #define s6_addr8 _S6_un._S6_u8
43 #define s6_addr32 _S6_un._S6_u32
45 #else /* else if not defined(SOL2) */
50 * Maybe this should be done by processing struct in6_addr directly...
59 #endif /* defined(SOL2) */
61 #define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0)
62 #define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \
63 ((e).e32[1] == (o).e32[1]))
64 #define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0;
66 #define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t))
68 #define eui64_magic(e) do { \
69 (e).e32[0] = magic(); \
70 (e).e32[1] = magic(); \
73 #define eui64_magic_nz(x) do { \
75 } while (eui64_iszero(x))
76 #define eui64_magic_ne(x, y) do { \
78 } while (eui64_equals(x, y))
80 #define eui64_get(ll, cp) do { \
81 eui64_copy((*cp), (ll)); \
82 (cp) += sizeof(eui64_t); \
85 #define eui64_put(ll, cp) do { \
86 eui64_copy((ll), (*cp)); \
87 (cp) += sizeof(eui64_t); \
90 #define eui64_set32(e, l) do { \
92 (e).e32[1] = htonl(l); \
94 #define eui64_setlo32(e, l) eui64_set32(e, l)
96 char *eui64_ntoa __P((eui64_t)); /* Returns ascii representation of id */
98 #endif /* __EUI64_H__ */