Eui64.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_EUI_EUI64_H
10 #define SQUID_SRC_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 
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); }
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;
50  }
51 
52  void clear() { memset(eui, 0, SZ_EUI64_BUF); }
53 
62  bool decode(const char *asc);
63 
73  bool encode(char *buf, const int len) const;
74 
75  // lookup an EUI-64 address via IPv6 SLAAC or NDP
76  bool lookup(const Ip::Address &c);
77 
78  // lookup an EUI-64 address via IPv6 NDP
79  bool lookupNdp(const Ip::Address &c);
80 
81  // lookup an EUI-64 address via decoding the IPv6 address SLAAC data
82  bool lookupSlaac(const Ip::Address &c);
83 
84 private:
85  unsigned char eui[SZ_EUI64_BUF];
86 };
87 
88 } // namespace Eui
89 
90 #endif /* USE_SQUID_EUI */
91 #endif /* SQUID_SRC_EUI_EUI64_H */
92 
bool operator<(const Eui64 &t) const
Definition: Eui64.h:41
bool encode(char *buf, const int len) const
Definition: Eui64.cc:34
bool lookupNdp(const Ip::Address &c)
Definition: Eui64.cc:78
bool decode(const char *asc)
Definition: Eui64.cc:22
unsigned char eui[SZ_EUI64_BUF]
Definition: Eui64.h:85
bool lookupSlaac(const Ip::Address &c)
Definition: Eui64.cc:58
Definition: Xaction.cc:137
bool operator==(const Eui64 &t) const
Definition: Eui64.h:40
#define SZ_EUI64_BUF
Definition: Eui64.h:31
bool set(const char *src, const int len)
Definition: Eui64.h:45
Definition: Config.h:12
const unsigned char * get(void)
Eui64()
Definition: Eui64.h:38
bool lookup(const Ip::Address &c)
Definition: Eui64.cc:47
void clear()
Definition: Eui64.h:52

 

Introduction

Documentation

Support

Miscellaneous