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