-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixedIPList.cpp
66 lines (60 loc) · 1.23 KB
/
FixedIPList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "FixedIPList.h"
#include "Logging.h"
IPAddress EmptyAddress = IPAddress ( 0UL );
FixedIPList::FixedIPList ( uint8_t MaxEntries ) : m_maxEntries ( MaxEntries )
{
m_pIPList = new IPAddress [ m_maxEntries ];
for ( uint8_t i = 0; i < m_maxEntries; i++ )
{
m_pIPList [ i ] = EmptyAddress;
}
}
bool FixedIPList::Add ( IPAddress addition )
{
bool bResult = false;
if ( !IsPresent ( addition ) )
{
if ( m_nextEntry >= m_maxEntries )
{
// list full, so discard oldest
for ( uint8_t i = 0; i < m_maxEntries - 1; i++ )
{
m_pIPList [ i ] = m_pIPList [ i + 1 ];
}
m_pIPList [ m_maxEntries - 1 ] = EmptyAddress;
m_nextEntry = m_maxEntries - 1;
}
// Error ( "Adding macast entry" );
m_pIPList [ m_nextEntry++ ] = addition;
}
return bResult;
}
uint8_t FixedIPList::Count ()
{
return m_nextEntry;
}
uint8_t FixedIPList::GetIterator ()
{
return 0;
}
IPAddress FixedIPList::GetNext ( uint8_t &iterator )
{
if ( iterator < m_nextEntry )
{
return m_pIPList [ iterator++ ];
}
return EmptyAddress;
}
bool FixedIPList::IsPresent ( IPAddress addr )
{
bool bResult = false;
for ( uint8_t i = 0; i < m_maxEntries; i++ )
{
if ( m_pIPList [ i ] == addr )
{
bResult = true;
break;
}
}
return bResult;
}