You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include <arpa/inet.h>
#include <assert.h>
#include <contrib/ccan/asprintf/asprintf.h>
#include <editline/readline.h>
uint32_t len;
if (!fread(&len, sizeof(len), 1, g_tty))
return NULL;
+ len = ntohl(len);
char *msg = malloc(1 + (size_t) len);
if (!msg)
return NULL;
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
*
* - This is just basic read-eval-print; libedit is supported through krsec;
* - stream->data represents a bool determining binary output mode (used by kresc);
+ * - binary output: uint32_t length in network order, followed by that many bytes;
*/
static void tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
{
size_t len_s = strlen(message);
if (len_s > UINT32_MAX)
goto finish;
- uint32_t len = len_s;
- fwrite(&len, sizeof(len), 1, out);
- fwrite(message, len, 1, out);
+ uint32_t len_n = htonl(len_s);
+ fwrite(&len_n, sizeof(len_n), 1, out);
+ fwrite(message, len_s, 1, out);
goto finish;
}