67#define ADDRESS_INIT(type, len, data) {type, len, data, NULL}
68#define ADDRESS_INIT_NONE ADDRESS_INIT(AT_NONE, 0, NULL)
92set_address(
address *addr,
int addr_type,
int addr_len,
const void *addr_data) {
102 addr->type = addr_type;
103 addr->len = addr_len;
104 addr->data = addr_data;
118 addr->type = AT_IPv4;
120 uint32_t val = g_htonl(ipv4->addr);
121 addr->priv = g_memdup2(&val,
sizeof(val));
122 addr->data = addr->priv;
135 set_address(addr, AT_IPv6,
sizeof(
ws_in6_addr), &ipv6->addr);
155set_address_tvb(
address *addr,
int addr_type,
unsigned addr_len,
tvbuff_t *tvb,
unsigned offset) {
164 set_address(addr, addr_type, addr_len, p);
180 int addr_type,
int addr_len,
const void *addr_data) {
183 addr->type = addr_type;
194 addr->data = addr->priv =
wmem_memdup(scope, addr_data, addr_len);
195 addr->len = addr_len;
213 int addr_type,
int addr_len,
tvbuff_t *tvb,
int offset) {
217 alloc_address_wmem(scope, addr, addr_type, addr_len, p);
231 if (addr1->type > addr2->type)
return 1;
232 if (addr1->type < addr2->type)
return -1;
233 if (addr1->len > addr2->len)
return 1;
234 if (addr1->len < addr2->len)
return -1;
235 if (addr1->len == 0) {
243 return memcmp(addr1->data, addr2->data, addr1->len);
265 if (addr1->type == addr2->type &&
266 addr1->len == addr2->len &&
268 memcmp(addr1->data, addr2->data, addr1->len) == 0))
287 if ( addr1->len == addr2->len
288 && memcmp(addr1->data, addr2->data, addr1->len) == 0
305 set_address(to, from->type, from->len, from->data);
318 alloc_address_wmem(scope, to, from->type, from->len, from->data);
329 copy_address_wmem(NULL, to, from);
341 if (addr->type != AT_NONE && addr->len > 0 && addr->priv != NULL) {
357 free_address_wmem(NULL, addr);
367static inline unsigned
368add_address_to_hash(
unsigned hash_val,
const address *addr) {
369 const uint8_t *hash_data = (
const uint8_t *)(addr)->data;
372 for (idx = 0; idx < (addr)->len; idx++) {
373 hash_val += hash_data[idx];
374 hash_val += ( hash_val << 10 );
375 hash_val ^= ( hash_val >> 6 );
388static inline uint64_t
389add_address_to_hash64(uint64_t hash_val,
const address *addr) {
390 const uint8_t *hash_data = (
const uint8_t *)(addr)->data;
393 for (idx = 0; idx < (addr)->len; idx++) {
394 hash_val += hash_data[idx];
395 hash_val += ( hash_val << 10 );
396 hash_val ^= ( hash_val >> 6 );
WS_DLL_PUBLIC unsigned address_to_bytes(const address *addr, uint8_t *buf, unsigned buf_len)
Converts an address to a byte array.
Definition address_types.c:989
const uint8_t * tvb_get_ptr(tvbuff_t *tvb, const unsigned offset, const unsigned length)
Returns a raw pointer to tvbuff data. Use with extreme caution.
Definition tvbuff.c:1129
void * wmem_memdup(wmem_allocator_t *allocator, const void *source, const size_t size)
Copies a block of memory.
Definition wmem_miscutl.c:19
void wmem_free(wmem_allocator_t *allocator, void *ptr)
Returns the allocated memory to the allocator.
Definition wmem_core.c:62
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
Represents a 128-bit IPv6 address.
Definition inet_addr.h:27
Definition inet_cidr.h:22
Definition inet_cidr.h:27
Definition tvbuff-int.h:36
#define ws_assert(expr)
Unconditionally assert an expression when assertions are enabled.
Definition ws_assert.h:102