[U-Boot] [PATCH 02/30] convert print_IPaddr() to %pI4

Mike Frysinger vapier at gentoo.org
Tue Feb 17 06:10:23 CET 2009


Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
CC: Ben Warren <biggerbadderben at gmail.com>
---
 common/cmd_bdinfo.c |   48 +++++++++++++++++++-----------------------------
 include/net.h       |    3 ---
 net/bootp.c         |   18 +++++-------------
 net/net.c           |   13 +------------
 net/nfs.c           |   10 ++++------
 net/tftp.c          |   10 ++++------
 6 files changed, 33 insertions(+), 69 deletions(-)

diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index b2d6f84..6af5749 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -26,7 +26,6 @@
  */
 #include <common.h>
 #include <command.h>
-#include <net.h>		/* for print_IPaddr */
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -134,8 +133,8 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #ifdef CONFIG_HERMES
 	print_str ("ethspeed",	    strmhz(buf, bd->bi_ethspeed));
 #endif
-	puts ("\nIP addr     = ");	print_IPaddr (bd->bi_ip_addr);
-	printf ("\nbaudrate    = %6ld bps\n", bd->bi_baudrate   );
+	printf ("IP addr     = %pI4\n", &bd->bi_ip_addr);
+	printf ("baudrate    = %6ld bps\n", bd->bi_baudrate   );
 	return 0;
 }
 
@@ -156,9 +155,8 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	for (i=0; i<6; ++i) {
 		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
 	}
-	puts ("\nip_addr     = ");
-	print_IPaddr (bd->bi_ip_addr);
-	printf ("\nbaudrate    = %ld bps\n", bd->bi_baudrate);
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
+	printf ("baudrate    = %ld bps\n", bd->bi_baudrate);
 
 	return 0;
 }
@@ -188,11 +186,10 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	for (i=0; i<6; ++i) {
 		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
 	}
-	puts ("\nip_addr     = ");
-	print_IPaddr (bd->bi_ip_addr);
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
 
-	printf ("\nbaudrate    = %ld bps\n", bd->bi_baudrate);
+	printf ("baudrate    = %ld bps\n", bd->bi_baudrate);
 
 	return 0;
 }
@@ -216,10 +213,9 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	for (i=0; i<6; ++i) {
 		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
 	}
-	puts ("\nip_addr     = ");
-	print_IPaddr (bd->bi_ip_addr);
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
-	printf ("\nbaudrate    = %ld bps\n", (ulong)bd->bi_baudrate);
+	printf ("baudrate    = %ld bps\n", (ulong)bd->bi_baudrate);
 	return 0;
 }
 
@@ -255,10 +251,9 @@ int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 	for (i = 0; i < 6; ++i) {
 		printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
 	}
-	puts("\nIP addr                = ");
-	print_IPaddr(bd->bi_ip_addr);
+	printf("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
-	printf("\nbaudrate               = %6ld bps\n", bd->bi_baudrate);
+	printf("baudrate               = %6ld bps\n", bd->bi_baudrate);
 	return 0;
 }
 
@@ -320,10 +315,9 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	}
 #endif
 
-	puts ("\nip_addr     = ");
-	print_IPaddr (bd->bi_ip_addr);
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
-	printf ("\nbaudrate    = %ld bps\n", bd->bi_baudrate);
+	printf ("baudrate    = %ld bps\n", bd->bi_baudrate);
 
 	return 0;
 }
@@ -354,9 +348,8 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	puts("ethaddr     =");
 	for (i = 0; i < 6; ++i)
 		printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
-	puts("\nip_addr     = ");
-	print_IPaddr(bd->bi_ip_addr);
-	printf("\nbaudrate    = %d bps\n", bd->bi_baudrate);
+	printf("ip_addr     = %pI4\n", &bd->bi_ip_addr);
+	printf("baudrate    = %d bps\n", bd->bi_baudrate);
 
 	return 0;
 }
@@ -379,9 +372,8 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	for (i=0; i<6; ++i) {
 		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
 	}
-	puts ("\nip_addr     = ");
-	print_IPaddr (bd->bi_ip_addr);
-	printf ("\nbaudrate    = %d bps\n", bd->bi_baudrate);
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
+	printf ("baudrate    = %d bps\n", bd->bi_baudrate);
 
 	return 0;
 }
@@ -409,12 +401,10 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	for (i=0; i<6; ++i) {
 		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
 	}
-	puts  ( "\n"
-		"ip_addr     = ");
-	print_IPaddr (bd->bi_ip_addr);
+	puts  ( "\n" );
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
 #endif
-	printf ("\n"
-		"baudrate    = %d bps\n", bd->bi_baudrate);
+	printf ("baudrate    = %d bps\n", bd->bi_baudrate);
 
 	return 0;
 }
diff --git a/include/net.h b/include/net.h
index b192db1..bd061d9 100644
--- a/include/net.h
+++ b/include/net.h
@@ -408,9 +408,6 @@ extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, i
 /* Processes a received packet */
 extern void	NetReceive(volatile uchar *, int);
 
-/* Print an IP address on the console */
-extern void	print_IPaddr (IPaddr_t);
-
 /*
  * The following functions are a bit ugly, but necessary to deal with
  * alignment restrictions on ARM.
diff --git a/net/bootp.c b/net/bootp.c
index 83465e4..d1cbd39 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -271,17 +271,11 @@ static void BootpVendorProcess (u8 * ext, int size)
 
 #ifdef DEBUG_BOOTP_EXT
 	puts ("[BOOTP] Received fields: \n");
-	if (NetOurSubnetMask) {
-		puts ("NetOurSubnetMask : ");
-		print_IPaddr (NetOurSubnetMask);
-		putc ('\n');
-	}
+	if (NetOurSubnetMask)
+		printf ("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
 
-	if (NetOurGatewayIP) {
-		puts ("NetOurGatewayIP	: ");
-		print_IPaddr (NetOurGatewayIP);
-		putc ('\n');
-	}
+	if (NetOurGatewayIP)
+		printf ("NetOurGatewayIP	: %pI4", &NetOurGatewayIP);
 
 	if (NetBootFileSize) {
 		printf ("NetBootFileSize : %d\n", NetBootFileSize);
@@ -942,9 +936,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 				DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
 			BootpCopyNetParams(bp); /* Store net params from reply */
 			dhcp_state = BOUND;
-			puts ("DHCP client bound to address ");
-			print_IPaddr(NetOurIP);
-			putc ('\n');
+			printf ("DHCP client bound to address %pI4\n", &NetOurIP);
 
 			/* Obey the 'autoload' setting */
 			if ((s = getenv("autoload")) != NULL) {
diff --git a/net/net.c b/net/net.c
index 459baf4..9740f38 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1445,9 +1445,7 @@ NetReceive(volatile uchar * inpkt, int len)
 			case ICMP_REDIRECT:
 				if (icmph->code != ICMP_REDIR_HOST)
 					return;
-				puts (" ICMP Host Redirect to ");
-				print_IPaddr(icmph->un.gateway);
-				putc(' ');
+				printf (" ICMP Host Redirect to %pI4 ", &icmph->un.gateway);
 				return;
 #if defined(CONFIG_CMD_PING)
 			case ICMP_ECHO_REPLY:
@@ -1789,15 +1787,6 @@ ushort string_to_VLAN(char *s)
 	return htons(id);
 }
 
-void print_IPaddr (IPaddr_t x)
-{
-	char tmp[16];
-
-	ip_to_string (x, tmp);
-
-	puts (tmp);
-}
-
 IPaddr_t getenv_IPaddr (char *var)
 {
 	return (string_to_ip(getenv(var)));
diff --git a/net/nfs.c b/net/nfs.c
index f290014..0101629 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -741,18 +741,16 @@ NfsStart (void)
 	printf ("Using %s device\n", eth_get_name());
 #endif
 
-	puts ("File transfer via NFS from server "); print_IPaddr (NfsServerIP);
-	puts ("; our IP address is ");		    print_IPaddr (NetOurIP);
+	printf("File transfer via NFS from server %pI4"
+		"; our IP address is %pI4", &NfsServerIP, &NetOurIP);
 
 	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
 		IPaddr_t OurNet	    = NetOurIP	  & NetOurSubnetMask;
 		IPaddr_t ServerNet  = NetServerIP & NetOurSubnetMask;
 
-		if (OurNet != ServerNet) {
-			puts ("; sending through gateway ");
-			print_IPaddr (NetOurGatewayIP) ;
-		}
+		if (OurNet != ServerNet)
+			printf("; sending through gateway %pI4", &NetOurGatewayIP);
 	}
 	printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
 
diff --git a/net/tftp.c b/net/tftp.c
index 3dac3d8..b0f1cca 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -508,18 +508,16 @@ TftpStart (void)
 #if defined(CONFIG_NET_MULTI)
 	printf ("Using %s device\n", eth_get_name());
 #endif
-	puts ("TFTP from server ");	print_IPaddr (TftpServerIP);
-	puts ("; our IP address is ");	print_IPaddr (NetOurIP);
+	printf("TFTP from server %pI4"
+		"; our IP address is %pI4", &TftpServerIP, &NetOurIP);
 
 	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
 	    IPaddr_t OurNet	= NetOurIP    & NetOurSubnetMask;
 	    IPaddr_t ServerNet	= TftpServerIP & NetOurSubnetMask;
 
-	    if (OurNet != ServerNet) {
-		puts ("; sending through gateway ");
-		print_IPaddr (NetOurGatewayIP) ;
-	    }
+	    if (OurNet != ServerNet)
+		printf("; sending through gateway %pI4", &NetOurGatewayIP);
 	}
 	putc ('\n');
 
-- 
1.6.1.3



More information about the U-Boot mailing list