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
16 #include <wsutil/file_util.h>
18 #include "sync_pipe.h"
20 /****************************************************************************************************************/
21 /* sync_pipe handling */
24 /* write a single message header to the recipient pipe */
26 pipe_write_header(int pipe_fd, char indicator, int length)
28 guchar header[1+3]; /* indicator + 3-byte len */
31 g_assert(length <= SP_MAX_MSG_LEN);
33 /* write header (indicator + 3-byte len) */
34 header[0] = indicator;
35 header[1] = (length >> 16) & 0xFF;
36 header[2] = (length >> 8) & 0xFF;
37 header[3] = (length >> 0) & 0xFF;
40 return ws_write(pipe_fd, header, sizeof header);
44 /* write a message to the recipient pipe in the standard format
45 (3 digit message length (excluding length and indicator field),
46 1 byte message indicator and the rest is the message).
47 If msg is NULL, the message has only a length and indicator. */
49 pipe_write_block(int pipe_fd, char indicator, const char *msg)
54 /*g_warning("write %d enter", pipe_fd);*/
57 len = (int) strlen(msg) + 1; /* including the terminating '\0'! */
62 /* write header (indicator + 3-byte len) */
63 ret = pipe_write_header(pipe_fd, indicator, len);
68 /* write value (if we have one) */
70 /*g_warning("write %d indicator: %c value len: %u msg: %s", pipe_fd, indicator, len, msg);*/
71 ret = ws_write(pipe_fd, msg, len);
76 /*g_warning("write %d indicator: %c no value", pipe_fd, indicator);*/
79 /*g_warning("write %d leave", pipe_fd);*/
84 sync_pipe_errmsg_to_parent(int pipe_fd, const char *error_msg,
85 const char *secondary_error_msg)
88 /* first write a "master header" with the length of the two messages plus their "slave headers" */
89 pipe_write_header(pipe_fd, SP_ERROR_MSG, (int) (strlen(error_msg) + 1 + 4 + strlen(secondary_error_msg) + 1 + 4));
90 pipe_write_block(pipe_fd, SP_ERROR_MSG, error_msg);
91 pipe_write_block(pipe_fd, SP_ERROR_MSG, secondary_error_msg);
95 * Editor modelines - http://www.wireshark.org/tools/modelines.html
100 * indent-tabs-mode: nil
103 * vi: set shiftwidth=4 tabstop=8 expandtab:
104 * :indentSize=4:tabSize=8:noTabs=true: