Merge commit 'brent/register_phys_mem'
[freebsd-src/fkvm-freebsd.git] / usr.sbin / pppd / eui64.h
blob4b4b5052191baa949a1487f57c4bfbc53b1da52f
1 /* $FreeBSD$ */
2 /*
3 eui64.h - EUI64 routines for IPv6CP.
4 Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
6 Redistribution and use in source and binary forms are permitted
7 provided that the above copyright notice and this paragraph are
8 duplicated in all such forms and that any documentation,
9 advertising materials, and other materials related to such
10 distribution and use acknowledge that the software was developed
11 by Tommi Komulainen. The name of the author may not be used
12 to endorse or promote products derived from this software without
13 specific prior written permission.
14 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 $Id: eui64.h,v 1.3 1999/09/30 19:56:37 masputra Exp $
22 #ifndef __EUI64_H__
23 #define __EUI64_H__
25 #if !defined(INET6)
26 #error "this file should only be included when INET6 is defined"
27 #endif /* not defined(INET6) */
29 #if defined(SOL2)
30 #include <netinet/in.h>
32 typedef union {
33 uint8_t e8[8]; /* lower 64-bit IPv6 address */
34 uint32_t e32[2]; /* lower 64-bit IPv6 address */
35 } eui64_t;
38 * Declare the two below, since in.h only defines them when _KERNEL
39 * is declared - which shouldn't be true when dealing with user-land programs
41 #define s6_addr8 _S6_un._S6_u8
42 #define s6_addr32 _S6_un._S6_u32
44 #else /* else if not defined(SOL2) */
47 * TODO:
49 * Maybe this should be done by processing struct in6_addr directly...
51 typedef union
53 u_int8_t e8[8];
54 u_int16_t e16[4];
55 u_int32_t e32[2];
56 } eui64_t;
58 #endif /* defined(SOL2) */
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;
65 #define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t))
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))
79 #define eui64_get(ll, cp) do { \
80 eui64_copy((*cp), (ll)); \
81 (cp) += sizeof(eui64_t); \
82 } while (0)
84 #define eui64_put(ll, cp) do { \
85 eui64_copy((ll), (*cp)); \
86 (cp) += sizeof(eui64_t); \
87 } while (0)
89 #define eui64_set32(e, l) do { \
90 (e).e32[0] = 0; \
91 (e).e32[1] = htonl(l); \
92 } while (0)
93 #define eui64_setlo32(e, l) eui64_set32(e, l)
95 char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */
97 #endif /* __EUI64_H__ */