]> git.ipfire.org Git - thirdparty/squid.git/blame - src/eui/Eui48.h
Implement subscription for AsyncCallT / JobCallback
[thirdparty/squid.git] / src / eui / Eui48.h
CommitLineData
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
63bd4bf7
A
11namespace Ip
12{
13class Address;
b7ac5457 14};
ee0927b6
AJ
15
16#if HAVE_CSTRING
17#include <cstring>
18#endif
19
f1e14020
FC
20/* memcpy and friends */
21#if HAVE_STRING_H
22#include <string.h>
23#endif
24
05320519
A
25namespace Eui
26{
a98c2da5 27
71ab4315
A
28class Eui48
29{
ee0927b6
AJ
30
31public:
32 Eui48() { clear(); };
33 Eui48(const Eui48 &t) { memcpy(this, &t, sizeof(Eui48)); };
34 ~Eui48() {};
35
36 const unsigned char *get(void);
37
38 bool set(const char *src, const int len) {
39 if (len > SZ_EUI48_BUF) return false;
40 if (len < SZ_EUI48_BUF) clear();
41 memcpy(eui, src, len);
42 return true;
43 };
44
55ae2269 45 void clear() { memset(eui, 0, SZ_EUI48_BUF); };
ee0927b6
AJ
46
47 /**
48 * Decode an ascii representation of an EUI-48 ethernet address.
49 *
50 * \param asc ASCII representation of an ethernet (MAC) address
51 * \param eth Binary representation of the ethernet address
52 * \retval false Conversion to binary failed. Invalid address
53 * \retval true Conversion completed successfully
54 */
55 bool decode(const char *asc);
56
57 /**
58 * Encode an ascii representation (asc) of an EUI-48 ethernet address.
59 *
60 * \param buf Buffer to receive ASCII representation of an ethernet (MAC) address
61 * \param len Length of the buffer space available. Must be >= SZ_EUI48_BUF bytes or the encode will fail.
62 * \param eui Binary representation of the ethernet address
63 * \retval false Conversion to ASCII failed.
64 * \retval true Conversion completed successfully.
65 */
66 bool encode(char *buf, const int len);
67
68 // lookup an EUI-48 / MAC address via ARP
b7ac5457 69 bool lookup(Ip::Address &c);
ee0927b6
AJ
70
71private:
72 unsigned char eui[SZ_EUI48_BUF];
73};
74
a98c2da5
AJ
75}; // namespace Eui
76
ee0927b6
AJ
77#endif /* USE_SQUID_EUI */
78#endif /* _SQUID_EUI_EUI48_H */