1 | /* $Id: ClientId.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DHCP server - client identifier
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_Dhcpd_ClientId_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Dhcpd_ClientId_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include "DhcpdInternal.h"
|
---|
25 | #include <iprt/net.h>
|
---|
26 | #include "DhcpOptions.h"
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * A client is identified by either the Client ID option it sends or its chaddr,
|
---|
30 | * i.e. MAC address.
|
---|
31 | */
|
---|
32 | class ClientId
|
---|
33 | {
|
---|
34 | /** The mac address of the client. */
|
---|
35 | RTMAC m_mac;
|
---|
36 | /** The client ID. */
|
---|
37 | OptClientId m_id;
|
---|
38 |
|
---|
39 | public:
|
---|
40 | ClientId()
|
---|
41 | : m_mac(), m_id()
|
---|
42 | {}
|
---|
43 | /** @throws std::bad_alloc */
|
---|
44 | ClientId(const RTMAC &a_mac, const OptClientId &a_id)
|
---|
45 | : m_mac(a_mac), m_id(a_id)
|
---|
46 | {}
|
---|
47 | /** @throws std::bad_alloc */
|
---|
48 | ClientId(const ClientId &a_rThat)
|
---|
49 | : m_mac(a_rThat.m_mac), m_id(a_rThat.m_id)
|
---|
50 | {}
|
---|
51 | /** @throws std::bad_alloc */
|
---|
52 | ClientId &operator=(const ClientId &a_rThat)
|
---|
53 | {
|
---|
54 | m_mac = a_rThat.m_mac;
|
---|
55 | m_id = a_rThat.m_id;
|
---|
56 | return *this;
|
---|
57 | }
|
---|
58 |
|
---|
59 | const RTMAC &mac() const RT_NOEXCEPT { return m_mac; }
|
---|
60 | const OptClientId &id() const RT_NOEXCEPT { return m_id; }
|
---|
61 |
|
---|
62 | /** @name String formatting of %R[id].
|
---|
63 | * @{ */
|
---|
64 | static void registerFormat() RT_NOEXCEPT;
|
---|
65 | private:
|
---|
66 | static DECLCALLBACK(size_t) rtStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, const char *pszType,
|
---|
67 | void const *pvValue, int cchWidth, int cchPrecision, unsigned fFlags, void *pvUser);
|
---|
68 | static bool g_fFormatRegistered;
|
---|
69 | /** @} */
|
---|
70 |
|
---|
71 | friend bool operator==(const ClientId &l, const ClientId &r) RT_NOEXCEPT;
|
---|
72 | friend bool operator<(const ClientId &l, const ClientId &r) RT_NOEXCEPT;
|
---|
73 | };
|
---|
74 |
|
---|
75 | bool operator==(const ClientId &l, const ClientId &r) RT_NOEXCEPT;
|
---|
76 | bool operator<(const ClientId &l, const ClientId &r) RT_NOEXCEPT;
|
---|
77 |
|
---|
78 | inline bool operator!=(const ClientId &l, const ClientId &r) RT_NOEXCEPT
|
---|
79 | {
|
---|
80 | return !(l == r);
|
---|
81 | }
|
---|
82 |
|
---|
83 | #endif /* !VBOX_INCLUDED_SRC_Dhcpd_ClientId_h */
|
---|