regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / epan / services.c
blobf92d2483d696c136c0acbd11883cba70aeb2eab4
1 /* services.c
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "services.h"
11 #include <stdlib.h>
13 #include "services-data.c"
16 static int
17 compare_entry(const void *a, const void *b)
19 return *(const uint16_t *)a - ((const ws_services_entry_t *)b)->port;
22 static inline
23 size_t global_tcp_udp_services_table_count(void)
25 return G_N_ELEMENTS(global_tcp_udp_services_table);
28 static inline
29 size_t global_tcp_services_table_count(void)
31 return G_N_ELEMENTS(global_tcp_services_table);
34 static inline
35 size_t global_udp_services_table_count(void)
37 return G_N_ELEMENTS(global_udp_services_table);
40 static inline
41 size_t global_sctp_services_table_count(void)
43 return G_N_ELEMENTS(global_sctp_services_table);
46 static inline
47 size_t global_dccp_services_table_count(void)
49 return G_N_ELEMENTS(global_dccp_services_table);
52 ws_services_entry_t const *
53 global_services_lookup(uint16_t value, ws_services_proto_t proto)
55 ws_services_entry_t const *list1 = NULL, *list2 = NULL;
56 size_t list1_size, list2_size;
57 ws_services_entry_t const *found;
59 switch (proto) {
60 case ws_tcp:
61 list1 = global_tcp_udp_services_table;
62 list1_size = global_tcp_udp_services_table_count();
63 list2 = global_tcp_services_table;
64 list2_size = global_tcp_services_table_count();
65 break;
66 case ws_udp:
67 list1 = global_tcp_udp_services_table;
68 list1_size = global_tcp_udp_services_table_count();
69 list2 = global_udp_services_table;
70 list2_size = global_udp_services_table_count();
71 break;
72 case ws_sctp:
73 list1 = global_sctp_services_table;
74 list1_size = global_sctp_services_table_count();
75 break;
76 case ws_dccp:
77 list1 = global_dccp_services_table;
78 list1_size = global_dccp_services_table_count();
79 break;
80 default:
81 ws_assert_not_reached();
84 if (list1) {
85 found = bsearch(&value, list1, list1_size, sizeof(ws_services_entry_t), compare_entry);
86 if (found) {
87 return found;
91 if (list2) {
92 found = bsearch(&value, list2, list2_size, sizeof(ws_services_entry_t), compare_entry);
93 if (found) {
94 return found;
98 return NULL;
101 void
102 global_services_dump(FILE *fp)
104 ws_services_entry_t const *ptr;
106 /* Brute-force approach... */
107 for (uint16_t num = 0; num <= _services_max_port && num < UINT16_MAX; num++) {
108 /* TCP */
109 ptr = global_services_lookup(num, ws_tcp);
110 if (ptr != NULL) {
111 fprintf(fp, "%s\t%"PRIu16"\ttcp\t%s\n", ptr->name, num, ptr->description);
113 /* UDP */
114 ptr = global_services_lookup(num, ws_udp);
115 if (ptr != NULL) {
116 fprintf(fp, "%s\t%"PRIu16"\tudp\t%s\n", ptr->name, num, ptr->description);
118 /* SCTP */
119 ptr = global_services_lookup(num, ws_sctp);
120 if (ptr != NULL) {
121 fprintf(fp, "%s\t%"PRIu16"\tsctp\t%s\n", ptr->name, num, ptr->description);
123 /* DCCP */
124 ptr = global_services_lookup(num, ws_dccp);
125 if (ptr != NULL) {
126 fprintf(fp, "%s\t%"PRIu16"\tdccp\t%s\n", ptr->name, num, ptr->description);