From patchwork Tue Mar 22 07:41:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Lozano <109lozanoi@gmail.com> X-Patchwork-Id: 8638661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BA53CC0553 for ; Tue, 22 Mar 2016 07:38:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E744201EC for ; Tue, 22 Mar 2016 07:38:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 55400200FF for ; Tue, 22 Mar 2016 07:38:54 +0000 (UTC) Received: from localhost ([::1]:34262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiGtx-0002bL-LI for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Mar 2016 03:38:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <109lozanoi@gmail.com>) id 1aiGtm-0002ax-JZ for qemu-devel@nongnu.org; Tue, 22 Mar 2016 03:38:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <109lozanoi@gmail.com>) id 1aiGtl-0000u9-K5 for qemu-devel@nongnu.org; Tue, 22 Mar 2016 03:38:42 -0400 Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]:33051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <109lozanoi@gmail.com>) id 1aiGtl-0000tt-C5 for qemu-devel@nongnu.org; Tue, 22 Mar 2016 03:38:41 -0400 Received: by mail-pf0-x22f.google.com with SMTP id 4so167724194pfd.0 for ; Tue, 22 Mar 2016 00:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=BGO5zIqg9wqKhEhGOyZO2MHh2UbVohBZKrkIaeC3lWY=; b=N1yZTAg5/YH+8KsHEKuVtBfwFvdWbDDWyB+jdVENS/vLvIpaXeJ6/xYwot8m4CNkhJ SjLnquxH50pNRgSIzaLiBS8c8b1rR/quxXk+QoWto5qqV8htRW0p5xLkhCZYrmLiyeK9 CtTfe/UGaPhR4Q1FkL77e9dZcuwCMYmzYMREi8H+CcZKq3h0W3HYC7acmlrKfW3wMY9G Jp/rrLQ4luy3LaMLjH+Jmys4sz/79vl0rw3s6jACXMi2NSpXzF+CMT3OZNLvhF0IOfLo 2vst1DoNVG2dC1ZndZO2zD1y1E1x6L1aEBqqwzjhiysM4wYjUxKh3JOmzJaJxkDMrwSL YA2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BGO5zIqg9wqKhEhGOyZO2MHh2UbVohBZKrkIaeC3lWY=; b=JSleY0mhSlZ/rIC2aVm93mrEkUaaThh7sJM3QQj+m3gIhIDRUoZ5K5EC5choxQgARg 4gh28SKqFSch9qoDDcUJX06EuPIllvYf6pjaTxpmuvfe2jpDQ3A9RX1BKcPSf+Rd/xxM c5KfXlM3W2J3/Q7UIKFnkkA8t0MPCRuF9PJ86H0OvLBgqmx4Yjb7Txv+j5BT79pmgiLK li3XmLpdja8Wz+pg+YVmhjfa0YGetulPpUC6p59YYOzP3PY+beR76BeJgfr+Yj6qg3Y/ MtHNYJiOHCIW2B0Ev6XB0Vm+Krmu4lebuk6325cetOC7pxoxYagpIYVBJ3gnZyVT2qop rFOA== X-Gm-Message-State: AD7BkJJGTqyeADkwmAN3xaAy4IJoSQ9813wxLOSNy4ZFwEYRUTNMxP3GH+sCchpWsvTrdA== X-Received: by 10.98.18.28 with SMTP id a28mr51877940pfj.145.1458632320171; Tue, 22 Mar 2016 00:38:40 -0700 (PDT) Received: from Phobos.attlocal.net ([2602:301:772d:a050::3ed]) by smtp.gmail.com with ESMTPSA id d19sm45730078pfj.92.2016.03.22.00.38.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 00:38:39 -0700 (PDT) From: Isaac Lozano <109lozanoi@gmail.com> To: qemu-devel@nongnu.org Date: Tue, 22 Mar 2016 00:41:37 -0700 Message-Id: <1458632497-27173-1-git-send-email-109lozanoi@gmail.com> X-Mailer: git-send-email 2.7.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::22f Cc: Isaac Lozano <109lozanoi@gmail.com> Subject: [Qemu-devel] [PATCH] util: Improved qemu_hexmap() to include an ascii dump of the buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_STARTS_WITH_NUMS,RCVD_IN_DNSWL_HI, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP qemu_hexdump() in util/hexdump.c has been changed to give also include a ascii dump of the buffer. Also, calls to hex_dump() in net/net.c have been replaced with calls to qemu_hexdump(). This takes care of two misc BiteSized Tasks. Signed-off-by: Isaac Lozano <109lozanoi@gmail.com> --- net/net.c | 31 +------------------------------ util/hexdump.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/net/net.c b/net/net.c index 1a78edf..8d51ffb 100644 --- a/net/net.c +++ b/net/net.c @@ -79,34 +79,6 @@ int default_net = 1; /***********************************************************/ /* network device redirectors */ -#if defined(DEBUG_NET) -static void hex_dump(FILE *f, const uint8_t *buf, int size) -{ - int len, i, j, c; - - for(i=0;i 16) - len = 16; - fprintf(f, "%08x ", i); - for(j=0;j<16;j++) { - if (j < len) - fprintf(f, " %02x", buf[i+j]); - else - fprintf(f, " "); - } - fprintf(f, " "); - for(j=0;j '~') - c = '.'; - fprintf(f, "%c", c); - } - fprintf(f, "\n"); - } -} -#endif - static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) { const char *p, *p1; @@ -661,8 +633,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender, int ret; #ifdef DEBUG_NET - printf("qemu_send_packet_async:\n"); - hex_dump(stdout, buf, size); + qemu_hexdump((const char*)buf, stdout, "qemu_send_packet_async", size); #endif if (sender->link_down || !sender->peer) { diff --git a/util/hexdump.c b/util/hexdump.c index 1d9c129..886e53c 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -18,21 +18,34 @@ void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size) { - unsigned int b; + unsigned int b, len, i, c; - for (b = 0; b < size; b++) { - if ((b % 16) == 0) { - fprintf(fp, "%s: %04x:", prefix, b); + for (b = 0; b < size; b += 16) { + len = size - b; + if (len > 16) { + len = 16; } - if ((b % 4) == 0) { - fprintf(fp, " "); + fprintf(fp, "%s: %04x:", prefix, b); + for (i = 0; i < 16; i++) { + if ((i % 4) == 0) { + fprintf(fp, " "); + } + if (i < len) { + fprintf(fp, " %02x", (unsigned char)buf[b + i]); + } + else + { + fprintf(fp, " "); + } } - fprintf(fp, " %02x", (unsigned char)buf[b]); - if ((b % 16) == 15) { - fprintf(fp, "\n"); + fprintf(fp, " "); + for (i = 0; i < len; i++) { + c = buf[b+i]; + if (c < ' ' || c > '~') { + c = '.'; + } + fprintf(fp, "%c", c); } - } - if ((b % 16) != 0) { fprintf(fp, "\n"); } }