epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / ftypes / ftype-bytes.c
blobf2c11dbb8643ef4a0596dbbb4f3e8344f9f95ccb
1 /*
2 * Wireshark - Network traffic analyzer
3 * By Gerald Combs <gerald@wireshark.org>
4 * Copyright 2001 Gerald Combs
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
9 #include "config.h"
11 #include <ftypes-int.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <stdlib.h>
15 #include <epan/addr_resolv.h>
16 #include <epan/strutil.h>
17 #include <epan/oids.h>
18 #include <epan/osi-utils.h>
19 #include <epan/to_str.h>
20 #include <wsutil/array.h>
22 static void
23 bytes_fvalue_new(fvalue_t *fv)
25 fv->value.bytes = NULL;
28 static void
29 bytes_fvalue_copy(fvalue_t *dst, const fvalue_t *src)
31 dst->value.bytes = g_bytes_ref(src->value.bytes);
34 static void
35 bytes_fvalue_free(fvalue_t *fv)
37 if (fv->value.bytes) {
38 g_bytes_unref(fv->value.bytes);
39 fv->value.bytes = NULL;
44 static void
45 bytes_fvalue_set(fvalue_t *fv, GBytes *value)
47 /* Free up the old value, if we have one */
48 bytes_fvalue_free(fv);
50 fv->value.bytes = g_bytes_ref(value);
53 static GBytes *
54 bytes_fvalue_get(fvalue_t *fv)
56 return g_bytes_ref(fv->value.bytes);
59 static char *
60 oid_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
62 return oid_encoded2string(scope, g_bytes_get_data(fv->value.bytes, NULL), (unsigned)g_bytes_get_size(fv->value.bytes));
65 static char *
66 rel_oid_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
68 return rel_oid_encoded2string(scope, g_bytes_get_data(fv->value.bytes, NULL), (unsigned)g_bytes_get_size(fv->value.bytes));
71 static char *
72 system_id_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
74 return print_system_id(scope, g_bytes_get_data(fv->value.bytes, NULL), (unsigned)g_bytes_get_size(fv->value.bytes));
77 char *
78 bytes_to_dfilter_repr(wmem_allocator_t *scope,
79 const uint8_t *src, size_t src_size)
81 char *buf;
82 size_t max_char_size;
83 char *buf_ptr;
85 /* Include space for extra punct and '\0'. */
86 max_char_size = src_size * 3 + 1;
88 buf = wmem_alloc(scope, max_char_size);
89 buf_ptr = bytes_to_hexstr_punct(buf, src, src_size, ':');
90 if (src_size == 1)
91 *buf_ptr++ = ':';
92 *buf_ptr = '\0';
93 return buf;
96 static char *
97 bytes_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display)
99 char separator;
100 const uint8_t *bytes;
101 size_t bytes_size;
103 bytes = g_bytes_get_data(fv->value.bytes, &bytes_size);
105 if (rtype == FTREPR_DFILTER) {
106 if (bytes_size == 0) {
107 /* An empty byte array in a display filter is represented as "" */
108 return wmem_strdup(scope, "\"\"");
110 return bytes_to_dfilter_repr(scope, bytes, bytes_size);
113 switch(FIELD_DISPLAY(field_display))
115 case SEP_DOT:
116 separator = '.';
117 break;
118 case SEP_DASH:
119 separator = '-';
120 break;
121 case SEP_SPACE:
122 case SEP_COLON:
123 case BASE_NONE:
124 default:
125 separator = ':';
126 break;
129 if (bytes_size) {
130 return bytes_to_str_punct_maxlen(scope, bytes, bytes_size, separator, 0);
133 return wmem_strdup(scope, "");
136 static bool
137 bytes_from_string(fvalue_t *fv, const char *s, size_t len, char **err_msg _U_)
139 GByteArray *bytes;
141 bytes = g_byte_array_new();
143 if (len == 0)
144 len = strlen(s);
146 g_byte_array_append(bytes, (const uint8_t *)s, (unsigned)len);
148 /* Free up the old value, if we have one */
149 bytes_fvalue_free(fv);
150 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
152 return true;
155 GByteArray *
156 byte_array_from_literal(const char *s, char **err_msg)
158 GByteArray *bytes;
159 bool res;
161 /* Skip leading colon if any. */
162 if (*s == ':')
163 s++;
166 * Special case where the byte string is specified using a one byte
167 * hex literal. We can't allow this for byte strings that are longer
168 * than one byte, because then we'd have to know which endianness the
169 * byte string should be in.
171 if (strlen(s) == 4 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
172 s = s + 2;
174 bytes = g_byte_array_new();
176 /* Hack: If we have a binary number 0bXXXXXXXX use that as a byte array
177 * of length one. This is ambiguous because it can also be
178 * parsed (without separators) as a byte array of length 5:
179 * 0bXXXXXXXX = 0b:XX:XX:XX:XX = { 0x0b, 0xXX, 0xXX, 0xXX, 0xXX } */
180 if (strlen(s) == 10 && s[0] == '0' && (s[1] == 'b' || s[1] == 'B') &&
181 (s[2] == '0' || s[2] == '1')) {
182 errno = 0;
183 char *endptr;
184 long number = strtol(s + 2, &endptr, 2);
185 if (errno == 0 && *endptr == '\0' && number >= 0x0 && number <= 0xff) {
186 uint8_t byte = (uint8_t)number;
187 g_byte_array_append(bytes, &byte, 1);
188 return bytes;
192 res = hex_str_to_bytes(s, bytes, false);
194 if (!res) {
195 if (err_msg != NULL)
196 *err_msg = ws_strdup_printf("\"%s\" is not a valid byte string.", s);
197 g_byte_array_free(bytes, true);
198 return NULL;
201 return bytes;
204 static bool
205 bytes_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
207 GByteArray *bytes;
209 bytes = byte_array_from_literal(s, err_msg);
210 if (bytes == NULL)
211 return false;
213 /* Free up the old value, if we have one */
214 bytes_fvalue_free(fv);
216 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
218 return true;
221 GByteArray *
222 byte_array_from_charconst(unsigned long num, char **err_msg)
224 if (num > UINT8_MAX) {
225 if (err_msg) {
226 *err_msg = ws_strdup_printf("%lu is too large for a byte value", num);
228 return NULL;
231 GByteArray *bytes = g_byte_array_new();
232 uint8_t one_byte = (uint8_t)num;
233 g_byte_array_append(bytes, &one_byte, 1);
234 return bytes;
237 static bool
238 bytes_from_charconst(fvalue_t *fv, unsigned long num, char **err_msg)
240 GByteArray *bytes;
242 bytes = byte_array_from_charconst(num, err_msg);
243 if (bytes == NULL)
244 return false;
246 /* Free up the old value, if we have one */
247 bytes_fvalue_free(fv);
249 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
251 return true;
254 static bool
255 bytes_from_uinteger64(fvalue_t *fv, const char *s _U_, uint64_t num, char **err_msg)
257 if (num > UINT8_MAX) {
258 if (err_msg) {
259 *err_msg = ws_strdup_printf("%s is too large for a byte value", s);
261 return false;
264 return bytes_from_charconst(fv, (unsigned long)num, err_msg);
267 static bool
268 bytes_from_sinteger64(fvalue_t *fv, const char *s, int64_t num, char **err_msg)
270 if (num < 0) {
271 if (err_msg) {
272 *err_msg = ws_strdup_printf("Byte values cannot be negative");
274 return false;
276 return bytes_from_uinteger64(fv, s, (uint64_t)num, err_msg);
279 static bool
280 vines_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value, char **err_msg)
283 * Don't request an error message if bytes_from_literal fails;
284 * if it does, we'll report an error specific to this address
285 * type.
287 if (bytes_from_literal(fv, s, true, NULL)) {
288 if (g_bytes_get_size(fv->value.bytes) > FT_VINES_ADDR_LEN) {
289 if (err_msg != NULL) {
290 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid Vines address.",
293 return false;
295 else if (g_bytes_get_size(fv->value.bytes) < FT_VINES_ADDR_LEN && !allow_partial_value) {
296 if (err_msg != NULL) {
297 *err_msg = ws_strdup_printf("\"%s\" contains too few bytes to be a valid Vines address.",
300 return false;
303 return true;
306 /* XXX - need better validation of Vines address */
308 if (err_msg != NULL)
309 *err_msg = ws_strdup_printf("\"%s\" is not a valid Vines address.", s);
310 return false;
313 static bool
314 ether_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value, char **err_msg)
317 * Don't request an error message if bytes_from_literal fails;
318 * if it does, we'll report an error specific to this address
319 * type.
321 if (bytes_from_literal(fv, s, true, NULL)) {
322 if (g_bytes_get_size(fv->value.bytes) > FT_ETHER_LEN) {
323 if (err_msg != NULL) {
324 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid Ethernet address.",
327 return false;
329 else if (g_bytes_get_size(fv->value.bytes) < FT_ETHER_LEN && !allow_partial_value) {
330 if (err_msg != NULL) {
331 *err_msg = ws_strdup_printf("\"%s\" contains too few bytes to be a valid Ethernet address.",
334 return false;
337 return true;
340 /* XXX - Try resolving as an Ethernet host name and parse that? */
342 if (err_msg != NULL)
343 *err_msg = ws_strdup_printf("\"%s\" is not a valid Ethernet address.", s);
344 return false;
347 static bool
348 oid_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
350 GByteArray *bytes;
351 bool res;
354 #if 0
356 * Don't log a message if this fails; we'll try looking it
357 * up as an OID if it does, and if that fails,
358 * we'll log a message.
360 /* do not try it as '.' is handled as valid separator for hexbytes :( */
361 if (bytes_from_literal(fv, s, true, NULL)) {
362 return true;
364 #endif
366 bytes = g_byte_array_new();
367 res = oid_str_to_bytes(s, bytes);
368 if (!res) {
369 if (err_msg != NULL)
370 *err_msg = ws_strdup_printf("\"%s\" is not a valid OBJECT IDENTIFIER.", s);
371 g_byte_array_free(bytes, true);
372 return false;
375 /* Free up the old value, if we have one */
376 bytes_fvalue_free(fv);
377 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
379 return true;
382 static bool
383 rel_oid_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
385 GByteArray *bytes;
386 bool res;
388 bytes = g_byte_array_new();
389 res = rel_oid_str_to_bytes(s, bytes, false);
390 if (!res) {
391 if (err_msg != NULL)
392 *err_msg = ws_strdup_printf("\"%s\" is not a valid RELATIVE-OID.", s);
393 g_byte_array_free(bytes, true);
394 return false;
397 /* Free up the old value, if we have one */
398 bytes_fvalue_free(fv);
399 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
401 return true;
404 static bool
405 system_id_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
408 * Don't request an error message if bytes_from_literal fails;
409 * if it does, we'll report an error specific to this address
410 * type.
412 if (bytes_from_literal(fv, s, true, NULL)) {
413 if (g_bytes_get_size(fv->value.bytes) > MAX_SYSTEMID_LEN) {
414 if (err_msg != NULL) {
415 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid OSI System-ID.",
418 return false;
421 return true;
424 /* XXX - need better validation of OSI System-ID address */
426 if (err_msg != NULL)
427 *err_msg = ws_strdup_printf("\"%s\" is not a valid OSI System-ID.", s);
428 return false;
431 static bool
432 fcwwn_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
435 * Don't request an error message if bytes_from_literal fails;
436 * if it does, we'll report an error specific to this address
437 * type.
439 if (bytes_from_literal(fv, s, true, NULL)) {
440 if (g_bytes_get_size(fv->value.bytes) > FT_FCWWN_LEN) {
441 if (err_msg != NULL) {
442 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid FCWWN.",
445 return false;
448 return true;
451 /* XXX - need better validation of FCWWN address */
453 if (err_msg != NULL)
454 *err_msg = ws_strdup_printf("\"%s\" is not a valid FCWWN.", s);
455 return false;
458 static unsigned
459 len(fvalue_t *fv)
461 return (unsigned)g_bytes_get_size(fv->value.bytes);
464 static void
465 slice(fvalue_t *fv, GByteArray *bytes, unsigned offset, unsigned length)
467 const uint8_t *data = (const uint8_t *)g_bytes_get_data(fv->value.bytes, NULL) + offset;
468 g_byte_array_append(bytes, data, length);
471 static enum ft_result
472 cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b, int *cmp)
474 *cmp = g_bytes_compare(fv_a->value.bytes, fv_b->value.bytes);
475 return FT_OK;
478 static enum ft_result
479 bytes_bitwise_and(fvalue_t *fv_dst, const fvalue_t *fv_a, const fvalue_t *fv_b, char **err_ptr _U_)
481 GByteArray *dst;
482 const uint8_t *p_a, *p_b;
483 size_t size_a, size_b;
485 p_a = g_bytes_get_data(fv_a->value.bytes, &size_a);
486 p_b = g_bytes_get_data(fv_b->value.bytes, &size_b);
488 size_t len = MIN(size_a, size_b);
489 if (len == 0) {
490 fv_dst->value.bytes = g_bytes_new(NULL, 0);
491 return FT_OK;
494 dst = g_byte_array_sized_new((unsigned)len);
495 for (size_t i = 0; i < len; i++) {
496 uint8_t byte = p_a[i] & p_b[i];
497 g_byte_array_append(dst, &byte, 1);
499 fv_dst->value.bytes = g_byte_array_free_to_bytes(dst);
500 return FT_OK;
503 static enum ft_result
504 cmp_contains(const fvalue_t *fv_a, const fvalue_t *fv_b, bool *contains)
506 const void *data_a, *data_b;
507 size_t size_a, size_b;
509 data_a = g_bytes_get_data(fv_a->value.bytes, &size_a);
510 data_b = g_bytes_get_data(fv_b->value.bytes, &size_b);
512 if (ws_memmem(data_a, size_a, data_b, size_b)) {
513 *contains = true;
515 else {
516 *contains = false;
519 return FT_OK;
522 static enum ft_result
523 cmp_matches(const fvalue_t *fv, const ws_regex_t *regex, bool *matches)
525 const void *data;
526 size_t data_size;
528 data = g_bytes_get_data(fv->value.bytes, &data_size);
530 *matches = ws_regex_matches_length(regex, data, data_size);
531 return FT_OK;
534 static unsigned
535 bytes_hash(const fvalue_t *fv)
537 return g_bytes_hash(fv->value.bytes);
540 static bool
541 bytes_is_zero(const fvalue_t *fv)
543 const uint8_t *data;
544 size_t data_size;
546 data = g_bytes_get_data(fv->value.bytes, &data_size);
548 if (data_size == 0)
549 return true;
551 for (size_t i = 0; i < data_size; i++) {
552 if (data[i] != 0) {
553 return false;
556 return true;
559 void
560 ftype_register_bytes(void)
563 static const ftype_t bytes_type = {
564 FT_BYTES, /* ftype */
565 0, /* wire_size */
566 bytes_fvalue_new, /* new_value */
567 bytes_fvalue_copy, /* copy_value */
568 bytes_fvalue_free, /* free_value */
569 bytes_from_literal, /* val_from_literal */
570 bytes_from_string, /* val_from_string */
571 bytes_from_charconst, /* val_from_charconst */
572 bytes_from_uinteger64, /* val_from_uinteger64 */
573 bytes_from_sinteger64, /* val_from_sinteger64 */
574 NULL, /* val_from_double */
575 bytes_to_repr, /* val_to_string_repr */
577 NULL, /* val_to_uinteger64 */
578 NULL, /* val_to_sinteger64 */
579 NULL, /* val_to_double */
581 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
582 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
584 cmp_order,
585 cmp_contains,
586 cmp_matches,
588 bytes_hash, /* hash */
589 bytes_is_zero, /* is_zero */
590 NULL, /* is_negative */
591 len,
592 (FvalueSlice)slice,
593 bytes_bitwise_and, /* bitwise_and */
594 NULL, /* unary_minus */
595 NULL, /* add */
596 NULL, /* subtract */
597 NULL, /* multiply */
598 NULL, /* divide */
599 NULL, /* modulo */
602 static const ftype_t uint_bytes_type = {
603 FT_UINT_BYTES, /* ftype */
604 0, /* wire_size */
605 bytes_fvalue_new, /* new_value */
606 bytes_fvalue_copy, /* copy_value */
607 bytes_fvalue_free, /* free_value */
608 bytes_from_literal, /* val_from_literal */
609 NULL, /* val_from_string */
610 NULL, /* val_from_charconst */
611 NULL, /* val_from_uinteger64 */
612 NULL, /* val_from_sinteger64 */
613 NULL, /* val_from_double */
614 bytes_to_repr, /* val_to_string_repr */
616 NULL, /* val_to_uinteger64 */
617 NULL, /* val_to_sinteger64 */
618 NULL, /* val_to_double */
620 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
621 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
623 cmp_order,
624 cmp_contains,
625 NULL, /* cmp_matches */
627 bytes_hash, /* hash */
628 bytes_is_zero, /* is_zero */
629 NULL, /* is_negative */
630 len,
631 (FvalueSlice)slice,
632 bytes_bitwise_and, /* bitwise_and */
633 NULL, /* unary_minus */
634 NULL, /* add */
635 NULL, /* subtract */
636 NULL, /* multiply */
637 NULL, /* divide */
638 NULL, /* modulo */
641 static const ftype_t vines_type = {
642 FT_VINES, /* ftype */
643 FT_VINES_ADDR_LEN, /* wire_size */
644 bytes_fvalue_new, /* new_value */
645 bytes_fvalue_copy, /* copy_value */
646 bytes_fvalue_free, /* free_value */
647 vines_from_literal, /* val_from_literal */
648 NULL, /* val_from_string */
649 NULL, /* val_from_charconst */
650 NULL, /* val_from_uinteger64 */
651 NULL, /* val_from_sinteger64 */
652 NULL, /* val_from_double */
653 bytes_to_repr, /* val_to_string_repr */
655 NULL, /* val_to_uinteger64 */
656 NULL, /* val_to_sinteger64 */
657 NULL, /* val_to_double */
659 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
660 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
662 cmp_order,
663 cmp_contains,
664 cmp_matches,
666 bytes_hash, /* hash */
667 bytes_is_zero, /* is_zero */
668 NULL, /* is_negative */
669 len,
670 (FvalueSlice)slice,
671 bytes_bitwise_and, /* bitwise_and */
672 NULL, /* unary_minus */
673 NULL, /* add */
674 NULL, /* subtract */
675 NULL, /* multiply */
676 NULL, /* divide */
677 NULL, /* modulo */
680 static const ftype_t ether_type = {
681 FT_ETHER, /* ftype */
682 FT_ETHER_LEN, /* wire_size */
683 bytes_fvalue_new, /* new_value */
684 bytes_fvalue_copy, /* copy_value */
685 bytes_fvalue_free, /* free_value */
686 ether_from_literal, /* val_from_literal */
687 NULL, /* val_from_string */
688 NULL, /* val_from_charconst */
689 NULL, /* val_from_uinteger64 */
690 NULL, /* val_from_sinteger64 */
691 NULL, /* val_from_double */
692 bytes_to_repr, /* val_to_string_repr */
694 NULL, /* val_to_uinteger64 */
695 NULL, /* val_to_sinteger64 */
696 NULL, /* val_to_double */
698 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
699 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
701 cmp_order,
702 cmp_contains,
703 cmp_matches,
705 bytes_hash, /* hash */
706 bytes_is_zero, /* is_zero */
707 NULL, /* is_negative */
708 len,
709 (FvalueSlice)slice,
710 bytes_bitwise_and, /* bitwise_and */
711 NULL, /* unary_minus */
712 NULL, /* add */
713 NULL, /* subtract */
714 NULL, /* multiply */
715 NULL, /* divide */
716 NULL, /* modulo */
719 static const ftype_t oid_type = {
720 FT_OID, /* ftype */
721 0, /* wire_size */
722 bytes_fvalue_new, /* new_value */
723 bytes_fvalue_copy, /* copy_value */
724 bytes_fvalue_free, /* free_value */
725 oid_from_literal, /* val_from_literal */
726 NULL, /* val_from_string */
727 NULL, /* val_from_charconst */
728 NULL, /* val_from_uinteger64 */
729 NULL, /* val_from_sinteger64 */
730 NULL, /* val_from_double */
731 oid_to_repr, /* val_to_string_repr */
733 NULL, /* val_to_uinteger64 */
734 NULL, /* val_to_sinteger64 */
735 NULL, /* val_to_double */
737 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
738 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
740 cmp_order,
741 cmp_contains,
742 NULL, /* cmp_matches */
744 bytes_hash, /* hash */
745 bytes_is_zero, /* is_zero */
746 NULL, /* is_negative */
747 len,
748 (FvalueSlice)slice,
749 bytes_bitwise_and, /* bitwise_and */
750 NULL, /* unary_minus */
751 NULL, /* add */
752 NULL, /* subtract */
753 NULL, /* multiply */
754 NULL, /* divide */
755 NULL, /* modulo */
758 static const ftype_t rel_oid_type = {
759 FT_REL_OID, /* ftype */
760 0, /* wire_size */
761 bytes_fvalue_new, /* new_value */
762 bytes_fvalue_copy, /* copy_value */
763 bytes_fvalue_free, /* free_value */
764 rel_oid_from_literal, /* val_from_literal */
765 NULL, /* val_from_string */
766 NULL, /* val_from_charconst */
767 NULL, /* val_from_uinteger64 */
768 NULL, /* val_from_sinteger64 */
769 NULL, /* val_from_double */
770 rel_oid_to_repr, /* val_to_string_repr */
772 NULL, /* val_to_uinteger64 */
773 NULL, /* val_to_sinteger64 */
774 NULL, /* val_to_double */
776 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
777 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
779 cmp_order,
780 cmp_contains,
781 NULL, /* cmp_matches */
783 bytes_hash, /* hash */
784 bytes_is_zero, /* is_zero */
785 NULL, /* is_negative */
786 len,
787 (FvalueSlice)slice,
788 bytes_bitwise_and, /* bitwise_and */
789 NULL, /* unary_minus */
790 NULL, /* add */
791 NULL, /* subtract */
792 NULL, /* multiply */
793 NULL, /* divide */
794 NULL, /* modulo */
797 static const ftype_t system_id_type = {
798 FT_SYSTEM_ID, /* ftype */
799 0, /* wire_size */
800 bytes_fvalue_new, /* new_value */
801 bytes_fvalue_copy, /* copy_value */
802 bytes_fvalue_free, /* free_value */
803 system_id_from_literal, /* val_from_literal */
804 NULL, /* val_from_string */
805 NULL, /* val_from_charconst */
806 NULL, /* val_from_uinteger64 */
807 NULL, /* val_from_sinteger64 */
808 NULL, /* val_from_double */
809 system_id_to_repr, /* val_to_string_repr */
811 NULL, /* val_to_uinteger64 */
812 NULL, /* val_to_sinteger64 */
813 NULL, /* val_to_double */
815 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
816 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
818 cmp_order,
819 cmp_contains,
820 NULL, /* cmp_matches */
822 bytes_hash, /* hash */
823 bytes_is_zero, /* is_zero */
824 NULL, /* is_negative */
825 len,
826 (FvalueSlice)slice,
827 bytes_bitwise_and, /* bitwise_and */
828 NULL, /* unary_minus */
829 NULL, /* add */
830 NULL, /* subtract */
831 NULL, /* multiply */
832 NULL, /* divide */
833 NULL, /* modulo */
836 static const ftype_t fcwwn_type = {
837 FT_FCWWN, /* ftype */
838 FT_FCWWN_LEN, /* wire_size */
839 bytes_fvalue_new, /* new_value */
840 bytes_fvalue_copy, /* copy_value */
841 bytes_fvalue_free, /* free_value */
842 fcwwn_from_literal, /* val_from_literal */
843 NULL, /* val_from_string */
844 NULL, /* val_from_charconst */
845 NULL, /* val_from_uinteger64 */
846 NULL, /* val_from_sinteger64 */
847 NULL, /* val_from_double */
848 bytes_to_repr, /* val_to_string_repr */
850 NULL, /* val_to_uinteger64 */
851 NULL, /* val_to_sinteger64 */
852 NULL, /* val_to_double */
854 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
855 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
857 cmp_order,
858 cmp_contains,
859 cmp_matches,
861 bytes_hash, /* hash */
862 bytes_is_zero, /* is_zero */
863 NULL, /* is_negative */
864 len,
865 (FvalueSlice)slice,
866 bytes_bitwise_and, /* bitwise_and */
867 NULL, /* unary_minus */
868 NULL, /* add */
869 NULL, /* subtract */
870 NULL, /* multiply */
871 NULL, /* divide */
872 NULL, /* modulo */
875 ftype_register(FT_BYTES, &bytes_type);
876 ftype_register(FT_UINT_BYTES, &uint_bytes_type);
877 ftype_register(FT_VINES, &vines_type);
878 ftype_register(FT_ETHER, &ether_type);
879 ftype_register(FT_OID, &oid_type);
880 ftype_register(FT_REL_OID, &rel_oid_type);
881 ftype_register(FT_SYSTEM_ID, &system_id_type);
882 ftype_register(FT_FCWWN, &fcwwn_type);
885 void
886 ftype_register_pseudofields_bytes(int proto)
888 static int hf_ft_bytes;
889 static int hf_ft_uint_bytes;
890 static int hf_ft_vines;
891 static int hf_ft_ether;
892 static int hf_ft_oid;
893 static int hf_ft_rel_oid;
894 static int hf_ft_system_id;
896 static hf_register_info hf_ftypes[] = {
897 { &hf_ft_bytes,
898 { "FT_BYTES", "_ws.ftypes.bytes",
899 FT_BYTES, BASE_NONE, NULL, 0x00,
900 NULL, HFILL }
902 { &hf_ft_uint_bytes,
903 { "FT_UINT_BYTES", "_ws.ftypes.uint_bytes",
904 FT_UINT_BYTES, BASE_NONE, NULL, 0x00,
905 NULL, HFILL }
907 { &hf_ft_vines,
908 { "FT_VINES", "_ws.ftypes.vines",
909 FT_VINES, BASE_NONE, NULL, 0x00,
910 NULL, HFILL }
912 { &hf_ft_ether,
913 { "FT_ETHER", "_ws.ftypes.ether",
914 FT_ETHER, BASE_NONE, NULL, 0x00,
915 NULL, HFILL }
917 { &hf_ft_oid,
918 { "FT_OID", "_ws.ftypes.oid",
919 FT_OID, BASE_NONE, NULL, 0x00,
920 NULL, HFILL }
922 { &hf_ft_rel_oid,
923 { "FT_REL_OID", "_ws.ftypes.rel_oid",
924 FT_REL_OID, BASE_NONE, NULL, 0x00,
925 NULL, HFILL }
927 { &hf_ft_system_id,
928 { "FT_SYSTEM_ID", "_ws.ftypes.system_id",
929 FT_SYSTEM_ID, BASE_NONE, NULL, 0x00,
930 NULL, HFILL }
934 proto_register_field_array(proto, hf_ftypes, array_length(hf_ftypes));
938 * Editor modelines - https://www.wireshark.org/tools/modelines.html
940 * Local variables:
941 * c-basic-offset: 8
942 * tab-width: 8
943 * indent-tabs-mode: t
944 * End:
946 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
947 * :indentSize=8:tabSize=8:noTabs=false: