lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 24 Oct 2008 18:41:45 -0700
From:	Joe Perches <joe@...ches.com>
To:	Johannes Berg <johannes@...solutions.net>
Cc:	"David S. Miller" <davem@...emloft.net>,
	netdev <netdev@...r.kernel.org>
Subject: Re: [PATCH] add %pM printf format specifier

On Sat, 2008-10-25 at 01:46 +0200, Johannes Berg wrote:
> This adds a new printf format specifier for the kernel, %pM,
> to be used to print out MAC addresses. This has advantages
> over the current print_mac scheme:
>  * no need for DECLARE_MAC_BUF
>  * can be used safely in statements that might be compiled
>    out without the print_mac call staying.

Good things.

> --- everything.orig/lib/vsprintf.c	2008-10-25 01:21:54.000000000 +0200
> +++ everything/lib/vsprintf.c	2008-10-25 01:24:15.000000000 +0200
> @@ -581,6 +581,22 @@ static char *resource_string(char *buf, 
>  	return string(buf, end, sym, field_width, precision, flags);
>  }
>  
> +static char *mac_address(char *buf, char *end, u8 *addr, int field_width, int precision, int flags)
> +{
> +	/* room for 6 * two hex digits, 5 colons and trailing zero */
> +	char mac[18];
> +	char *p = mac, *pend = mac + sizeof(mac);
> +	int i;
> +
> +	for (i=0; i < 6; i++) {
> +		p = number(p, pend, addr[i], 16, 2, -1, SMALL | ZEROPAD);
> +		*p++ = ':';
> +	}

For consistency, shouldn't the function name be mac_address_string?

I (and perhaps Harvey H) would be happier with:

	char mac[18];
	char *p = mac;
	int i;

	for (i = 0; i < 5; i++) {
		p = pack_hex_byte(p, addr[i]);
		*p++ = ':';
	}
	p = pack_hex_byte(p, addr[5]);
	*p = '\0';

Smaller, faster, etc...

Also, as the number of %p(foo) types increases, perhaps
something like sparse could validate the printf argument
types?

cheers, Joe

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ