1 /* $NetBSD: eui64.h,v 1.4 2014/10/25 21:11:37 christos Exp $ */ 2 3 /* 4 * eui64.h - EUI64 routines for IPv6CP. 5 * 6 * Copyright (c) 1999 Tommi Komulainen. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The name(s) of the authors of this software must not be used to 21 * endorse or promote products derived from this software without 22 * prior written permission. 23 * 24 * 4. Redistributions of any form whatsoever must retain the following 25 * acknowledgment: 26 * "This product includes software developed by Tommi Komulainen 27 * <Tommi.Komulainen@iki.fi>". 28 * 29 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 30 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 31 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 32 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 33 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 34 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 35 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 36 * 37 * Id: eui64.h,v 1.6 2002/12/04 23:03:32 paulus Exp 38 */ 39 40 #ifndef __EUI64_H__ 41 #define __EUI64_H__ 42 43 #if !defined(INET6) 44 #error "this file should only be included when INET6 is defined" 45 #endif /* not defined(INET6) */ 46 47 #if defined(SOL2) 48 #include <netinet/in.h> 49 50 typedef union { 51 uint8_t e8[8]; /* lower 64-bit IPv6 address */ 52 uint32_t e32[2]; /* lower 64-bit IPv6 address */ 53 } eui64_t; 54 55 /* 56 * Declare the two below, since in.h only defines them when _KERNEL 57 * is declared - which shouldn't be true when dealing with user-land programs 58 */ 59 #define s6_addr8 _S6_un._S6_u8 60 #define s6_addr32 _S6_un._S6_u32 61 62 #else /* else if not defined(SOL2) */ 63 64 /* 65 * TODO: 66 * 67 * Maybe this should be done by processing struct in6_addr directly... 68 */ 69 typedef union 70 { 71 u_int8_t e8[8]; 72 u_int16_t e16[4]; 73 u_int32_t e32[2]; 74 } eui64_t; 75 76 #endif /* defined(SOL2) */ 77 78 #define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0) 79 #define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \ 80 ((e).e32[1] == (o).e32[1])) 81 #define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0; 82 83 #define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t)) 84 85 #define eui64_magic(e) do { \ 86 (e).e32[0] = magic(); \ 87 (e).e32[1] = magic(); \ 88 (e).e8[0] &= ~2; \ 89 } while (0) 90 #define eui64_magic_nz(x) do { \ 91 eui64_magic(x); \ 92 } while (eui64_iszero(x)) 93 #define eui64_magic_ne(x, y) do { \ 94 eui64_magic(x); \ 95 } while (eui64_equals(x, y)) 96 97 #define eui64_get(ll, cp) do { \ 98 eui64_copy((*cp), (ll)); \ 99 (cp) += sizeof(eui64_t); \ 100 } while (0) 101 102 #define eui64_put(ll, cp) do { \ 103 eui64_copy((ll), (*cp)); \ 104 (cp) += sizeof(eui64_t); \ 105 } while (0) 106 107 #define eui64_set32(e, l) do { \ 108 (e).e32[0] = 0; \ 109 (e).e32[1] = htonl(l); \ 110 } while (0) 111 #define eui64_setlo32(e, l) eui64_set32(e, l) 112 113 char *eui64_ntoa __P((eui64_t)); /* Returns ascii representation of id */ 114 115 #endif /* __EUI64_H__ */ 116 117