]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
a98c2da5 AJ |
9 | #ifndef _SQUID_EUI_EUI64_H |
10 | #define _SQUID_EUI_EUI64_H | |
11 | ||
a98c2da5 AJ |
12 | #if USE_SQUID_EUI |
13 | ||
63bd4bf7 A |
14 | namespace Ip |
15 | { | |
16 | class Address; | |
e5519212 | 17 | } |
a98c2da5 | 18 | |
a98c2da5 | 19 | #include <cstring> |
a98c2da5 AJ |
20 | #if HAVE_SYS_EUI64_H |
21 | #include <sys/eui64.h> | |
22 | #endif | |
23 | ||
05320519 A |
24 | namespace Eui |
25 | { | |
a98c2da5 AJ |
26 | |
27 | /* EUI-64 is 8 bytes. */ | |
28 | #if defined(EUI64_LEN) | |
29 | #define SZ_EUI64_BUF EUI64_LEN | |
30 | #else | |
31 | #define SZ_EUI64_BUF 8 | |
32 | #endif | |
33 | ||
05320519 A |
34 | class Eui64 |
35 | { | |
a98c2da5 AJ |
36 | |
37 | public: | |
68e47c3e | 38 | Eui64() { clear(); } |
b56b37cf | 39 | |
fdd757c5 FC |
40 | bool operator== (const Eui64 &t) const { return (memcmp(eui,t.eui,SZ_EUI64_BUF) == 0); } |
41 | bool operator< (const Eui64 &t) const { return (memcmp(eui,t.eui,SZ_EUI64_BUF) < 0); } | |
a98c2da5 AJ |
42 | |
43 | const unsigned char *get(void); | |
44 | ||
45 | bool set(const char *src, const int len) { | |
46 | if (len > SZ_EUI64_BUF) return false; | |
47 | if (len < SZ_EUI64_BUF) clear(); | |
48 | memcpy(eui, src, len); | |
49 | return true; | |
68e47c3e | 50 | } |
a98c2da5 | 51 | |
68e47c3e | 52 | void clear() { memset(eui, 0, SZ_EUI64_BUF); } |
a98c2da5 AJ |
53 | |
54 | /** | |
55 | * Decode an ascii representation of an EUI-64 address. | |
56 | * | |
57 | * \param asc ASCII representation of an EUI-64 address | |
58 | * \param eth Binary representation of the EUI_64 address | |
59 | * \retval false Conversion to binary failed. Invalid address | |
60 | * \retval true Conversion completed successfully | |
61 | */ | |
62 | bool decode(const char *asc); | |
63 | ||
64 | /** | |
65 | * Encode an ascii representation (asc) of an EUI-64 address. | |
66 | * | |
67 | * \param buf Buffer to receive ASCII representation of an EUI-64 address | |
68 | * \param len Length of the buffer space available. Must be >= SZ_EUI64_BUF bytes or the encode will fail. | |
69 | * \param eui Binary representation of the EUI-64 address | |
70 | * \retval false Conversion to ASCII failed. | |
71 | * \retval true Conversion completed successfully. | |
72 | */ | |
736a7789 | 73 | bool encode(char *buf, const int len) const; |
a98c2da5 AJ |
74 | |
75 | // lookup an EUI-64 address via IPv6 SLAAC or NDP | |
00406b24 | 76 | bool lookup(const Ip::Address &c); |
a98c2da5 AJ |
77 | |
78 | // lookup an EUI-64 address via IPv6 NDP | |
00406b24 | 79 | bool lookupNdp(const Ip::Address &c); |
a98c2da5 AJ |
80 | |
81 | // lookup an EUI-64 address via decoding the IPv6 address SLAAC data | |
00406b24 | 82 | bool lookupSlaac(const Ip::Address &c); |
a98c2da5 AJ |
83 | |
84 | private: | |
85 | unsigned char eui[SZ_EUI64_BUF]; | |
86 | }; | |
87 | ||
e5519212 | 88 | } // namespace Eui |
a98c2da5 AJ |
89 | |
90 | #endif /* USE_SQUID_EUI */ | |
91 | #endif /* _SQUID_EUI_EUI64_H */ | |
f53969cc | 92 |