1*d6eebaa4SHervé Poussineau /* 2*d6eebaa4SHervé Poussineau * eui64.h - EUI64 routines for IPv6CP. 3*d6eebaa4SHervé Poussineau * 4*d6eebaa4SHervé Poussineau * Copyright (c) 1999 Tommi Komulainen. All rights reserved. 5*d6eebaa4SHervé Poussineau * 6*d6eebaa4SHervé Poussineau * Redistribution and use in source and binary forms, with or without 7*d6eebaa4SHervé Poussineau * modification, are permitted provided that the following conditions 8*d6eebaa4SHervé Poussineau * are met: 9*d6eebaa4SHervé Poussineau * 10*d6eebaa4SHervé Poussineau * 1. Redistributions of source code must retain the above copyright 11*d6eebaa4SHervé Poussineau * notice, this list of conditions and the following disclaimer. 12*d6eebaa4SHervé Poussineau * 13*d6eebaa4SHervé Poussineau * 2. Redistributions in binary form must reproduce the above copyright 14*d6eebaa4SHervé Poussineau * notice, this list of conditions and the following disclaimer in 15*d6eebaa4SHervé Poussineau * the documentation and/or other materials provided with the 16*d6eebaa4SHervé Poussineau * distribution. 17*d6eebaa4SHervé Poussineau * 18*d6eebaa4SHervé Poussineau * 3. The name(s) of the authors of this software must not be used to 19*d6eebaa4SHervé Poussineau * endorse or promote products derived from this software without 20*d6eebaa4SHervé Poussineau * prior written permission. 21*d6eebaa4SHervé Poussineau * 22*d6eebaa4SHervé Poussineau * 4. Redistributions of any form whatsoever must retain the following 23*d6eebaa4SHervé Poussineau * acknowledgment: 24*d6eebaa4SHervé Poussineau * "This product includes software developed by Tommi Komulainen 25*d6eebaa4SHervé Poussineau * <Tommi.Komulainen@iki.fi>". 26*d6eebaa4SHervé Poussineau * 27*d6eebaa4SHervé Poussineau * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 28*d6eebaa4SHervé Poussineau * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 29*d6eebaa4SHervé Poussineau * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 30*d6eebaa4SHervé Poussineau * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 31*d6eebaa4SHervé Poussineau * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 32*d6eebaa4SHervé Poussineau * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 33*d6eebaa4SHervé Poussineau * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 34*d6eebaa4SHervé Poussineau * 35*d6eebaa4SHervé Poussineau * $Id: eui64.h,v 1.6 2002/12/04 23:03:32 paulus Exp $ 36*d6eebaa4SHervé Poussineau */ 37*d6eebaa4SHervé Poussineau 38*d6eebaa4SHervé Poussineau #include "netif/ppp/ppp_opts.h" 39*d6eebaa4SHervé Poussineau #if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ 40*d6eebaa4SHervé Poussineau 41*d6eebaa4SHervé Poussineau #ifndef EUI64_H 42*d6eebaa4SHervé Poussineau #define EUI64_H 43*d6eebaa4SHervé Poussineau 44*d6eebaa4SHervé Poussineau #ifdef __cplusplus 45*d6eebaa4SHervé Poussineau extern "C" { 46*d6eebaa4SHervé Poussineau #endif 47*d6eebaa4SHervé Poussineau 48*d6eebaa4SHervé Poussineau /* 49*d6eebaa4SHervé Poussineau * @todo: 50*d6eebaa4SHervé Poussineau * 51*d6eebaa4SHervé Poussineau * Maybe this should be done by processing struct in6_addr directly... 52*d6eebaa4SHervé Poussineau */ 53*d6eebaa4SHervé Poussineau typedef union 54*d6eebaa4SHervé Poussineau { 55*d6eebaa4SHervé Poussineau u8_t e8[8]; 56*d6eebaa4SHervé Poussineau u16_t e16[4]; 57*d6eebaa4SHervé Poussineau u32_t e32[2]; 58*d6eebaa4SHervé Poussineau } eui64_t; 59*d6eebaa4SHervé Poussineau 60*d6eebaa4SHervé Poussineau #define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0) 61*d6eebaa4SHervé Poussineau #define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \ 62*d6eebaa4SHervé Poussineau ((e).e32[1] == (o).e32[1])) 63*d6eebaa4SHervé Poussineau #define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0; 64*d6eebaa4SHervé Poussineau 65*d6eebaa4SHervé Poussineau #define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t)) 66*d6eebaa4SHervé Poussineau 67*d6eebaa4SHervé Poussineau #define eui64_magic(e) do { \ 68*d6eebaa4SHervé Poussineau (e).e32[0] = magic(); \ 69*d6eebaa4SHervé Poussineau (e).e32[1] = magic(); \ 70*d6eebaa4SHervé Poussineau (e).e8[0] &= ~2; \ 71*d6eebaa4SHervé Poussineau } while (0) 72*d6eebaa4SHervé Poussineau #define eui64_magic_nz(x) do { \ 73*d6eebaa4SHervé Poussineau eui64_magic(x); \ 74*d6eebaa4SHervé Poussineau } while (eui64_iszero(x)) 75*d6eebaa4SHervé Poussineau #define eui64_magic_ne(x, y) do { \ 76*d6eebaa4SHervé Poussineau eui64_magic(x); \ 77*d6eebaa4SHervé Poussineau } while (eui64_equals(x, y)) 78*d6eebaa4SHervé Poussineau 79*d6eebaa4SHervé Poussineau #define eui64_get(ll, cp) do { \ 80*d6eebaa4SHervé Poussineau eui64_copy((*cp), (ll)); \ 81*d6eebaa4SHervé Poussineau (cp) += sizeof(eui64_t); \ 82*d6eebaa4SHervé Poussineau } while (0) 83*d6eebaa4SHervé Poussineau 84*d6eebaa4SHervé Poussineau #define eui64_put(ll, cp) do { \ 85*d6eebaa4SHervé Poussineau eui64_copy((ll), (*cp)); \ 86*d6eebaa4SHervé Poussineau (cp) += sizeof(eui64_t); \ 87*d6eebaa4SHervé Poussineau } while (0) 88*d6eebaa4SHervé Poussineau 89*d6eebaa4SHervé Poussineau #define eui64_set32(e, l) do { \ 90*d6eebaa4SHervé Poussineau (e).e32[0] = 0; \ 91*d6eebaa4SHervé Poussineau (e).e32[1] = lwip_htonl(l); \ 92*d6eebaa4SHervé Poussineau } while (0) 93*d6eebaa4SHervé Poussineau #define eui64_setlo32(e, l) eui64_set32(e, l) 94*d6eebaa4SHervé Poussineau 95*d6eebaa4SHervé Poussineau char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */ 96*d6eebaa4SHervé Poussineau 97*d6eebaa4SHervé Poussineau #ifdef __cplusplus 98*d6eebaa4SHervé Poussineau } 99*d6eebaa4SHervé Poussineau #endif 100*d6eebaa4SHervé Poussineau 101*d6eebaa4SHervé Poussineau #endif /* EUI64_H */ 102*d6eebaa4SHervé Poussineau #endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */ 103