Wed Mar 18 01:28:25 2009 UTC ()
Format the address/offset of hexdump in hex, not decimal.

Addresses my PR bin/41035


(pgoyette)
diff -r1.126 -r1.127 src/sbin/sysctl/sysctl.c

cvs diff -r1.126 -r1.127 src/sbin/sysctl/sysctl.c (expand / switch to unified diff)

--- src/sbin/sysctl/sysctl.c 2009/03/05 15:35:59 1.126
+++ src/sbin/sysctl/sysctl.c 2009/03/18 01:28:25 1.127
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysctl.c,v 1.126 2009/03/05 15:35:59 njoly Exp $ */ 1/* $NetBSD: sysctl.c,v 1.127 2009/03/18 01:28:25 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Brown. 8 * by Andrew Brown.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -58,27 +58,27 @@ @@ -58,27 +58,27 @@
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62#ifndef lint 62#ifndef lint
63__COPYRIGHT("@(#) Copyright (c) 1993\ 63__COPYRIGHT("@(#) Copyright (c) 1993\
64 The Regents of the University of California. All rights reserved."); 64 The Regents of the University of California. All rights reserved.");
65#endif /* not lint */ 65#endif /* not lint */
66 66
67#ifndef lint 67#ifndef lint
68#if 0 68#if 0
69static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93"; 69static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
70#else 70#else
71__RCSID("$NetBSD: sysctl.c,v 1.126 2009/03/05 15:35:59 njoly Exp $"); 71__RCSID("$NetBSD: sysctl.c,v 1.127 2009/03/18 01:28:25 pgoyette Exp $");
72#endif 72#endif
73#endif /* not lint */ 73#endif /* not lint */
74 74
75#include <sys/types.h> 75#include <sys/types.h>
76#include <sys/param.h> 76#include <sys/param.h>
77#include <sys/sysctl.h> 77#include <sys/sysctl.h>
78#include <sys/mount.h> 78#include <sys/mount.h>
79#include <sys/resource.h> 79#include <sys/resource.h>
80#include <sys/stat.h> 80#include <sys/stat.h>
81#include <sys/sched.h> 81#include <sys/sched.h>
82#include <sys/socket.h> 82#include <sys/socket.h>
83#include <netinet/in.h> 83#include <netinet/in.h>
84#include <netinet/ip_var.h> 84#include <netinet/ip_var.h>
@@ -1917,27 +1917,27 @@ static void @@ -1917,27 +1917,27 @@ static void
1917hex_dump(const unsigned char *buf, size_t len) 1917hex_dump(const unsigned char *buf, size_t len)
1918{ 1918{
1919 int i, j; 1919 int i, j;
1920 char line[80], tmp[12]; 1920 char line[80], tmp[12];
1921 1921
1922 memset(line, ' ', sizeof(line)); 1922 memset(line, ' ', sizeof(line));
1923 for (i = 0, j = 15; i < len; i++) { 1923 for (i = 0, j = 15; i < len; i++) {
1924 j = i % 16; 1924 j = i % 16;
1925 /* reset line */ 1925 /* reset line */
1926 if (j == 0) { 1926 if (j == 0) {
1927 line[58] = '|'; 1927 line[58] = '|';
1928 line[77] = '|'; 1928 line[77] = '|';
1929 line[78] = 0; 1929 line[78] = 0;
1930 snprintf(tmp, sizeof(tmp), "%07d", i); 1930 snprintf(tmp, sizeof(tmp), "%07x", i);
1931 memcpy(&line[0], tmp, 7); 1931 memcpy(&line[0], tmp, 7);
1932 } 1932 }
1933 /* copy out hex version of byte */ 1933 /* copy out hex version of byte */
1934 snprintf(tmp, sizeof(tmp), "%02x", buf[i]); 1934 snprintf(tmp, sizeof(tmp), "%02x", buf[i]);
1935 memcpy(&line[9 + j * 3], tmp, 2); 1935 memcpy(&line[9 + j * 3], tmp, 2);
1936 /* copy out plain version of byte */ 1936 /* copy out plain version of byte */
1937 line[60 + j] = (isprint(buf[i])) ? buf[i] : '.'; 1937 line[60 + j] = (isprint(buf[i])) ? buf[i] : '.';
1938 /* print a full line and erase it */ 1938 /* print a full line and erase it */
1939 if (j == 15) { 1939 if (j == 15) {
1940 printf("%s\n", line); 1940 printf("%s\n", line);
1941 memset(line, ' ', sizeof(line)); 1941 memset(line, ' ', sizeof(line));
1942 } 1942 }
1943 } 1943 }