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 * $Id: eui64.h,v 1.6 2002/12/04 23:03:32 paulus Exp $ 36 */ 37 38 #include "netif/ppp/ppp_opts.h" 39 #if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ 40 41 #ifndef EUI64_H 42 #define EUI64_H 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /* 49 * @todo: 50 * 51 * Maybe this should be done by processing struct in6_addr directly... 52 */ 53 typedef union 54 { 55 u8_t e8[8]; 56 u16_t e16[4]; 57 u32_t e32[2]; 58 } eui64_t; 59 60 #define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0) 61 #define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \ 62 ((e).e32[1] == (o).e32[1])) 63 #define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0; 64 65 #define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t)) 66 67 #define eui64_magic(e) do { \ 68 (e).e32[0] = magic(); \ 69 (e).e32[1] = magic(); \ 70 (e).e8[0] &= ~2; \ 71 } while (0) 72 #define eui64_magic_nz(x) do { \ 73 eui64_magic(x); \ 74 } while (eui64_iszero(x)) 75 #define eui64_magic_ne(x, y) do { \ 76 eui64_magic(x); \ 77 } while (eui64_equals(x, y)) 78 79 #define eui64_get(ll, cp) do { \ 80 eui64_copy((*cp), (ll)); \ 81 (cp) += sizeof(eui64_t); \ 82 } while (0) 83 84 #define eui64_put(ll, cp) do { \ 85 eui64_copy((ll), (*cp)); \ 86 (cp) += sizeof(eui64_t); \ 87 } while (0) 88 89 #define eui64_set32(e, l) do { \ 90 (e).e32[0] = 0; \ 91 (e).e32[1] = lwip_htonl(l); \ 92 } while (0) 93 #define eui64_setlo32(e, l) eui64_set32(e, l) 94 95 char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */ 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101 #endif /* EUI64_H */ 102 #endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */ 103