Go to the documentation of this file.
357 static uint32_t ProtoNameHashFunc(
HashTable *ht,
void *data, uint16_t datalen)
367 static char ProtoNameHashCompareFunc(
void *data1, uint16_t datalen1,
void *data2, uint16_t datalen2)
372 if (p1 == NULL || p2 == NULL)
375 if (p1->
name == NULL || p2->
name == NULL)
378 int len1 = strlen(p1->
name);
379 int len2 = strlen(p2->
name);
381 return len1 == len2 && memcmp(p1->
name, p2->
name, len1) == 0;
384 static void ProtoNameAddEntry(
const char *proto_name,
const uint8_t proto_number)
388 FatalError(
"Unable to allocate protocol hash entry");
392 if (!proto_ent->
name)
393 FatalError(
"Unable to allocate memory for protocol name entries");
395 proto_ent->
number = proto_number;
397 SCLogDebug(
"new protocol entry: name: \"%s\"; protocol number: %d", proto_ent->
name,
400 FatalError(
"Unable to add entry to proto hash table for "
401 "name: \"%s\"; number: %d",
406 static void ProtoNameHashFreeFunc(
void *data)
420 HashTableInit(256, ProtoNameHashFunc, ProtoNameHashCompareFunc, ProtoNameHashFreeFunc);
421 if (proto_ht == NULL) {
422 FatalError(
"Unable to initialize protocol name/number table");
440 if (proto_ht != NULL) {
468 if (!protoname || !proto_number) {
473 proto.name = protoname;
477 *proto_number = proto_ent->
number;
484 static int ProtoNameTest01(
void)
void SCProtoNameRegisterTests(void)
struct ProtoNameHashEntry_ ProtoNameHashEntry
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void SCProtoNameInit(void)
bool SCProtoNameValid(uint16_t proto)
Function to check if the received protocol number is valid and do we have corresponding name entry fo...
const char * known_proto[256]
void HashTableFree(HashTable *ht)
const char * proto_aliases[256]
#define PASS
Pass the test.
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
void SCProtoNameRelease(void)
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
bool SCGetProtoByName(const char *protoname, uint8_t *proto_number)
Function to return the protocol number for a named protocol. Note that protocol name aliases are hono...
uint32_t StringHashDjb2(const uint8_t *data, uint32_t datalen)