/src/wireshark/wiretap/pcapng-darwin-custom.c
Line | Count | Source |
1 | | /** |
2 | | * Support for Apple Legacy and Custom pcapng blocks and options |
3 | | * Copyright 2025, Omer Shapira <oesh@apple.com> |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 2001 Gerald Combs |
8 | | * |
9 | | * SPDX-License-Identifier: GPL-2.0-or-later |
10 | | */ |
11 | | |
12 | | #include "config.h" |
13 | | |
14 | | #include <glib.h> |
15 | | |
16 | | #include "wtap_module.h" |
17 | | #include "pcapng.h" |
18 | | #include "pcapng_module.h" |
19 | | #include "wtap_opttypes.h" |
20 | | #include "wsutil/ws_padding_to.h" |
21 | | |
22 | | |
23 | | /* pcapng: legacy DPIB (Darwin Process Info Block) file encoding. */ |
24 | | typedef struct pcapng_legacy_darwin_process_info_block_s { |
25 | | uint32_t process_id; |
26 | | /* Options */ |
27 | | } pcapng_legacy_darwin_process_info_block_t; |
28 | | |
29 | | |
30 | | /* Minimum DPIB size = minimum block size + size of fixed length portion of DPIB. */ |
31 | 0 | #define MIN_DPIB_SIZE ((uint32_t)sizeof(pcapng_legacy_darwin_process_info_block_t)) |
32 | | |
33 | | |
34 | | static uint32_t |
35 | | compute_dpib_option_size(wtap_block_t block _U_, unsigned option_code, wtap_opttype_e option_type _U_, wtap_optval_t* optval) |
36 | 0 | { |
37 | 0 | uint32_t size = 0; |
38 | |
|
39 | 0 | switch (option_code) { |
40 | 0 | case(OPT_DPIB_NAME): /* dpib_process_name */ |
41 | 0 | size = (uint32_t)strlen(optval->stringval) & 0xffff; |
42 | 0 | break; |
43 | 0 | case(OPT_DPIB_UUID): /* dpib_process_uuid */ |
44 | 0 | size = 16; |
45 | 0 | break; |
46 | 0 | default: |
47 | 0 | ws_warning("Unrecognized DPIB option code %u", option_code); |
48 | 0 | } |
49 | 0 | return size; |
50 | 0 | } |
51 | | |
52 | | static bool |
53 | | put_dpib_option(wtap_block_t block _U_, unsigned option_code, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data) |
54 | 0 | { |
55 | 0 | struct pcapng_option_header option_hdr; |
56 | 0 | size_t size = 0; |
57 | 0 | size_t pad = 0; |
58 | 0 | uint8_t **opt_ptrp = (uint8_t **)user_data; |
59 | 0 | const void *uuid_bytes; |
60 | |
|
61 | 0 | switch (option_code) { |
62 | 0 | case OPT_DPIB_NAME: |
63 | 0 | size = strlen(optval->stringval); |
64 | 0 | if (size > 65535) { |
65 | | /* Too big to fit */ |
66 | 0 | return true; |
67 | 0 | } |
68 | 0 | if (size == 0) { |
69 | | /* If the name is an empty string, it won't be accounted for |
70 | | * by `pcapng_compute_options_size`. We have two alternatives |
71 | | * available if we want to avoid creating a corrupted file: |
72 | | * 1. Skip writing the empty string; or |
73 | | * 2. Don't use `pcapng_compute_options_size`; implement |
74 | | * a similar function that will account for the size |
75 | | * of an option header while calculating the options size. |
76 | | * Here, we are opting for the first alternative: skip |
77 | | * writing the empty option. This creates a file that is |
78 | | * readable by Darwin tcpdump. |
79 | | */ |
80 | 0 | return true; |
81 | 0 | } |
82 | 0 | option_hdr.type = (uint16_t)option_code; |
83 | 0 | option_hdr.value_length = (uint16_t)size; |
84 | 0 | memcpy(*opt_ptrp, &option_hdr, 4); |
85 | 0 | *opt_ptrp += 4; |
86 | 0 | memcpy(*opt_ptrp, optval->stringval, size); |
87 | 0 | *opt_ptrp += size; |
88 | | /* write padding (if any) */ |
89 | 0 | if ((pad = WS_PADDING_TO_4(size)) != 0) { |
90 | 0 | memset(*opt_ptrp, 0, pad); |
91 | 0 | *opt_ptrp += pad; |
92 | 0 | } |
93 | |
|
94 | 0 | break; |
95 | 0 | case OPT_DPIB_UUID: |
96 | 0 | uuid_bytes = g_bytes_get_data(optval->byteval, &size); |
97 | 0 | option_hdr.type = (uint16_t)option_code; |
98 | 0 | option_hdr.value_length = (uint16_t)size; |
99 | 0 | memcpy(*opt_ptrp, &option_hdr, 4); |
100 | 0 | *opt_ptrp += 4; |
101 | 0 | memcpy(*opt_ptrp, uuid_bytes, size); |
102 | 0 | *opt_ptrp += size; |
103 | 0 | break; |
104 | 0 | default: |
105 | 0 | break; |
106 | 0 | } |
107 | 0 | return true; |
108 | 0 | } |
109 | | |
110 | | bool |
111 | | pcapng_write_legacy_darwin_process_event_block(wtap_dumper *wdh, wtap_block_t sdata, int *err) |
112 | 0 | { |
113 | 0 | pcapng_block_header_t bh; |
114 | 0 | wtapng_ft_specific_mandatory_t *dpib_mand; |
115 | 0 | uint32_t options_size; |
116 | 0 | uint8_t *block_data; |
117 | 0 | uint8_t *opt_ptr; |
118 | 0 | uint32_t block_off; |
119 | | |
120 | | /* Note: the process id is represented by the `record_type` field |
121 | | * of the generic type `wtap_ft_specific_mandatory_t` |
122 | | */ |
123 | 0 | dpib_mand = (wtapng_ft_specific_mandatory_t*)wtap_block_get_mandatory_data(sdata); |
124 | |
|
125 | 0 | if (!dpib_mand) { |
126 | 0 | return true; |
127 | 0 | } |
128 | | |
129 | | /* pcapng_compute_options_size takes care of the 4 bytes for the end-of-options. */ |
130 | 0 | options_size = pcapng_compute_options_size(sdata, compute_dpib_option_size); |
131 | | |
132 | |
|
133 | 0 | bh.block_type = BLOCK_TYPE_LEGACY_DPIB; |
134 | 0 | bh.block_total_length = sizeof(bh) + sizeof(dpib_mand->record_type) + options_size + sizeof(bh.block_total_length); |
135 | | |
136 | | /* Allocate the block data */ |
137 | 0 | block_data = (uint8_t *)g_malloc0(bh.block_total_length); |
138 | | |
139 | | /* Copy the block header */ |
140 | 0 | memcpy(block_data, &bh, sizeof(bh)); |
141 | 0 | block_off = sizeof(bh); |
142 | | |
143 | | /* Copy the process id */ |
144 | 0 | memcpy(block_data + block_off, &dpib_mand->record_type, 4); |
145 | 0 | block_off += 4; |
146 | | |
147 | | /* Populate the options */ |
148 | 0 | opt_ptr = block_data + block_off; |
149 | 0 | wtap_block_foreach_option(sdata, put_dpib_option, &opt_ptr); |
150 | 0 | block_off += options_size; |
151 | | |
152 | | /* Copy the block trailer */ |
153 | 0 | memcpy(block_data + block_off, &bh.block_total_length, sizeof(bh.block_total_length)); |
154 | |
|
155 | 0 | if (!wtap_dump_file_write(wdh, block_data, bh.block_total_length, err)) { |
156 | 0 | g_free(block_data); |
157 | 0 | return false; |
158 | 0 | } |
159 | | |
160 | 0 | return true; |
161 | 0 | } |
162 | | |
163 | | static bool |
164 | | pcapng_write_darwin_legacy_uint32_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) |
165 | 0 | { |
166 | 0 | struct pcapng_option_header option_hdr; |
167 | |
|
168 | 0 | option_hdr.type = (uint16_t)option_id; |
169 | 0 | option_hdr.value_length = (uint16_t)4; |
170 | |
|
171 | 0 | ws_noisy("%s: type: %hu len: %hu value: %u", __func__, |
172 | 0 | option_hdr.type, option_hdr.value_length, optval->uint32val); |
173 | |
|
174 | 0 | if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) |
175 | 0 | return false; |
176 | | |
177 | 0 | if (!wtap_dump_file_write(wdh, &optval->uint32val, 4, err)) |
178 | 0 | return false; |
179 | | |
180 | 0 | return true; |
181 | 0 | } |
182 | | |
183 | | static bool |
184 | | pcapng_write_darwin_legacy_uint16_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) |
185 | 0 | { |
186 | 0 | struct pcapng_option_header option_hdr; |
187 | 0 | uint16_t option_val; |
188 | |
|
189 | 0 | option_val = (uint16_t)optval->uint32val; |
190 | 0 | option_hdr.type = (uint16_t)option_id; |
191 | 0 | option_hdr.value_length = (uint16_t)2; |
192 | | |
193 | |
|
194 | 0 | ws_noisy("%s: type: %hu len: %hu value: %u", __func__, |
195 | 0 | option_hdr.type, option_hdr.value_length, optval->uint32val); |
196 | |
|
197 | 0 | if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) |
198 | 0 | return false; |
199 | | |
200 | 0 | if (!wtap_dump_file_write(wdh, &option_val, 2, err)) |
201 | 0 | return false; |
202 | | |
203 | 0 | return pcapng_write_padding(wdh, 2, err); |
204 | 0 | } |
205 | | |
206 | | static bool |
207 | | pcapng_write_darwin_legacy_string_option(wtap_dumper *wdh, unsigned option_id, wtap_optval_t *optval, int *err) |
208 | 0 | { |
209 | 0 | struct pcapng_option_header option_hdr; |
210 | 0 | size_t size = strlen(optval->stringval); |
211 | |
|
212 | 0 | if (size == 0) |
213 | 0 | return true; |
214 | | |
215 | 0 | if (size > 65535) { |
216 | | /* |
217 | | * Too big to fit in the option. |
218 | | * Don't write anything. |
219 | | * |
220 | | * XXX - truncate it? Report an error? |
221 | | */ |
222 | 0 | return true; |
223 | 0 | } |
224 | | |
225 | | /* write option header */ |
226 | | /* String options don't consider pad bytes part of the length */ |
227 | 0 | option_hdr.type = (uint16_t)option_id; |
228 | 0 | option_hdr.value_length = (uint16_t)size; |
229 | | |
230 | |
|
231 | 0 | ws_noisy("%s: type: %hu len: %hu value: %s ", __func__, |
232 | 0 | option_hdr.type, option_hdr.value_length, optval->stringval); |
233 | |
|
234 | 0 | if (!wtap_dump_file_write(wdh, &option_hdr, 4, err)) |
235 | 0 | return false; |
236 | | |
237 | 0 | if (!wtap_dump_file_write(wdh, optval->stringval, size, err)) |
238 | 0 | return false; |
239 | | |
240 | | /* write padding (if any) */ |
241 | 0 | return pcapng_write_padding(wdh, WS_PADDING_TO_4(size), err); |
242 | 0 | } |
243 | | |
244 | | |
245 | | uint32_t |
246 | | pcapng_compute_epb_legacy_darwin_size(unsigned option_id, wtap_optval_t *optval) |
247 | 0 | { |
248 | 0 | switch (option_id) { |
249 | | /* 32-bit options */ |
250 | 0 | case OPT_PKT_DARWIN_PIB_ID: |
251 | 0 | case OPT_PKT_DARWIN_EFFECTIVE_PIB_ID: |
252 | 0 | case OPT_PKT_DARWIN_SVC_CODE: |
253 | 0 | case OPT_PKT_DARWIN_MD_FLAGS: |
254 | 0 | case OPT_PKT_DARWIN_FLOW_ID: |
255 | 0 | case OPT_PKT_DARWIN_DROP_REASON: |
256 | 0 | case OPT_PKT_DARWIN_COMP_GENCNT: |
257 | 0 | return 4; |
258 | 0 | break; |
259 | | /* 16-bit options (independent of DPIBs) */ |
260 | 0 | case OPT_PKT_DARWIN_DROP_LINE: |
261 | 0 | case OPT_PKT_DARWIN_TRACE_TAG: |
262 | 0 | return 2; |
263 | 0 | break; |
264 | | /* String options */ |
265 | 0 | case OPT_PKT_DARWIN_DROP_FUNC: |
266 | 0 | { |
267 | | /* 65535 is too large to be written */ |
268 | 0 | uint32_t size = (uint32_t)strlen(optval->stringval); |
269 | 0 | return size <= 65535 ? size : 0; |
270 | 0 | break; |
271 | 0 | } |
272 | 0 | default: |
273 | 0 | break; |
274 | 0 | } |
275 | | |
276 | 0 | return 0; |
277 | 0 | } |
278 | | |
279 | | |
280 | | bool |
281 | | pcapng_write_epb_legacy_darwin_option(wtap_dumper *wdh, wtap_block_t sdata _U_, |
282 | | unsigned option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, int *err, char **err_info _U_) |
283 | 0 | { |
284 | 0 | switch (option_id) { |
285 | | /* 32-bit options that refer to the DPIBs */ |
286 | 0 | case OPT_PKT_DARWIN_PIB_ID: |
287 | 0 | case OPT_PKT_DARWIN_EFFECTIVE_PIB_ID: { |
288 | | /* The referenced Darwin PIB id should be present in the wdh->dpibs */ |
289 | 0 | if ((wdh->dpibs_growing == NULL) || (wdh->dpibs_growing->len <= (uint32_t)optval->int32val)) { |
290 | | /* The `optval` is unlikely to be a Darwin PIB id reference, ignore. */ |
291 | 0 | ws_warning("Attempting to write a DPIB option while no DPIBs are present. Writing anyway."); |
292 | | // return true; |
293 | 0 | } |
294 | 0 | if (!pcapng_write_darwin_legacy_uint32_option(wdh, option_id, optval, err)) { |
295 | | /* Write error */ |
296 | 0 | return false; |
297 | 0 | } |
298 | 0 | break; |
299 | 0 | } |
300 | | /* 32-bit options that are independent of DPIBs */ |
301 | 0 | case OPT_PKT_DARWIN_SVC_CODE: |
302 | 0 | case OPT_PKT_DARWIN_MD_FLAGS: |
303 | 0 | case OPT_PKT_DARWIN_FLOW_ID: |
304 | 0 | case OPT_PKT_DARWIN_DROP_REASON: |
305 | 0 | case OPT_PKT_DARWIN_COMP_GENCNT: { |
306 | 0 | if (!pcapng_write_darwin_legacy_uint32_option(wdh, option_id, optval, err)) { |
307 | | /* Write error */ |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | break; |
311 | 0 | } |
312 | | /* 16-bit options (independent of DPIBs) */ |
313 | 0 | case OPT_PKT_DARWIN_DROP_LINE: |
314 | 0 | case OPT_PKT_DARWIN_TRACE_TAG: { |
315 | 0 | if (!pcapng_write_darwin_legacy_uint16_option(wdh, option_id, optval, err)) { |
316 | | /* Write error */ |
317 | 0 | return false; |
318 | 0 | } |
319 | 0 | break; |
320 | 0 | } |
321 | | /* String options */ |
322 | 0 | case OPT_PKT_DARWIN_DROP_FUNC: { |
323 | 0 | if (!pcapng_write_darwin_legacy_string_option(wdh, option_id, optval, err)) { |
324 | | /* Write error */ |
325 | 0 | return false; |
326 | 0 | } |
327 | 0 | break; |
328 | 0 | } |
329 | 0 | default: |
330 | 0 | break; |
331 | 0 | } |
332 | | |
333 | | /* We return true for unrecognized options */ |
334 | 0 | return true; |
335 | 0 | } |
336 | | |
337 | | static bool |
338 | | pcapng_process_apple_legacy_block_option(wtapng_block_t *wblock, section_info_t *section_info _U_, |
339 | | uint16_t option_code, uint16_t option_length, const uint8_t *option_content, |
340 | | int *err, char **err_info) |
341 | 0 | { |
342 | | /* Handle the DPIB option content. */ |
343 | 0 | switch (option_code) { |
344 | 0 | case(OPT_DPIB_NAME): /* dpip_process_name */ |
345 | 0 | pcapng_process_string_option(wblock, option_code, option_length, option_content); |
346 | 0 | break; |
347 | 0 | case(OPT_DPIB_UUID): /* dpib_process_uuid */ |
348 | 0 | pcapng_process_bytes_option(wblock, option_code, option_length, option_content); |
349 | 0 | break; |
350 | 0 | default: |
351 | 0 | *err = WTAP_ERR_BAD_FILE; |
352 | 0 | *err_info = ws_strdup_printf("pcapng: unrecognized option %u in legacy DPIB block", option_code); |
353 | 0 | return false; |
354 | 0 | } |
355 | | |
356 | 0 | return true; |
357 | 0 | } |
358 | | |
359 | | static bool |
360 | | pcapng_read_darwin_legacy_block(wtap* wth, FILE_T fh, uint32_t block_size _U_, |
361 | | uint32_t block_content_size, |
362 | | section_info_t* section_info, |
363 | | wtapng_block_t* wblock, |
364 | | int* err, char** err_info) |
365 | 0 | { |
366 | 0 | unsigned opt_cont_buf_len; |
367 | 0 | pcapng_legacy_darwin_process_info_block_t process_info; |
368 | 0 | wtapng_ft_specific_mandatory_t *dpib_mand; |
369 | 0 | wtap_block_t dpib; |
370 | | |
371 | | /* Is this block long enough to be a DPIB? */ |
372 | 0 | if (block_content_size < sizeof(uint32_t)) { |
373 | | /* Too short */ |
374 | 0 | *err = WTAP_ERR_BAD_FILE; |
375 | 0 | *err_info = ws_strdup_printf("pcapng: total block length %u of an DPIB is too small (< %u)", |
376 | 0 | block_content_size, MIN_DPIB_SIZE); |
377 | 0 | return false; |
378 | 0 | } |
379 | | |
380 | | /* Read the fixed part of the DPIB */ |
381 | 0 | if (!wtap_read_bytes(fh, &process_info, sizeof process_info, err, err_info)) { |
382 | 0 | ws_debug("failed to read packet data"); |
383 | 0 | *err = WTAP_ERR_BAD_FILE; |
384 | 0 | *err_info = ws_strdup_printf("pcapng: can not read %zu bytes for process info", |
385 | 0 | sizeof(process_info)); |
386 | 0 | return false; |
387 | 0 | } |
388 | | |
389 | | /* Initialize the wblock->block to point to a new DPIB block */ |
390 | 0 | dpib_mand = g_malloc0(sizeof(wtapng_ft_specific_mandatory_t)); |
391 | 0 | dpib = wtap_block_create( WTAP_BLOCK_FT_SPECIFIC_INFORMATION); |
392 | 0 | dpib->mandatory_data = dpib_mand; |
393 | 0 | wblock->block = dpib; |
394 | | /* Add the block to the `wtap->dpibs` array, and increment the block's refcount, |
395 | | * to reflect that the block is now referenced by two entities. |
396 | | */ |
397 | 0 | wtap_add_dpib(wth, dpib); |
398 | 0 | wtap_block_ref(wblock->block); |
399 | | |
400 | | /* We don't return these to the caller in pcapng_read(). */ |
401 | 0 | wblock->internal = true; |
402 | | |
403 | | /* Populate the mandatory values for the block. */ |
404 | 0 | if (section_info->byte_swapped) { |
405 | 0 | dpib_mand->record_type = GUINT32_SWAP_LE_BE(process_info.process_id); |
406 | 0 | } else { |
407 | 0 | dpib_mand->record_type = process_info.process_id; |
408 | 0 | } |
409 | 0 | ws_debug("process_id %u", dpib_mand->record_type); |
410 | | |
411 | | /* Process options. Note: encountering an unknown option should not discard the block. */ |
412 | 0 | opt_cont_buf_len = block_content_size - MIN_DPIB_SIZE; /* fixed part */ |
413 | 0 | if (!pcapng_process_options(fh, wblock, section_info, opt_cont_buf_len, |
414 | 0 | pcapng_process_apple_legacy_block_option, |
415 | 0 | OPT_SECTION_BYTE_ORDER, err, err_info)) { |
416 | |
|
417 | 0 | *err = 0; |
418 | 0 | g_free(*err_info); |
419 | 0 | *err_info = NULL; |
420 | 0 | } |
421 | |
|
422 | 0 | return true; |
423 | 0 | } |
424 | | |
425 | | static bool |
426 | | pcapng_parse_darwin_legacy_uint32(wtap_block_t block, unsigned option_code, |
427 | | unsigned option_length, const uint8_t* option_content, |
428 | | int* err, char** err_info) |
429 | 0 | { |
430 | 0 | uint32_t uint32; |
431 | |
|
432 | 0 | if (option_length != 4) { |
433 | 0 | *err = WTAP_ERR_BAD_FILE; |
434 | 0 | *err_info = ws_strdup_printf("pcapng: Darwin option 0x%hx length expected %u, actual %u", |
435 | 0 | (uint16_t)option_code, 4, option_length); |
436 | 0 | return false; |
437 | 0 | } |
438 | | |
439 | 0 | memcpy(&uint32, option_content, sizeof(uint32_t)); |
440 | 0 | wtap_block_add_uint32_option(block, option_code, uint32); |
441 | |
|
442 | 0 | ws_noisy("Processed integer option 0x%08x (len: %u) == %d", option_code, option_length, *(int32_t*)option_content); |
443 | 0 | return true; |
444 | 0 | } |
445 | | |
446 | | static bool |
447 | | pcapng_parse_darwin_legacy_uint16(wtap_block_t block, unsigned option_code, |
448 | | unsigned option_length, const uint8_t* option_content, |
449 | | int* err, char** err_info) |
450 | 0 | { |
451 | 0 | uint32_t uint32; |
452 | 0 | if (option_length != 2) { |
453 | 0 | *err = WTAP_ERR_BAD_FILE; |
454 | 0 | *err_info = ws_strdup_printf("pcapng: Darwin option 0x%hx length expected %u, actual %u", |
455 | 0 | (uint16_t)option_code, 2, option_length); |
456 | 0 | return false; |
457 | 0 | } |
458 | | |
459 | | /* NOTE: Internally, the 16-bit options are stored as 32-bit. |
460 | | * Because of that, we are using uint32_t as the option length, |
461 | | * and not the real option length. |
462 | | */ |
463 | 0 | memcpy(&uint32, option_content, sizeof(uint32_t)); |
464 | 0 | wtap_block_add_uint32_option(block, option_code, uint32); |
465 | |
|
466 | 0 | ws_noisy("Processed integer option 0x%08x (len: %u) == %d", option_code, option_length, *(int32_t*)option_content); |
467 | 0 | return true; |
468 | 0 | } |
469 | | |
470 | | static bool |
471 | | pcapng_parse_darwin_legacy_dpib_id(wtap_block_t block, bool byte_swapped _U_, |
472 | | unsigned option_length, const uint8_t* option_content, |
473 | | int* err, char** err_info) |
474 | 0 | { |
475 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_PIB_ID, option_length, option_content, err, err_info); |
476 | 0 | } |
477 | | |
478 | | static bool |
479 | | pcapng_parse_darwin_legacy_svc_code(wtap_block_t block, bool byte_swapped _U_, |
480 | | unsigned option_length, const uint8_t* option_content, |
481 | | int* err, char** err_info) |
482 | 0 | { |
483 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_SVC_CODE, option_length, option_content, err, err_info); |
484 | 0 | } |
485 | | |
486 | | static bool |
487 | | pcapng_parse_darwin_legacy_effective_dpib_id(wtap_block_t block, bool byte_swapped _U_, |
488 | | unsigned option_length, const uint8_t* option_content, |
489 | | int* err, char** err_info) |
490 | 0 | { |
491 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_EFFECTIVE_PIB_ID, option_length, option_content, err, err_info); |
492 | 0 | } |
493 | | |
494 | | static bool |
495 | | pcapng_parse_darwin_legacy_md_flags(wtap_block_t block, bool byte_swapped _U_, |
496 | | unsigned option_length, const uint8_t* option_content, |
497 | | int* err, char** err_info) |
498 | 0 | { |
499 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_MD_FLAGS, option_length, option_content, err, err_info); |
500 | 0 | } |
501 | | |
502 | | static bool |
503 | | pcapng_parse_darwin_legacy_flow_id(wtap_block_t block, bool byte_swapped _U_, |
504 | | unsigned option_length, const uint8_t* option_content, |
505 | | int* err, char** err_info) |
506 | 0 | { |
507 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_FLOW_ID, option_length, option_content, err, err_info); |
508 | 0 | } |
509 | | |
510 | | static bool |
511 | | pcapng_parse_darwin_legacy_drop_reason(wtap_block_t block, bool byte_swapped _U_, |
512 | | unsigned option_length, const uint8_t* option_content, |
513 | | int* err, char** err_info) |
514 | 0 | { |
515 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_DROP_REASON, option_length, option_content, err, err_info); |
516 | 0 | } |
517 | | |
518 | | static bool |
519 | | pcapng_parse_darwin_legacy_comp_gencnt(wtap_block_t block, bool byte_swapped _U_, |
520 | | unsigned option_length, const uint8_t* option_content, |
521 | | int* err, char** err_info) |
522 | 0 | { |
523 | 0 | return pcapng_parse_darwin_legacy_uint32(block, OPT_PKT_DARWIN_COMP_GENCNT, option_length, option_content, err, err_info); |
524 | 0 | } |
525 | | |
526 | | static bool |
527 | | pcapng_parse_darwin_legacy_trace_tag(wtap_block_t block, bool byte_swapped _U_, |
528 | | unsigned option_length, const uint8_t* option_content, |
529 | | int* err, char** err_info) |
530 | 0 | { |
531 | 0 | return pcapng_parse_darwin_legacy_uint16(block, OPT_PKT_DARWIN_TRACE_TAG, option_length, option_content, err, err_info); |
532 | 0 | } |
533 | | |
534 | | static bool |
535 | | pcapng_parse_darwin_legacy_drop_line(wtap_block_t block, bool byte_swapped _U_, |
536 | | unsigned option_length, const uint8_t* option_content, |
537 | | int* err, char** err_info) |
538 | 0 | { |
539 | 0 | return pcapng_parse_darwin_legacy_uint16(block, OPT_PKT_DARWIN_DROP_LINE, option_length, option_content, err, err_info); |
540 | 0 | } |
541 | | |
542 | | static bool |
543 | | pcapng_parse_darwin_legacy_drop_func(wtap_block_t block, bool byte_swapped _U_, |
544 | | unsigned option_length, const uint8_t* option_content, |
545 | | int* err _U_, char** err_info _U_) |
546 | 0 | { |
547 | 0 | wtap_opttype_return_val ret = wtap_block_add_string_option(block, OPT_PKT_DARWIN_DROP_FUNC, (const char*)option_content, option_length); |
548 | 0 | if (ret != WTAP_OPTTYPE_SUCCESS) |
549 | 0 | return false; |
550 | | |
551 | 0 | ws_noisy("Processed string option 0x%08x (len: %u)", OPT_PKT_DARWIN_DROP_FUNC, option_length); |
552 | 0 | return true; |
553 | 0 | } |
554 | | |
555 | | static const wtap_opttype_t dpib_name = { |
556 | | "name", |
557 | | "Darwin Process Name", |
558 | | WTAP_OPTTYPE_STRING, |
559 | | 0 |
560 | | }; |
561 | | static const wtap_opttype_t dpib_uuid = { |
562 | | "name", |
563 | | "Darwin Process UUID", |
564 | | WTAP_OPTTYPE_BYTES, |
565 | | 0 |
566 | | }; |
567 | | |
568 | | void register_darwin(void) |
569 | 15 | { |
570 | 15 | static pcapng_block_type_information_t LEGACY = { BLOCK_TYPE_LEGACY_DPIB, pcapng_read_darwin_legacy_block, NULL, NULL, true, NULL }; |
571 | 15 | static wtap_block_t dpib = NULL; |
572 | | |
573 | 15 | if (dpib == NULL) { |
574 | 15 | wtap_blocktype_t *blocktype; |
575 | 15 | dpib = wtap_block_create( WTAP_BLOCK_FT_SPECIFIC_INFORMATION); |
576 | 15 | blocktype = dpib->info; |
577 | 15 | g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_DPIB_NAME), |
578 | 15 | (void *)&dpib_name); |
579 | 15 | g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_DPIB_UUID), |
580 | 15 | (void *)&dpib_uuid); |
581 | 15 | } |
582 | | |
583 | 15 | register_pcapng_block_type_information(&LEGACY); |
584 | | |
585 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_PIB_ID, pcapng_parse_darwin_legacy_dpib_id, NULL, NULL); |
586 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_SVC_CODE, pcapng_parse_darwin_legacy_svc_code, NULL, NULL); |
587 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_EFFECTIVE_PIB_ID, pcapng_parse_darwin_legacy_effective_dpib_id, NULL, NULL); |
588 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_MD_FLAGS, pcapng_parse_darwin_legacy_md_flags, NULL, NULL); |
589 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_FLOW_ID, pcapng_parse_darwin_legacy_flow_id, NULL, NULL); |
590 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_TRACE_TAG, pcapng_parse_darwin_legacy_trace_tag, NULL, NULL); |
591 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_DROP_REASON, pcapng_parse_darwin_legacy_drop_reason, NULL, NULL); |
592 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_DROP_LINE, pcapng_parse_darwin_legacy_drop_line, NULL, NULL); |
593 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_COMP_GENCNT, pcapng_parse_darwin_legacy_comp_gencnt, NULL, NULL); |
594 | 15 | register_pcapng_option_handler(BLOCK_TYPE_EPB, OPT_PKT_DARWIN_DROP_FUNC, pcapng_parse_darwin_legacy_drop_func, NULL, NULL); |
595 | 15 | } |