[LWN Logo]

Date:	Wed, 28 Oct 1998 10:57:24 +0000 (GMT)
From:	Riley Williams <rhw@bigfoot.com>
To:	Linus Torvalds <torvalds@transmeta.com>, Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: Patch to fix /proc/net files.

Hi there.

There has been quite a bit of comment recently regarding the
formatting of data in the /proc file system, and Linus was heard to
comment (amongst other things) that he would prefer to see all IP
addresses specified in dotted quad format therein, rather than in any
form of endian-specific integers or the like. 

This patch should convert /proc/net/{raw,tcp,udp} so that the various
IP addresses therein are shown in dotted quad format rather than in
little-endian hex integers.

I have verified that it compiles when applied to a clean 2.0.35
source, but have not yet been able to thoroughly test it, nor is my
system alone necessarily a good testbed for such a patch. Hence I am
posting it here for you all to tear to bits as appropriate.

Please report any problems to:

	Riley Williams <rhw@bigfoot.com>

Best wishes from Riley.

***************************************************************************

--- linux/net/ipv4/proc.c.orig	Wed Jun  3 23:17:50 1998
+++ linux/net/ipv4/proc.c	Wed Oct 28 10:21:46 1998
@@ -48,6 +48,23 @@
 #include <net/sock.h>
 #include <net/raw.h>
 
+char *malloc(size_t size);
+
+/*
+ * Convert its IP address parameter to a dotted quad string, returning that string.
+ * Its second parameter is assumed to be loaded such that the first part of the
+ * dotted quad is in the most significant bits of the integer.
+ */
+
+void
+ip_to_quad(char *result, unsigned long address)
+{
+	sprintf( result, "%lu.%lu.%lu.%lu", (address >> 24) & 255,
+					    (address >> 16) & 255,
+					    (address >>  8) & 255,
+					     address        & 255 );
+}
+
 /*
  * Get__netinfo returns the length of that string.
  *
@@ -58,6 +75,7 @@
 static int
 get__netinfo(struct proto *pro, char *buffer, int format, char **start, off_t offset, int length)
 {
+	char tmpbuf[255], srcs[16], dests[16];
 	struct sock *sp;
 	int timer_active, timer_active1, timer_active2;
 	unsigned long timer_expires;
@@ -66,7 +84,6 @@
 	int len=0, i = 0;
 	off_t pos=0;
 	off_t begin;
-	char tmpbuf[129];
   
 	if (offset < 128) 
 		len += sprintf(buffer, "%-127s\n",
@@ -110,9 +127,11 @@
 			timer_active=timer_active2;
 			timer_expires=sp->timer.expires;
 		}
-		sprintf(tmpbuf, "%4d: %08lX:%04X %08lX:%04X"
+		ip_to_quad(srcs, src);
+		ip_to_quad(dests, dest);
+		sprintf(tmpbuf, "%4d: %15s:%-5d %15s:%-5d"
 			" %02X %08X:%08X %02X:%08lX %08X %5d %8d %ld",
-			i, src, srcp, dest, destp, sp->state, 
+			i, srcs, srcp, dests, destp, sp->state, 
 			format==0?sp->write_seq-sp->rcv_ack_seq:sp->wmem_alloc, 
 			format==0?sp->acked_seq-sp->copied_seq:sp->rmem_alloc,
 			timer_active, timer_expires-jiffies, (unsigned) sp->retransmits,


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/