]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 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 | ||
ee0927b6 AJ |
9 | #ifndef _SQUID_EUI_EUI48_H |
10 | #define _SQUID_EUI_EUI48_H | |
11 | ||
ee0927b6 AJ |
12 | #if USE_SQUID_EUI |
13 | ||
14 | /* EUI-48 is 6 bytes. */ | |
15 | #define SZ_EUI48_BUF 6 | |
16 | ||
63bd4bf7 A |
17 | namespace Ip |
18 | { | |
19 | class Address; | |
b7ac5457 | 20 | }; |
ee0927b6 | 21 | |
ee0927b6 | 22 | #include <cstring> |
f1e14020 | 23 | |
05320519 A |
24 | namespace Eui |
25 | { | |
a98c2da5 | 26 | |
71ab4315 A |
27 | class Eui48 |
28 | { | |
ee0927b6 AJ |
29 | |
30 | public: | |
68e47c3e AJ |
31 | Eui48() { clear(); } |
32 | Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); } | |
41b91720 FC |
33 | bool operator== (const Eui48 &t) const { return memcmp(eui, t.eui, SZ_EUI48_BUF) == 0; } |
34 | bool operator< (const Eui48 &t) const { return memcmp(eui, t.eui, SZ_EUI48_BUF) < 0; } | |
68e47c3e | 35 | ~Eui48() {} |
ee0927b6 AJ |
36 | |
37 | const unsigned char *get(void); | |
38 | ||
39 | bool set(const char *src, const int len) { | |
40 | if (len > SZ_EUI48_BUF) return false; | |
41 | if (len < SZ_EUI48_BUF) clear(); | |
42 | memcpy(eui, src, len); | |
43 | return true; | |
68e47c3e | 44 | } |
ee0927b6 | 45 | |
68e47c3e | 46 | void clear() { memset(eui, 0, SZ_EUI48_BUF); } |
ee0927b6 AJ |
47 | |
48 | /** | |
49 | * Decode an ascii representation of an EUI-48 ethernet address. | |
50 | * | |
51 | * \param asc ASCII representation of an ethernet (MAC) address | |
52 | * \param eth Binary representation of the ethernet address | |
53 | * \retval false Conversion to binary failed. Invalid address | |
54 | * \retval true Conversion completed successfully | |
55 | */ | |
56 | bool decode(const char *asc); | |
57 | ||
58 | /** | |
59 | * Encode an ascii representation (asc) of an EUI-48 ethernet address. | |
60 | * | |
61 | * \param buf Buffer to receive ASCII representation of an ethernet (MAC) address | |
62 | * \param len Length of the buffer space available. Must be >= SZ_EUI48_BUF bytes or the encode will fail. | |
63 | * \param eui Binary representation of the ethernet address | |
64 | * \retval false Conversion to ASCII failed. | |
65 | * \retval true Conversion completed successfully. | |
66 | */ | |
4c79ed3d | 67 | bool encode(char *buf, const int len) const; |
ee0927b6 AJ |
68 | |
69 | // lookup an EUI-48 / MAC address via ARP | |
00406b24 | 70 | bool lookup(const Ip::Address &c); |
ee0927b6 AJ |
71 | |
72 | private: | |
73 | unsigned char eui[SZ_EUI48_BUF]; | |
74 | }; | |
75 | ||
e5519212 | 76 | } // namespace Eui |
a98c2da5 | 77 | |
ee0927b6 AJ |
78 | #endif /* USE_SQUID_EUI */ |
79 | #endif /* _SQUID_EUI_EUI48_H */ | |
f53969cc | 80 |