print case where host is zero but port is not (as in server local addresses)
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Wed, 5 Feb 1986 14:10:16 +0000 (06:10 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Wed, 5 Feb 1986 14:10:16 +0000 (06:10 -0800)
SCCS-vsn: lib/libc/net/ns_ntoa.c 6.2

usr/src/lib/libc/net/ns_ntoa.c

index dbee910..90382c6 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ns_ntoa.c  6.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)ns_ntoa.c  6.2 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/types.h>
 #endif not lint
 
 #include <sys/types.h>
@@ -18,26 +18,31 @@ struct ns_addr addr;
 {
        static char obuf[40];
        char *spectHex();
 {
        static char obuf[40];
        char *spectHex();
-       u_long net;
+       union { union ns_net net_e; u_long long_e; } net;
        u_short port = htons(addr.x_port);
        register char *cp;
        char *cp2;
        register u_char *up = addr.x_host.c_host;
        u_char *uplim = up + 6;
 
        u_short port = htons(addr.x_port);
        register char *cp;
        char *cp2;
        register u_char *up = addr.x_host.c_host;
        u_char *uplim = up + 6;
 
-       * (union ns_net *) &net = addr.x_net;
-       net = ntohl(net);
-       sprintf(obuf, "%lx", net);
+       net.net_e = addr.x_net;
+       sprintf(obuf, "%lx", ntohl(net.long_e));
        cp = spectHex(obuf);
        cp2 = cp + 1;
        while (*up==0 && up < uplim) up++;
        cp = spectHex(obuf);
        cp2 = cp + 1;
        while (*up==0 && up < uplim) up++;
-       if (up == uplim) return (obuf);
-       sprintf(cp, ".%x", *up++);
-       while (up < uplim) {
-               while (*cp) cp++;
-               sprintf(cp, "%02x", *up++);
+       if (up == uplim) {
+               if (port) {
+                       sprintf(cp, ".0");
+                       cp += 2;
+               }
+       } else {
+               sprintf(cp, ".%x", *up++);
+               while (up < uplim) {
+                       while (*cp) cp++;
+                       sprintf(cp, "%02x", *up++);
+               }
+               cp = spectHex(cp2);
        }
        }
-       cp = spectHex(cp2);
        if (port) {
                sprintf(cp, ".%x", port);
                spectHex(cp + 1);
        if (port) {
                sprintf(cp, ".%x", port);
                spectHex(cp + 1);