65#define ADDRESS_INIT(type, len, data) {type, len, data, NULL}
66#define ADDRESS_INIT_NONE ADDRESS_INIT(AT_NONE, 0, NULL)
86set_address(
address *addr,
int addr_type,
int addr_len,
const void *addr_data) {
89 ws_assert(addr_data == NULL);
92 ws_assert(addr_type != AT_NONE);
94 ws_assert(addr_data != NULL);
96 addr->type = addr_type;
98 addr->data = addr_data;
104 addr->type = AT_IPv4;
106 uint32_t val = g_htonl(ipv4->addr);
107 addr->priv = g_memdup2(&val,
sizeof(val));
108 addr->data = addr->priv;
113 set_address(addr, AT_IPv6,
sizeof(
ws_in6_addr), &ipv6->addr);
132set_address_tvb(
address *addr,
int addr_type,
int addr_len,
tvbuff_t *tvb,
int offset) {
137 ws_assert(addr_type != AT_NONE);
141 set_address(addr, addr_type, addr_len, p);
156 int addr_type,
int addr_len,
const void *addr_data) {
159 addr->type = addr_type;
162 ws_assert(addr_data == NULL);
167 ws_assert(addr_type != AT_NONE);
169 ws_assert(addr_data != NULL);
170 addr->data = addr->priv =
wmem_memdup(scope, addr_data, addr_len);
171 addr->len = addr_len;
188 int addr_type,
int addr_len,
tvbuff_t *tvb,
int offset) {
192 alloc_address_wmem(scope, addr, addr_type, addr_len, p);
205 if (addr1->type > addr2->type)
return 1;
206 if (addr1->type < addr2->type)
return -1;
207 if (addr1->len > addr2->len)
return 1;
208 if (addr1->len < addr2->len)
return -1;
209 if (addr1->len == 0) {
217 return memcmp(addr1->data, addr2->data, addr1->len);
238 if (addr1->type == addr2->type &&
239 addr1->len == addr2->len &&
241 memcmp(addr1->data, addr2->data, addr1->len) == 0))
259 if ( addr1->len == addr2->len
260 && memcmp(addr1->data, addr2->data, addr1->len) == 0
276 set_address(to, from->type, from->len, from->data);
288 alloc_address_wmem(scope, to, from->type, from->len, from->data);
298 copy_address_wmem(NULL, to, from);
309 if (addr->type != AT_NONE && addr->len > 0 && addr->priv != NULL) {
312 ws_assert(addr->data == addr->priv);
324 free_address_wmem(NULL, addr);
333static inline unsigned
334add_address_to_hash(
unsigned hash_val,
const address *addr) {
335 const uint8_t *hash_data = (
const uint8_t *)(addr)->data;
338 for (idx = 0; idx < (addr)->len; idx++) {
339 hash_val += hash_data[idx];
340 hash_val += ( hash_val << 10 );
341 hash_val ^= ( hash_val >> 6 );
353static inline uint64_t
354add_address_to_hash64(uint64_t hash_val,
const address *addr) {
355 const uint8_t *hash_data = (
const uint8_t *)(addr)->data;
358 for (idx = 0; idx < (addr)->len; idx++) {
359 hash_val += hash_data[idx];
360 hash_val += ( hash_val << 10 );
361 hash_val ^= ( hash_val >> 6 );
366WS_DLL_PUBLIC
unsigned address_to_bytes(
const address *addr, uint8_t *buf,
unsigned buf_len);
const uint8_t * tvb_get_ptr(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:1001
void * wmem_memdup(wmem_allocator_t *allocator, const void *source, const size_t size)
Definition wmem_miscutl.c:19
void wmem_free(wmem_allocator_t *allocator, void *ptr)
Definition wmem_core.c:62
Definition wmem_allocator.h:27
Definition inet_addr.h:21
Definition inet_cidr.h:22
Definition inet_cidr.h:27
Definition tvbuff-int.h:35