patch-2.1.48 linux/lib/vsprintf.c

Next file: linux/mm/filemap.c
Previous file: linux/kernel/sched.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.47/linux/lib/vsprintf.c linux/lib/vsprintf.c
@@ -131,6 +131,9 @@
 	return str;
 }
 
+/* Forward decl. needed for IP address printing stuff... */
+int sprintf(char * buf, const char *fmt, ...);
+
 int vsprintf(char *buf, const char *fmt, va_list args)
 {
 	int len;
@@ -247,6 +250,41 @@
 			} else {
 				int * ip = va_arg(args, int *);
 				*ip = (str - buf);
+			}
+			continue;
+
+		case 'I': /* IPv4 / IPv6 printout */
+			{
+			  __u8 *ip4;
+			  char sbuf[6];
+			  if (qualifier == 'l') {
+			    __u16 *ip6 = va_arg(args, __u16 *);
+			    i = 6;
+			    for ( ; i > 0; --i, ++ip6)
+			      if (*ip6 != 0)
+				break;
+			    if (i < 6)
+			      *str++ = ':';
+			    for ( ; i > 0; --i, ++ip6) {
+			      sprintf(sbuf,":%04x",(int)(*ip6));
+			      s = sbuf;
+			      while (*s)
+				*str++ = *s++;
+			    }
+			    *str++ = ':';
+			    ip4 = (__u8*) ip6;
+			  } else {
+			    ip4 = va_arg(args, __u8 *);
+			  }
+			  for (i = 0; i < 4; ++i, ++ip4) {
+			    if (i == 3)
+			      sprintf(sbuf,"%d", 0xFF & (*ip4));
+			    else
+			      sprintf(sbuf,"%d.", 0xFF & (*ip4));
+			    s = sbuf;
+			    while (*s)
+			      *str++ = *s++;
+			  }
 			}
 			continue;
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov