add the 'i' and 'V' formats back
authorRonald G. Minnich <rminnich@google.com>
Thu, 23 Jan 2014 17:25:08 +0000 (09:25 -0800)
committerRonald G. Minnich <rminnich@google.com>
Thu, 23 Jan 2014 17:25:08 +0000 (09:25 -0800)
'i' is ipv6 as four longs, V is ipv4.
This completes restoring well-known plan 9 formats
to the kernel.

Signed-off-by: Ronald G. Minnich <rminnich@google.com>
kern/include/stdio.h
kern/src/net/eipconv.c
kern/src/printfmt.c

index 4f61246..a9bb787 100644 (file)
@@ -57,5 +57,5 @@ char *seprintf(char *buf, char *end, const char *fmt, ...);
 void printemac(void (*putch)(int, void**), void **putdat, uint8_t *mac);
 void printip(void (*putch)(int, void**), void **putdat, uint8_t *ip);
 void printipmask(void (*putch)(int, void**), void **putdat, uint8_t *ip);
-
+void printipv4(void (*putch)(int, void**), void **putdat, uint8_t *ip);
 #endif /* !ROS_INC_STDIO_H */
index b69ead6..09392fa 100644 (file)
@@ -76,20 +76,10 @@ void printip(void (*putch)(int, void**), void **putdat, uint8_t *ip)
        }
 }
 
-/* what format to use? */
-#if 0
-case 'i':      /* v6 address as 4 longs */
-                       lp = va_arg(ap, uint32_t *);
-                       for (i = 0; i < 4; i++)
-                               hnputl(ip + 4 * i, *lp++);
-                       p = ip;
-                       goto common;
-
-               case 'V':       /* v4 ip address */
-                       p = va_arg(ap, uint8_t *);
-                       printfmt(putch, putdat, ifmt, p[0], p[1], p[2], p[3]);
-                       break;
-#endif
+void printipv4(void (*putch)(int, void**), void **putdat, uint8_t *p)
+{
+       printfmt(putch, putdat, ifmt, p[0], p[1], p[2], p[3]);
+}
 
 void printipmask(void (*putch)(int, void**), void **putdat, uint8_t *ip)
 {
index e30b928..a3bd013 100644 (file)
@@ -60,6 +60,7 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
        char padc;
        uint8_t *mac, *ip, *mask;
        int i;
+       uint32_t *lp;
 
        while (1) {
                while ((ch = *(unsigned char *) fmt) != '%') {
@@ -155,6 +156,16 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        }
                        printemac(putch, putdat, mac);
                        break;
+               case 'i':
+                       /* what to do if they screw up? */
+                       if ((lp = va_arg(ap, uint32_t *)) != NULL){
+                               uint32_t hostfmt;
+                               for(i = 0; i < 4; i++){
+                                       hnputl(&lp[i], &hostfmt);
+                                       printfmt(putch, putdat, "%08lx", hostfmt);
+                               }
+                       }
+                       break;
                case 'I':
                        /* what to do if they screw up? */
                        if ((ip = va_arg(ap, uint8_t *)) != NULL)
@@ -165,6 +176,12 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        if ((mask = va_arg(ap, uint8_t *)) != NULL)
                                printipmask(putch, putdat, mask);
                        break;
+               case 'V':
+                       /* what to do if they screw up? */
+                       if ((ip = va_arg(ap, uint8_t *)) != NULL)
+                               printipv4(putch, putdat, ip);
+                       break;
+
                // string
                case 's':
                        if ((p = va_arg(ap, char *)) == NULL)