mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Increase UIDs to 96 bits w/ C/F prefix - BIT-1016
- The bit-length is adjustable via redef'ing bits_per_uid. - Prefix 'C' is used for connection UIDS (including IP tunnels) and 'F' for files.
This commit is contained in:
parent
df84083227
commit
22bf3e1196
103 changed files with 20911 additions and 20772 deletions
43
src/UID.cc
Normal file
43
src/UID.cc
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include "UID.h"
|
||||
|
||||
using namespace Bro;
|
||||
using namespace std;
|
||||
|
||||
void UID::Set(bro_uint_t bits, const std::vector<uint64>& v)
|
||||
{
|
||||
uid.clear();
|
||||
|
||||
div_t res = div(bits, 64);
|
||||
int size = res.rem ? res.quot + 1 : res.quot;
|
||||
|
||||
for ( int i = 0; i < size; ++i )
|
||||
uid.push_back(i < v.size() ? v[i] : calculate_unique_id());
|
||||
|
||||
if ( res.rem )
|
||||
uid[0] >>= 64 - res.rem;
|
||||
}
|
||||
|
||||
string UID::Base62(const std::string& prefix) const
|
||||
{
|
||||
char tmp[64]; // technically, this should dynamically scale based on size
|
||||
string rval(prefix);
|
||||
|
||||
for ( size_t i = 0; i < uid.size(); ++i )
|
||||
rval.append(uitoa_n(uid[i], tmp, sizeof(tmp), 62));
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool Bro::operator==(const UID& u1, const UID& u2)
|
||||
{
|
||||
if ( u1.uid.size() != u2.uid.size() )
|
||||
return false;
|
||||
|
||||
for ( size_t i = 0; i < u1.uid.size(); ++i )
|
||||
if ( u1.uid[i] != u2.uid[i] )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue