suricata
datasets-ipv4.c
Go to the documentation of this file.
1 /* Copyright (C) 2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Eric Leblond <el@stamus-networks.com>
22  */
23 
24 #include "suricata-common.h"
25 #include "conf.h"
26 #include "datasets.h"
27 #include "datasets-ipv4.h"
28 #include "util-thash.h"
29 #include "util-print.h"
30 
31 int IPv4Set(void *dst, void *src)
32 {
33  IPv4Type *src_s = src;
34  IPv4Type *dst_s = dst;
35  memcpy(dst_s->ipv4, src_s->ipv4, sizeof(dst_s->ipv4));
36  dst_s->rep = src_s->rep;
37  return 0;
38 }
39 
40 bool IPv4Compare(void *a, void *b)
41 {
42  const IPv4Type *as = a;
43  const IPv4Type *bs = b;
44 
45  return (memcmp(as->ipv4, bs->ipv4, sizeof(as->ipv4)) == 0);
46 }
47 
48 uint32_t IPv4Hash(void *s)
49 {
50  const IPv4Type *str = s;
51  uint32_t hash = 5381;
52 
53  for (int i = 0; i < (int)sizeof(str->ipv4); i++) {
54  hash = ((hash << 5) + hash) + str->ipv4[i]; /* hash * 33 + c */
55  }
56  return hash;
57 }
58 
59 // data stays in hash
60 void IPv4Free(void *s)
61 {
62 }
datasets.h
util-print.h
datasets-ipv4.h
IPv4Set
int IPv4Set(void *dst, void *src)
Definition: datasets-ipv4.c:31
conf.h
IPv4Free
void IPv4Free(void *s)
Definition: datasets-ipv4.c:60
IPv4Hash
uint32_t IPv4Hash(void *s)
Definition: datasets-ipv4.c:48
suricata-common.h
IPv4Type
Definition: datasets-ipv4.h:29
IPv4Compare
bool IPv4Compare(void *a, void *b)
Definition: datasets-ipv4.c:40
str
#define str(s)
Definition: suricata-common.h:280
src
uint16_t src
Definition: app-layer-dnp3.h:5
IPv4Type::ipv4
uint8_t ipv4[4]
Definition: datasets-ipv4.h:30
IPv4Type::rep
DataRepType rep
Definition: datasets-ipv4.h:31
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
util-thash.h