]> git.ipfire.org Git - thirdparty/squid.git/blob - src/eui/Eui64.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / eui / Eui64.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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
9 #ifndef _SQUID_EUI_EUI64_H
10 #define _SQUID_EUI_EUI64_H
11
12 #if USE_SQUID_EUI
13
14 namespace Ip
15 {
16 class Address;
17 }
18
19 #include <cstring>
20 #if HAVE_SYS_EUI64_H
21 #include <sys/eui64.h>
22 #endif
23
24 namespace Eui
25 {
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
34 class Eui64
35 {
36
37 public:
38 Eui64() { clear(); }
39 Eui64(const Eui64 &t) { memcpy(this, &t, sizeof(Eui64)); }
40 ~Eui64() {}
41
42 const unsigned char *get(void);
43
44 bool set(const char *src, const int len) {
45 if (len > SZ_EUI64_BUF) return false;
46 if (len < SZ_EUI64_BUF) clear();
47 memcpy(eui, src, len);
48 return true;
49 }
50
51 void clear() { memset(eui, 0, SZ_EUI64_BUF); }
52
53 /**
54 * Decode an ascii representation of an EUI-64 address.
55 *
56 * \param asc ASCII representation of an EUI-64 address
57 * \param eth Binary representation of the EUI_64 address
58 * \retval false Conversion to binary failed. Invalid address
59 * \retval true Conversion completed successfully
60 */
61 bool decode(const char *asc);
62
63 /**
64 * Encode an ascii representation (asc) of an EUI-64 address.
65 *
66 * \param buf Buffer to receive ASCII representation of an EUI-64 address
67 * \param len Length of the buffer space available. Must be >= SZ_EUI64_BUF bytes or the encode will fail.
68 * \param eui Binary representation of the EUI-64 address
69 * \retval false Conversion to ASCII failed.
70 * \retval true Conversion completed successfully.
71 */
72 bool encode(char *buf, const int len);
73
74 // lookup an EUI-64 address via IPv6 SLAAC or NDP
75 bool lookup(const Ip::Address &c);
76
77 // lookup an EUI-64 address via IPv6 NDP
78 bool lookupNdp(const Ip::Address &c);
79
80 // lookup an EUI-64 address via decoding the IPv6 address SLAAC data
81 bool lookupSlaac(const Ip::Address &c);
82
83 private:
84 unsigned char eui[SZ_EUI64_BUF];
85 };
86
87 } // namespace Eui
88
89 #endif /* USE_SQUID_EUI */
90 #endif /* _SQUID_EUI_EUI64_H */
91