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