Go to the documentation of this file.
356 static uint32_t ProtoNameHashFunc(
HashTable *ht,
void *data, uint16_t datalen)
366 static char ProtoNameHashCompareFunc(
void *data1, uint16_t datalen1,
void *data2, uint16_t datalen2)
371 if (p1 == NULL || p2 == NULL)
374 if (p1->
name == NULL || p2->
name == NULL)
377 return strcmp(p1->
name, p2->
name) == 0;
380 static void ProtoNameAddEntry(
const char *proto_name,
const uint8_t proto_number)
384 FatalError(
"Unable to allocate protocol hash entry");
388 if (!proto_ent->
name)
389 FatalError(
"Unable to allocate memory for protocol name entries");
391 proto_ent->
number = proto_number;
393 SCLogDebug(
"new protocol entry: name: \"%s\"; protocol number: %d", proto_ent->
name,
396 FatalError(
"Unable to add entry to proto hash table for "
397 "name: \"%s\"; number: %d",
402 static void ProtoNameHashFreeFunc(
void *data)
416 HashTableInit(256, ProtoNameHashFunc, ProtoNameHashCompareFunc, ProtoNameHashFreeFunc);
417 if (proto_ht == NULL) {
418 FatalError(
"Unable to initialize protocol name/number table");
436 if (proto_ht != NULL) {
464 if (!protoname || !proto_number) {
469 proto.name = protoname;
473 *proto_number = proto_ent->
number;
480 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)
Free a HashTable and all its contents.
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)