]>
Commit | Line | Data |
---|---|---|
ee0927b6 AJ |
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 | public: | |
20 | Eui48() { clear(); }; | |
21 | Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); }; | |
22 | ~Eui48() {}; | |
23 | ||
24 | const unsigned char *get(void); | |
25 | ||
26 | bool set(const char *src, const int len) { | |
27 | if (len > SZ_EUI48_BUF) return false; | |
28 | if (len < SZ_EUI48_BUF) clear(); | |
29 | memcpy(eui, src, len); | |
30 | return true; | |
31 | }; | |
32 | ||
55ae2269 | 33 | void clear() { memset(eui, 0, SZ_EUI48_BUF); }; |
ee0927b6 AJ |
34 | |
35 | /** | |
36 | * Decode an ascii representation of an EUI-48 ethernet address. | |
37 | * | |
38 | * \param asc ASCII representation of an ethernet (MAC) address | |
39 | * \param eth Binary representation of the ethernet address | |
40 | * \retval false Conversion to binary failed. Invalid address | |
41 | * \retval true Conversion completed successfully | |
42 | */ | |
43 | bool decode(const char *asc); | |
44 | ||
45 | /** | |
46 | * Encode an ascii representation (asc) of an EUI-48 ethernet address. | |
47 | * | |
48 | * \param buf Buffer to receive ASCII representation of an ethernet (MAC) address | |
49 | * \param len Length of the buffer space available. Must be >= SZ_EUI48_BUF bytes or the encode will fail. | |
50 | * \param eui Binary representation of the ethernet address | |
51 | * \retval false Conversion to ASCII failed. | |
52 | * \retval true Conversion completed successfully. | |
53 | */ | |
54 | bool encode(char *buf, const int len); | |
55 | ||
56 | // lookup an EUI-48 / MAC address via ARP | |
57 | bool lookup(IpAddress &c); | |
58 | ||
59 | private: | |
60 | unsigned char eui[SZ_EUI48_BUF]; | |
61 | }; | |
62 | ||
63 | #endif /* USE_SQUID_EUI */ | |
64 | #endif /* _SQUID_EUI_EUI48_H */ |