]> git.ipfire.org Git - thirdparty/squid.git/blob - src/eui/Eui48.h
Use libcap functions instead of raw kernel interface
[thirdparty/squid.git] / src / eui / Eui48.h
1 #ifndef _SQUID_EUI_EUI48_H
2 #define _SQUID_EUI_EUI48_H
3
4 #include "config.h"
5
6 #if USE_SQUID_EUI
7
8 /* EUI-48 is 6 bytes. */
9 #define SZ_EUI48_BUF 6
10
11 class IpAddress;
12
13 #if HAVE_CSTRING
14 #include <cstring>
15 #endif
16
17 class Eui48
18 {
19
20 public:
21 Eui48() { clear(); };
22 Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); };
23 ~Eui48() {};
24
25 const unsigned char *get(void);
26
27 bool set(const char *src, const int len) {
28 if (len > SZ_EUI48_BUF) return false;
29 if (len < SZ_EUI48_BUF) clear();
30 memcpy(eui, src, len);
31 return true;
32 };
33
34 void clear() { memset(eui, 0, SZ_EUI48_BUF); };
35
36 /**
37 * Decode an ascii representation of an EUI-48 ethernet address.
38 *
39 * \param asc ASCII representation of an ethernet (MAC) address
40 * \param eth Binary representation of the ethernet address
41 * \retval false Conversion to binary failed. Invalid address
42 * \retval true Conversion completed successfully
43 */
44 bool decode(const char *asc);
45
46 /**
47 * Encode an ascii representation (asc) of an EUI-48 ethernet address.
48 *
49 * \param buf Buffer to receive ASCII representation of an ethernet (MAC) address
50 * \param len Length of the buffer space available. Must be >= SZ_EUI48_BUF bytes or the encode will fail.
51 * \param eui Binary representation of the ethernet address
52 * \retval false Conversion to ASCII failed.
53 * \retval true Conversion completed successfully.
54 */
55 bool encode(char *buf, const int len);
56
57 // lookup an EUI-48 / MAC address via ARP
58 bool lookup(IpAddress &c);
59
60 private:
61 unsigned char eui[SZ_EUI48_BUF];
62 };
63
64 #endif /* USE_SQUID_EUI */
65 #endif /* _SQUID_EUI_EUI48_H */