util: Improved qemu_hexmap() to include an ascii dump of the buffer
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. Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Isaac Lozano <109lozanoi@gmail.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
		
							parent
							
								
									7acbff99c6
								
							
						
					
					
						commit
						a1555559ab
					
				
							
								
								
									
										30
									
								
								net/net.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								net/net.c
									
									
									
									
									
								
							@ -81,34 +81,6 @@ int default_net = 1;
 | 
				
			|||||||
/***********************************************************/
 | 
					/***********************************************************/
 | 
				
			||||||
/* network device redirectors */
 | 
					/* 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<size;i+=16) {
 | 
					 | 
				
			||||||
        len = size - i;
 | 
					 | 
				
			||||||
        if (len > 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<len;j++) {
 | 
					 | 
				
			||||||
            c = buf[i+j];
 | 
					 | 
				
			||||||
            if (c < ' ' || c > '~')
 | 
					 | 
				
			||||||
                c = '.';
 | 
					 | 
				
			||||||
            fprintf(f, "%c", c);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        fprintf(f, "\n");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 | 
					static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    const char *p, *p1;
 | 
					    const char *p, *p1;
 | 
				
			||||||
@ -664,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifdef DEBUG_NET
 | 
					#ifdef DEBUG_NET
 | 
				
			||||||
    printf("qemu_send_packet_async:\n");
 | 
					    printf("qemu_send_packet_async:\n");
 | 
				
			||||||
    hex_dump(stdout, buf, size);
 | 
					    qemu_hexdump((const char *)buf, stdout, "net", size);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (sender->link_down || !sender->peer) {
 | 
					    if (sender->link_down || !sender->peer) {
 | 
				
			||||||
 | 
				
			|||||||
@ -18,21 +18,32 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
 | 
					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++) {
 | 
					    for (b = 0; b < size; b += 16) {
 | 
				
			||||||
        if ((b % 16) == 0) {
 | 
					        len = size - b;
 | 
				
			||||||
            fprintf(fp, "%s: %04x:", prefix, b);
 | 
					        if (len > 16) {
 | 
				
			||||||
 | 
					            len = 16;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if ((b % 4) == 0) {
 | 
					        fprintf(fp, "%s: %04x:", prefix, b);
 | 
				
			||||||
            fprintf(fp, " ");
 | 
					        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]);
 | 
					        fprintf(fp, " ");
 | 
				
			||||||
        if ((b % 16) == 15) {
 | 
					        for (i = 0; i < len; i++) {
 | 
				
			||||||
            fprintf(fp, "\n");
 | 
					            c = buf[b + i];
 | 
				
			||||||
 | 
					            if (c < ' ' || c > '~') {
 | 
				
			||||||
 | 
					                c = '.';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            fprintf(fp, "%c", c);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if ((b % 16) != 0) {
 | 
					 | 
				
			||||||
        fprintf(fp, "\n");
 | 
					        fprintf(fp, "\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user