18 #include "wmem/wmem.h" 56 #define ADDRESS_INIT(type, len, data) {type, len, data, NULL} 57 #define ADDRESS_INIT_NONE ADDRESS_INIT(AT_NONE, 0, NULL) 77 set_address(
address *addr,
int addr_type,
int addr_len,
const void *addr_data) {
80 g_assert(addr_data == NULL);
83 g_assert(addr_type != AT_NONE);
85 g_assert(addr_data != NULL);
87 addr->type = addr_type;
89 addr->data = addr_data;
109 set_address_tvb(
address *addr,
int addr_type,
int addr_len,
tvbuff_t *tvb,
int offset) {
114 g_assert(addr_type != AT_NONE);
118 set_address(addr, addr_type, addr_len, p);
133 int addr_type,
int addr_len,
const void *addr_data) {
136 addr->type = addr_type;
139 g_assert(addr_data == NULL);
144 g_assert(addr_type != AT_NONE);
146 g_assert(addr_data != NULL);
147 addr->data = addr->priv =
wmem_memdup(scope, addr_data, addr_len);
148 addr->len = addr_len;
165 int addr_type,
int addr_len,
tvbuff_t *tvb,
int offset) {
169 alloc_address_wmem(scope, addr, addr_type, addr_len, p);
182 if (addr1->type > addr2->type)
return 1;
183 if (addr1->type < addr2->type)
return -1;
184 if (addr1->len > addr2->len)
return 1;
185 if (addr1->len < addr2->len)
return -1;
186 if (addr1->len == 0) {
194 return memcmp(addr1->data, addr2->data, addr1->len);
208 static inline gboolean
215 if (addr1->type == addr2->type &&
216 addr1->len == addr2->len &&
218 memcmp(addr1->data, addr2->data, addr1->len) == 0))
234 static inline gboolean
235 addresses_data_equal(
const address *addr1,
const address *addr2) {
236 if ( addr1->len == addr2->len
237 && memcmp(addr1->data, addr2->data, addr1->len) == 0
253 set_address(to, from->type, from->len, from->data);
265 alloc_address_wmem(scope, to, from->type, from->len, from->data);
275 copy_address_wmem(NULL, to, from);
286 if (addr->type != AT_NONE && addr->len > 0 && addr->priv != NULL) {
289 g_assert(addr->data == addr->priv);
301 free_address_wmem(NULL, addr);
311 add_address_to_hash(guint hash_val,
const address *addr) {
312 const guint8 *hash_data = (
const guint8 *)(addr)->data;
315 for (idx = 0; idx < (addr)->len; idx++) {
316 hash_val += hash_data[idx];
317 hash_val += ( hash_val << 10 );
318 hash_val ^= ( hash_val >> 6 );
330 static inline guint64
331 add_address_to_hash64(guint64 hash_val,
const address *addr) {
332 const guint8 *hash_data = (
const guint8 *)(addr)->data;
335 for (idx = 0; idx < (addr)->len; idx++) {
336 hash_val += hash_data[idx];
337 hash_val += ( hash_val << 10 );
338 hash_val ^= ( hash_val >> 6 );
343 WS_DLL_PUBLIC guint address_to_bytes(
const address *addr, guint8 *buf, guint buf_len);
Definition: tvbuff-int.h:35
void * wmem_memdup(wmem_allocator_t *allocator, const void *source, const size_t size)
Definition: wmem_miscutl.c:19
Definition: wmem_allocator.h:26
void wmem_free(wmem_allocator_t *allocator, void *ptr)
Definition: wmem_core.c:64
const guint8 * tvb_get_ptr(tvbuff_t *tvb, const gint offset, const gint length)
Definition: tvbuff.c:897