Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / ftypes / ftype-bytes.c
blobc555478197ad180980ad1fab43645f083767a569
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>
21 #include <wsutil/pint.h>
23 static void
24 bytes_fvalue_new(fvalue_t *fv)
26 fv->value.bytes = NULL;
29 static void
30 bytes_fvalue_copy(fvalue_t *dst, const fvalue_t *src)
32 dst->value.bytes = g_bytes_ref(src->value.bytes);
35 static void
36 bytes_fvalue_free(fvalue_t *fv)
38 if (fv->value.bytes) {
39 g_bytes_unref(fv->value.bytes);
40 fv->value.bytes = NULL;
45 static void
46 bytes_fvalue_set(fvalue_t *fv, GBytes *value)
48 /* Free up the old value, if we have one */
49 bytes_fvalue_free(fv);
51 fv->value.bytes = g_bytes_ref(value);
54 static GBytes *
55 bytes_fvalue_get(fvalue_t *fv)
57 return g_bytes_ref(fv->value.bytes);
60 static char *
61 oid_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
63 return oid_encoded2string(scope, g_bytes_get_data(fv->value.bytes, NULL), (unsigned)g_bytes_get_size(fv->value.bytes));
66 static char *
67 rel_oid_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
69 return rel_oid_encoded2string(scope, g_bytes_get_data(fv->value.bytes, NULL), (unsigned)g_bytes_get_size(fv->value.bytes));
72 static char *
73 system_id_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_)
75 return print_system_id(scope, g_bytes_get_data(fv->value.bytes, NULL), (unsigned)g_bytes_get_size(fv->value.bytes));
78 char *
79 bytes_to_dfilter_repr(wmem_allocator_t *scope,
80 const uint8_t *src, size_t src_size)
82 char *buf;
83 size_t max_char_size;
84 char *buf_ptr;
86 /* Include space for extra punct and '\0'. */
87 max_char_size = src_size * 3 + 1;
89 buf = wmem_alloc(scope, max_char_size);
90 buf_ptr = bytes_to_hexstr_punct(buf, src, src_size, ':');
91 if (src_size == 1)
92 *buf_ptr++ = ':';
93 *buf_ptr = '\0';
94 return buf;
97 static char *
98 bytes_to_repr(wmem_allocator_t *scope, const fvalue_t *fv, ftrepr_t rtype, int field_display)
100 char separator;
101 const uint8_t *bytes;
102 size_t bytes_size;
104 bytes = g_bytes_get_data(fv->value.bytes, &bytes_size);
106 if (rtype == FTREPR_DFILTER) {
107 if (bytes_size == 0) {
108 /* An empty byte array in a display filter is represented as "" */
109 return wmem_strdup(scope, "\"\"");
111 return bytes_to_dfilter_repr(scope, bytes, bytes_size);
114 switch(FIELD_DISPLAY(field_display))
116 case SEP_DOT:
117 separator = '.';
118 break;
119 case SEP_DASH:
120 separator = '-';
121 break;
122 case SEP_SPACE:
123 case SEP_COLON:
124 case BASE_NONE:
125 default:
126 separator = ':';
127 break;
130 if (bytes_size) {
131 return bytes_to_str_punct_maxlen(scope, bytes, bytes_size, separator, 0);
134 return wmem_strdup(scope, "");
137 static bool
138 bytes_from_string(fvalue_t *fv, const char *s, size_t len, char **err_msg _U_)
140 GByteArray *bytes;
142 bytes = g_byte_array_new();
144 if (len == 0)
145 len = strlen(s);
147 g_byte_array_append(bytes, (const uint8_t *)s, (unsigned)len);
149 /* Free up the old value, if we have one */
150 bytes_fvalue_free(fv);
151 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
153 return true;
156 GByteArray *
157 byte_array_from_literal(const char *s, char **err_msg)
159 GByteArray *bytes;
160 bool res;
162 /* Skip leading colon if any. */
163 if (*s == ':')
164 s++;
167 * Special case where the byte string is specified using a one byte
168 * hex literal. We can't allow this for byte strings that are longer
169 * than one byte, because then we'd have to know which endianness the
170 * byte string should be in.
172 if (strlen(s) == 4 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
173 s = s + 2;
175 bytes = g_byte_array_new();
177 /* Hack: If we have a binary number 0bXXXXXXXX use that as a byte array
178 * of length one. This is ambiguous because it can also be
179 * parsed (without separators) as a byte array of length 5:
180 * 0bXXXXXXXX = 0b:XX:XX:XX:XX = { 0x0b, 0xXX, 0xXX, 0xXX, 0xXX } */
181 if (strlen(s) == 10 && s[0] == '0' && (s[1] == 'b' || s[1] == 'B') &&
182 (s[2] == '0' || s[2] == '1')) {
183 errno = 0;
184 char *endptr;
185 long number = strtol(s + 2, &endptr, 2);
186 if (errno == 0 && *endptr == '\0' && number >= 0x0 && number <= 0xff) {
187 uint8_t byte = (uint8_t)number;
188 g_byte_array_append(bytes, &byte, 1);
189 return bytes;
193 res = hex_str_to_bytes(s, bytes, false);
195 if (!res) {
196 if (err_msg != NULL)
197 *err_msg = ws_strdup_printf("\"%s\" is not a valid byte string.", s);
198 g_byte_array_free(bytes, true);
199 return NULL;
202 return bytes;
205 static bool
206 bytes_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
208 GByteArray *bytes;
210 bytes = byte_array_from_literal(s, err_msg);
211 if (bytes == NULL)
212 return false;
214 /* Free up the old value, if we have one */
215 bytes_fvalue_free(fv);
217 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
219 return true;
222 GByteArray *
223 byte_array_from_charconst(unsigned long num, char **err_msg)
225 if (num > UINT8_MAX) {
226 if (err_msg) {
227 *err_msg = ws_strdup_printf("%lu is too large for a byte value", num);
229 return NULL;
232 GByteArray *bytes = g_byte_array_new();
233 uint8_t one_byte = (uint8_t)num;
234 g_byte_array_append(bytes, &one_byte, 1);
235 return bytes;
238 static bool
239 bytes_from_charconst(fvalue_t *fv, unsigned long num, char **err_msg)
241 GByteArray *bytes;
243 bytes = byte_array_from_charconst(num, err_msg);
244 if (bytes == NULL)
245 return false;
247 /* Free up the old value, if we have one */
248 bytes_fvalue_free(fv);
250 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
252 return true;
255 static bool
256 bytes_from_uinteger64(fvalue_t *fv, const char *s _U_, uint64_t num, char **err_msg)
258 if (num > UINT8_MAX) {
259 if (err_msg) {
260 *err_msg = ws_strdup_printf("%s is too large for a byte value", s);
262 return false;
265 return bytes_from_charconst(fv, (unsigned long)num, err_msg);
268 static bool
269 bytes_from_sinteger64(fvalue_t *fv, const char *s, int64_t num, char **err_msg)
271 if (num < 0) {
272 if (err_msg) {
273 *err_msg = ws_strdup_printf("Byte values cannot be negative");
275 return false;
277 return bytes_from_uinteger64(fv, s, (uint64_t)num, err_msg);
280 static bool
281 vines_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value, char **err_msg)
284 * Don't request an error message if bytes_from_literal fails;
285 * if it does, we'll report an error specific to this address
286 * type.
288 if (bytes_from_literal(fv, s, true, NULL)) {
289 if (g_bytes_get_size(fv->value.bytes) > FT_VINES_ADDR_LEN) {
290 if (err_msg != NULL) {
291 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid Vines address.",
294 return false;
296 else if (g_bytes_get_size(fv->value.bytes) < FT_VINES_ADDR_LEN && !allow_partial_value) {
297 if (err_msg != NULL) {
298 *err_msg = ws_strdup_printf("\"%s\" contains too few bytes to be a valid Vines address.",
301 return false;
304 return true;
307 /* XXX - need better validation of Vines address */
309 if (err_msg != NULL)
310 *err_msg = ws_strdup_printf("\"%s\" is not a valid Vines address.", s);
311 return false;
314 static bool
315 ether_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value, char **err_msg)
318 * Don't request an error message if bytes_from_literal fails;
319 * if it does, we'll report an error specific to this address
320 * type.
322 if (bytes_from_literal(fv, s, true, NULL)) {
323 if (g_bytes_get_size(fv->value.bytes) > FT_ETHER_LEN) {
324 if (err_msg != NULL) {
325 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid Ethernet address.",
328 return false;
330 else if (g_bytes_get_size(fv->value.bytes) < FT_ETHER_LEN && !allow_partial_value) {
331 if (err_msg != NULL) {
332 *err_msg = ws_strdup_printf("\"%s\" contains too few bytes to be a valid Ethernet address.",
335 return false;
338 return true;
341 /* XXX - Try resolving as an Ethernet host name and parse that? */
343 if (err_msg != NULL)
344 *err_msg = ws_strdup_printf("\"%s\" is not a valid Ethernet address.", s);
345 return false;
348 static bool
349 oid_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
351 GByteArray *bytes;
352 bool res;
355 #if 0
357 * Don't log a message if this fails; we'll try looking it
358 * up as an OID if it does, and if that fails,
359 * we'll log a message.
361 /* do not try it as '.' is handled as valid separator for hexbytes :( */
362 if (bytes_from_literal(fv, s, true, NULL)) {
363 return true;
365 #endif
367 bytes = g_byte_array_new();
368 res = oid_str_to_bytes(s, bytes);
369 if (!res) {
370 if (err_msg != NULL)
371 *err_msg = ws_strdup_printf("\"%s\" is not a valid OBJECT IDENTIFIER.", s);
372 g_byte_array_free(bytes, true);
373 return false;
376 /* Free up the old value, if we have one */
377 bytes_fvalue_free(fv);
378 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
380 return true;
383 static bool
384 rel_oid_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
386 GByteArray *bytes;
387 bool res;
389 bytes = g_byte_array_new();
390 res = rel_oid_str_to_bytes(s, bytes, false);
391 if (!res) {
392 if (err_msg != NULL)
393 *err_msg = ws_strdup_printf("\"%s\" is not a valid RELATIVE-OID.", s);
394 g_byte_array_free(bytes, true);
395 return false;
398 /* Free up the old value, if we have one */
399 bytes_fvalue_free(fv);
400 fv->value.bytes = g_byte_array_free_to_bytes(bytes);
402 return true;
405 static bool
406 system_id_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
409 * Don't request an error message if bytes_from_literal fails;
410 * if it does, we'll report an error specific to this address
411 * type.
413 if (bytes_from_literal(fv, s, true, NULL)) {
414 if (g_bytes_get_size(fv->value.bytes) > MAX_SYSTEMID_LEN) {
415 if (err_msg != NULL) {
416 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid OSI System-ID.",
419 return false;
422 return true;
425 /* XXX - need better validation of OSI System-ID address */
427 if (err_msg != NULL)
428 *err_msg = ws_strdup_printf("\"%s\" is not a valid OSI System-ID.", s);
429 return false;
432 static bool
433 fcwwn_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value _U_, char **err_msg)
436 * Don't request an error message if bytes_from_literal fails;
437 * if it does, we'll report an error specific to this address
438 * type.
440 if (bytes_from_literal(fv, s, true, NULL)) {
441 if (g_bytes_get_size(fv->value.bytes) > FT_FCWWN_LEN) {
442 if (err_msg != NULL) {
443 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid FCWWN.",
446 return false;
449 return true;
452 /* XXX - need better validation of FCWWN address */
454 if (err_msg != NULL)
455 *err_msg = ws_strdup_printf("\"%s\" is not a valid FCWWN.", s);
456 return false;
459 static bool
460 eui64_from_literal(fvalue_t *fv, const char *s, bool allow_partial_value, char **err_msg)
463 * Don't request an error message if bytes_from_literal fails;
464 * if it does, we'll report an error specific to this address
465 * type.
467 if (bytes_from_literal(fv, s, true, NULL)) {
468 if (g_bytes_get_size(fv->value.bytes) > FT_EUI64_LEN) {
469 if (err_msg != NULL) {
470 *err_msg = ws_strdup_printf("\"%s\" contains too many bytes to be a valid EUI-64 address.",
473 return false;
475 else if (g_bytes_get_size(fv->value.bytes) < FT_EUI64_LEN && !allow_partial_value) {
476 if (err_msg != NULL) {
477 *err_msg = ws_strdup_printf("\"%s\" contains too few bytes to be a valid EUI-64 address.",
480 return false;
483 return true;
486 /* XXX - Implement EUI-64 resolving (#15487) and lookup and parse that? */
488 if (err_msg != NULL)
489 *err_msg = ws_strdup_printf("\"%s\" is not a valid EUI-64 address.", s);
490 return false;
493 static bool
494 eui64_from_uinteger64(fvalue_t *fv, const char *s _U_, uint64_t value, char **err_msg _U_)
496 /* Backwards compatibility for specifying as unsigned integer. */
497 uint8_t data[FT_EUI64_LEN];
498 phton64(data, value);
500 /* Free up the old value, if we have one */
501 bytes_fvalue_free(fv);
502 fv->value.bytes = g_bytes_new(data, FT_EUI64_LEN);
503 return true;
506 static unsigned
507 len(fvalue_t *fv)
509 return (unsigned)g_bytes_get_size(fv->value.bytes);
512 static void
513 slice(fvalue_t *fv, GByteArray *bytes, unsigned offset, unsigned length)
515 const uint8_t *data = (const uint8_t *)g_bytes_get_data(fv->value.bytes, NULL) + offset;
516 g_byte_array_append(bytes, data, length);
519 static enum ft_result
520 cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b, int *cmp)
522 *cmp = g_bytes_compare(fv_a->value.bytes, fv_b->value.bytes);
523 return FT_OK;
526 static enum ft_result
527 bytes_bitwise_and(fvalue_t *fv_dst, const fvalue_t *fv_a, const fvalue_t *fv_b, char **err_ptr _U_)
529 GByteArray *dst;
530 const uint8_t *p_a, *p_b;
531 size_t size_a, size_b;
533 p_a = g_bytes_get_data(fv_a->value.bytes, &size_a);
534 p_b = g_bytes_get_data(fv_b->value.bytes, &size_b);
536 size_t len = MIN(size_a, size_b);
537 if (len == 0) {
538 fv_dst->value.bytes = g_bytes_new(NULL, 0);
539 return FT_OK;
542 dst = g_byte_array_sized_new((unsigned)len);
543 for (size_t i = 0; i < len; i++) {
544 uint8_t byte = p_a[i] & p_b[i];
545 g_byte_array_append(dst, &byte, 1);
547 fv_dst->value.bytes = g_byte_array_free_to_bytes(dst);
548 return FT_OK;
551 static enum ft_result
552 cmp_contains(const fvalue_t *fv_a, const fvalue_t *fv_b, bool *contains)
554 const void *data_a, *data_b;
555 size_t size_a, size_b;
557 data_a = g_bytes_get_data(fv_a->value.bytes, &size_a);
558 data_b = g_bytes_get_data(fv_b->value.bytes, &size_b);
560 if (ws_memmem(data_a, size_a, data_b, size_b)) {
561 *contains = true;
563 else {
564 *contains = false;
567 return FT_OK;
570 static enum ft_result
571 cmp_matches(const fvalue_t *fv, const ws_regex_t *regex, bool *matches)
573 const void *data;
574 size_t data_size;
576 data = g_bytes_get_data(fv->value.bytes, &data_size);
578 *matches = ws_regex_matches_length(regex, data, data_size);
579 return FT_OK;
582 static unsigned
583 bytes_hash(const fvalue_t *fv)
585 return g_bytes_hash(fv->value.bytes);
588 static bool
589 bytes_is_zero(const fvalue_t *fv)
591 const uint8_t *data;
592 size_t data_size;
594 data = g_bytes_get_data(fv->value.bytes, &data_size);
596 if (data_size == 0)
597 return true;
599 for (size_t i = 0; i < data_size; i++) {
600 if (data[i] != 0) {
601 return false;
604 return true;
607 void
608 ftype_register_bytes(void)
611 static const ftype_t bytes_type = {
612 FT_BYTES, /* ftype */
613 0, /* wire_size */
614 bytes_fvalue_new, /* new_value */
615 bytes_fvalue_copy, /* copy_value */
616 bytes_fvalue_free, /* free_value */
617 bytes_from_literal, /* val_from_literal */
618 bytes_from_string, /* val_from_string */
619 bytes_from_charconst, /* val_from_charconst */
620 bytes_from_uinteger64, /* val_from_uinteger64 */
621 bytes_from_sinteger64, /* val_from_sinteger64 */
622 NULL, /* val_from_double */
623 bytes_to_repr, /* val_to_string_repr */
625 NULL, /* val_to_uinteger64 */
626 NULL, /* val_to_sinteger64 */
627 NULL, /* val_to_double */
629 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
630 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
632 cmp_order,
633 cmp_contains,
634 cmp_matches,
636 bytes_hash, /* hash */
637 bytes_is_zero, /* is_zero */
638 NULL, /* is_negative */
639 len,
640 (FvalueSlice)slice,
641 bytes_bitwise_and, /* bitwise_and */
642 NULL, /* unary_minus */
643 NULL, /* add */
644 NULL, /* subtract */
645 NULL, /* multiply */
646 NULL, /* divide */
647 NULL, /* modulo */
650 static const ftype_t uint_bytes_type = {
651 FT_UINT_BYTES, /* ftype */
652 0, /* wire_size */
653 bytes_fvalue_new, /* new_value */
654 bytes_fvalue_copy, /* copy_value */
655 bytes_fvalue_free, /* free_value */
656 bytes_from_literal, /* val_from_literal */
657 NULL, /* val_from_string */
658 NULL, /* val_from_charconst */
659 NULL, /* val_from_uinteger64 */
660 NULL, /* val_from_sinteger64 */
661 NULL, /* val_from_double */
662 bytes_to_repr, /* val_to_string_repr */
664 NULL, /* val_to_uinteger64 */
665 NULL, /* val_to_sinteger64 */
666 NULL, /* val_to_double */
668 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
669 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
671 cmp_order,
672 cmp_contains,
673 NULL, /* cmp_matches */
675 bytes_hash, /* hash */
676 bytes_is_zero, /* is_zero */
677 NULL, /* is_negative */
678 len,
679 (FvalueSlice)slice,
680 bytes_bitwise_and, /* bitwise_and */
681 NULL, /* unary_minus */
682 NULL, /* add */
683 NULL, /* subtract */
684 NULL, /* multiply */
685 NULL, /* divide */
686 NULL, /* modulo */
689 static const ftype_t vines_type = {
690 FT_VINES, /* ftype */
691 FT_VINES_ADDR_LEN, /* wire_size */
692 bytes_fvalue_new, /* new_value */
693 bytes_fvalue_copy, /* copy_value */
694 bytes_fvalue_free, /* free_value */
695 vines_from_literal, /* val_from_literal */
696 NULL, /* val_from_string */
697 NULL, /* val_from_charconst */
698 NULL, /* val_from_uinteger64 */
699 NULL, /* val_from_sinteger64 */
700 NULL, /* val_from_double */
701 bytes_to_repr, /* val_to_string_repr */
703 NULL, /* val_to_uinteger64 */
704 NULL, /* val_to_sinteger64 */
705 NULL, /* val_to_double */
707 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
708 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
710 cmp_order,
711 cmp_contains,
712 cmp_matches,
714 bytes_hash, /* hash */
715 bytes_is_zero, /* is_zero */
716 NULL, /* is_negative */
717 len,
718 (FvalueSlice)slice,
719 bytes_bitwise_and, /* bitwise_and */
720 NULL, /* unary_minus */
721 NULL, /* add */
722 NULL, /* subtract */
723 NULL, /* multiply */
724 NULL, /* divide */
725 NULL, /* modulo */
728 static const ftype_t ether_type = {
729 FT_ETHER, /* ftype */
730 FT_ETHER_LEN, /* wire_size */
731 bytes_fvalue_new, /* new_value */
732 bytes_fvalue_copy, /* copy_value */
733 bytes_fvalue_free, /* free_value */
734 ether_from_literal, /* val_from_literal */
735 NULL, /* val_from_string */
736 NULL, /* val_from_charconst */
737 NULL, /* val_from_uinteger64 */
738 NULL, /* val_from_sinteger64 */
739 NULL, /* val_from_double */
740 bytes_to_repr, /* val_to_string_repr */
742 NULL, /* val_to_uinteger64 */
743 NULL, /* val_to_sinteger64 */
744 NULL, /* val_to_double */
746 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
747 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
749 cmp_order,
750 cmp_contains,
751 cmp_matches,
753 bytes_hash, /* hash */
754 bytes_is_zero, /* is_zero */
755 NULL, /* is_negative */
756 len,
757 (FvalueSlice)slice,
758 bytes_bitwise_and, /* bitwise_and */
759 NULL, /* unary_minus */
760 NULL, /* add */
761 NULL, /* subtract */
762 NULL, /* multiply */
763 NULL, /* divide */
764 NULL, /* modulo */
767 static const ftype_t oid_type = {
768 FT_OID, /* ftype */
769 0, /* wire_size */
770 bytes_fvalue_new, /* new_value */
771 bytes_fvalue_copy, /* copy_value */
772 bytes_fvalue_free, /* free_value */
773 oid_from_literal, /* val_from_literal */
774 NULL, /* val_from_string */
775 NULL, /* val_from_charconst */
776 NULL, /* val_from_uinteger64 */
777 NULL, /* val_from_sinteger64 */
778 NULL, /* val_from_double */
779 oid_to_repr, /* val_to_string_repr */
781 NULL, /* val_to_uinteger64 */
782 NULL, /* val_to_sinteger64 */
783 NULL, /* val_to_double */
785 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
786 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
788 cmp_order,
789 cmp_contains,
790 NULL, /* cmp_matches */
792 bytes_hash, /* hash */
793 bytes_is_zero, /* is_zero */
794 NULL, /* is_negative */
795 len,
796 (FvalueSlice)slice,
797 bytes_bitwise_and, /* bitwise_and */
798 NULL, /* unary_minus */
799 NULL, /* add */
800 NULL, /* subtract */
801 NULL, /* multiply */
802 NULL, /* divide */
803 NULL, /* modulo */
806 static const ftype_t rel_oid_type = {
807 FT_REL_OID, /* ftype */
808 0, /* wire_size */
809 bytes_fvalue_new, /* new_value */
810 bytes_fvalue_copy, /* copy_value */
811 bytes_fvalue_free, /* free_value */
812 rel_oid_from_literal, /* val_from_literal */
813 NULL, /* val_from_string */
814 NULL, /* val_from_charconst */
815 NULL, /* val_from_uinteger64 */
816 NULL, /* val_from_sinteger64 */
817 NULL, /* val_from_double */
818 rel_oid_to_repr, /* val_to_string_repr */
820 NULL, /* val_to_uinteger64 */
821 NULL, /* val_to_sinteger64 */
822 NULL, /* val_to_double */
824 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
825 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
827 cmp_order,
828 cmp_contains,
829 NULL, /* cmp_matches */
831 bytes_hash, /* hash */
832 bytes_is_zero, /* is_zero */
833 NULL, /* is_negative */
834 len,
835 (FvalueSlice)slice,
836 bytes_bitwise_and, /* bitwise_and */
837 NULL, /* unary_minus */
838 NULL, /* add */
839 NULL, /* subtract */
840 NULL, /* multiply */
841 NULL, /* divide */
842 NULL, /* modulo */
845 static const ftype_t system_id_type = {
846 FT_SYSTEM_ID, /* ftype */
847 0, /* wire_size */
848 bytes_fvalue_new, /* new_value */
849 bytes_fvalue_copy, /* copy_value */
850 bytes_fvalue_free, /* free_value */
851 system_id_from_literal, /* val_from_literal */
852 NULL, /* val_from_string */
853 NULL, /* val_from_charconst */
854 NULL, /* val_from_uinteger64 */
855 NULL, /* val_from_sinteger64 */
856 NULL, /* val_from_double */
857 system_id_to_repr, /* val_to_string_repr */
859 NULL, /* val_to_uinteger64 */
860 NULL, /* val_to_sinteger64 */
861 NULL, /* val_to_double */
863 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
864 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
866 cmp_order,
867 cmp_contains,
868 NULL, /* cmp_matches */
870 bytes_hash, /* hash */
871 bytes_is_zero, /* is_zero */
872 NULL, /* is_negative */
873 len,
874 (FvalueSlice)slice,
875 bytes_bitwise_and, /* bitwise_and */
876 NULL, /* unary_minus */
877 NULL, /* add */
878 NULL, /* subtract */
879 NULL, /* multiply */
880 NULL, /* divide */
881 NULL, /* modulo */
884 static const ftype_t fcwwn_type = {
885 FT_FCWWN, /* ftype */
886 FT_FCWWN_LEN, /* wire_size */
887 bytes_fvalue_new, /* new_value */
888 bytes_fvalue_copy, /* copy_value */
889 bytes_fvalue_free, /* free_value */
890 fcwwn_from_literal, /* val_from_literal */
891 NULL, /* val_from_string */
892 NULL, /* val_from_charconst */
893 NULL, /* val_from_uinteger64 */
894 NULL, /* val_from_sinteger64 */
895 NULL, /* val_from_double */
896 bytes_to_repr, /* val_to_string_repr */
898 NULL, /* val_to_uinteger64 */
899 NULL, /* val_to_sinteger64 */
900 NULL, /* val_to_double */
902 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
903 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
905 cmp_order,
906 cmp_contains,
907 cmp_matches,
909 bytes_hash, /* hash */
910 bytes_is_zero, /* is_zero */
911 NULL, /* is_negative */
912 len,
913 (FvalueSlice)slice,
914 bytes_bitwise_and, /* bitwise_and */
915 NULL, /* unary_minus */
916 NULL, /* add */
917 NULL, /* subtract */
918 NULL, /* multiply */
919 NULL, /* divide */
920 NULL, /* modulo */
923 static const ftype_t eui64_type = {
924 FT_EUI64, /* ftype */
925 FT_EUI64_LEN, /* wire_size */
926 bytes_fvalue_new, /* new_value */
927 bytes_fvalue_copy, /* copy_value */
928 bytes_fvalue_free, /* free_value */
929 eui64_from_literal, /* val_from_literal */
930 NULL, /* val_from_string */
931 NULL, /* val_from_charconst */
932 eui64_from_uinteger64, /* val_from_uinteger64 */
933 NULL, /* val_from_sinteger64 */
934 NULL, /* val_from_double */
935 bytes_to_repr, /* val_to_string_repr */
937 NULL, /* val_to_uinteger64 */
938 NULL, /* val_to_sinteger64 */
939 NULL, /* val_to_double */
941 { .set_value_bytes = bytes_fvalue_set }, /* union set_value */
942 { .get_value_bytes = bytes_fvalue_get }, /* union get_value */
944 cmp_order,
945 cmp_contains,
946 cmp_matches,
948 bytes_hash, /* hash */
949 bytes_is_zero, /* is_zero */
950 NULL, /* is_negative */
951 len,
952 (FvalueSlice)slice,
953 bytes_bitwise_and, /* bitwise_and */
954 NULL, /* unary_minus */
955 NULL, /* add */
956 NULL, /* subtract */
957 NULL, /* multiply */
958 NULL, /* divide */
959 NULL, /* modulo */
962 ftype_register(FT_BYTES, &bytes_type);
963 ftype_register(FT_UINT_BYTES, &uint_bytes_type);
964 ftype_register(FT_VINES, &vines_type);
965 ftype_register(FT_ETHER, &ether_type);
966 ftype_register(FT_OID, &oid_type);
967 ftype_register(FT_REL_OID, &rel_oid_type);
968 ftype_register(FT_SYSTEM_ID, &system_id_type);
969 ftype_register(FT_FCWWN, &fcwwn_type);
970 ftype_register(FT_EUI64, &eui64_type);
973 void
974 ftype_register_pseudofields_bytes(int proto)
976 static int hf_ft_bytes;
977 static int hf_ft_uint_bytes;
978 static int hf_ft_vines;
979 static int hf_ft_ether;
980 static int hf_ft_oid;
981 static int hf_ft_rel_oid;
982 static int hf_ft_system_id;
983 static int hf_ft_eui64;
985 static hf_register_info hf_ftypes[] = {
986 { &hf_ft_bytes,
987 { "FT_BYTES", "_ws.ftypes.bytes",
988 FT_BYTES, BASE_NONE, NULL, 0x00,
989 NULL, HFILL }
991 { &hf_ft_uint_bytes,
992 { "FT_UINT_BYTES", "_ws.ftypes.uint_bytes",
993 FT_UINT_BYTES, BASE_NONE, NULL, 0x00,
994 NULL, HFILL }
996 { &hf_ft_vines,
997 { "FT_VINES", "_ws.ftypes.vines",
998 FT_VINES, BASE_NONE, NULL, 0x00,
999 NULL, HFILL }
1001 { &hf_ft_ether,
1002 { "FT_ETHER", "_ws.ftypes.ether",
1003 FT_ETHER, BASE_NONE, NULL, 0x00,
1004 NULL, HFILL }
1006 { &hf_ft_oid,
1007 { "FT_OID", "_ws.ftypes.oid",
1008 FT_OID, BASE_NONE, NULL, 0x00,
1009 NULL, HFILL }
1011 { &hf_ft_rel_oid,
1012 { "FT_REL_OID", "_ws.ftypes.rel_oid",
1013 FT_REL_OID, BASE_NONE, NULL, 0x00,
1014 NULL, HFILL }
1016 { &hf_ft_system_id,
1017 { "FT_SYSTEM_ID", "_ws.ftypes.system_id",
1018 FT_SYSTEM_ID, BASE_NONE, NULL, 0x00,
1019 NULL, HFILL }
1021 { &hf_ft_eui64,
1022 { "FT_EUI64", "_ws.ftypes.eui64",
1023 FT_EUI64, BASE_NONE, NULL, 0x00,
1024 NULL, HFILL }
1028 proto_register_field_array(proto, hf_ftypes, array_length(hf_ftypes));
1032 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1034 * Local variables:
1035 * c-basic-offset: 8
1036 * tab-width: 8
1037 * indent-tabs-mode: t
1038 * End:
1040 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1041 * :indentSize=8:tabSize=8:noTabs=false: