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
13 #include "services-data.c"
17 compare_entry(const void *a
, const void *b
)
19 return *(const uint16_t *)a
- ((const ws_services_entry_t
*)b
)->port
;
23 size_t global_tcp_udp_services_table_count(void)
25 return G_N_ELEMENTS(global_tcp_udp_services_table
);
29 size_t global_tcp_services_table_count(void)
31 return G_N_ELEMENTS(global_tcp_services_table
);
35 size_t global_udp_services_table_count(void)
37 return G_N_ELEMENTS(global_udp_services_table
);
41 size_t global_sctp_services_table_count(void)
43 return G_N_ELEMENTS(global_sctp_services_table
);
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
;
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();
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();
73 list1
= global_sctp_services_table
;
74 list1_size
= global_sctp_services_table_count();
77 list1
= global_dccp_services_table
;
78 list1_size
= global_dccp_services_table_count();
81 ws_assert_not_reached();
85 found
= bsearch(&value
, list1
, list1_size
, sizeof(ws_services_entry_t
), compare_entry
);
92 found
= bsearch(&value
, list2
, list2_size
, sizeof(ws_services_entry_t
), compare_entry
);
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
++) {
109 ptr
= global_services_lookup(num
, ws_tcp
);
111 fprintf(fp
, "%s\t%"PRIu16
"\ttcp\t%s\n", ptr
->name
, num
, ptr
->description
);
114 ptr
= global_services_lookup(num
, ws_udp
);
116 fprintf(fp
, "%s\t%"PRIu16
"\tudp\t%s\n", ptr
->name
, num
, ptr
->description
);
119 ptr
= global_services_lookup(num
, ws_sctp
);
121 fprintf(fp
, "%s\t%"PRIu16
"\tsctp\t%s\n", ptr
->name
, num
, ptr
->description
);
124 ptr
= global_services_lookup(num
, ws_dccp
);
126 fprintf(fp
, "%s\t%"PRIu16
"\tdccp\t%s\n", ptr
->name
, num
, ptr
->description
);