summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt <>2002-07-25 21:12:47 +0000
committerderaadt <>2002-07-25 21:12:47 +0000
commitf60b3a80fab33686119eda8629a7cbe8319cc074 (patch)
treee87c5b7f68631666bcf5b06256c63bf99df6227f
parent0a8e0953b806aa0ac60022c94c66011f44ceaacd (diff)
downloadopenbsd-f60b3a80fab33686119eda8629a7cbe8319cc074.tar.gz
openbsd-f60b3a80fab33686119eda8629a7cbe8319cc074.tar.bz2
openbsd-f60b3a80fab33686119eda8629a7cbe8319cc074.zip
cleanup
-rw-r--r--src/lib/libc/net/ns_ntoa.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/lib/libc/net/ns_ntoa.c b/src/lib/libc/net/ns_ntoa.c
index 3c82bc3cee..5ff410e28a 100644
--- a/src/lib/libc/net/ns_ntoa.c
+++ b/src/lib/libc/net/ns_ntoa.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.9 2002/05/24 21:22:37 deraadt Exp $"; 35static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.10 2002/07/25 21:12:47 deraadt Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/param.h> 38#include <sys/param.h>
@@ -42,22 +42,21 @@ static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.9 2002/05/24 21:22:37 deraadt Exp
42static char *spectHex(char *); 42static char *spectHex(char *);
43 43
44char * 44char *
45ns_ntoa(addr) 45ns_ntoa(struct ns_addr addr)
46 struct ns_addr addr;
47{ 46{
48 static char obuf[40]; 47 static char obuf[40];
49 union { union ns_net net_e; u_int32_t long_e; } net; 48 union { union ns_net net_e; u_int32_t long_e; } net;
50 in_port_t port = htons(addr.x_port); 49 in_port_t port = htons(addr.x_port);
51 register char *cp; 50 char *cp, *cp2;
52 char *cp2; 51 u_char *up = addr.x_host.c_host;
53 register u_char *up = addr.x_host.c_host;
54 u_char *uplim = up + 6; 52 u_char *uplim = up + 6;
55 53
56 net.net_e = addr.x_net; 54 net.net_e = addr.x_net;
57 snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e)); 55 snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e));
58 cp = spectHex(obuf); 56 cp = spectHex(obuf);
59 cp2 = cp + 1; 57 cp2 = cp + 1;
60 while (*up==0 && up < uplim) up++; 58 while (*up==0 && up < uplim)
59 up++;
61 if (up == uplim) { 60 if (up == uplim) {
62 if (port) { 61 if (port) {
63 sprintf(cp, ".0"); 62 sprintf(cp, ".0");
@@ -66,7 +65,8 @@ ns_ntoa(addr)
66 } else { 65 } else {
67 sprintf(cp, ".%x", *up++); 66 sprintf(cp, ".%x", *up++);
68 while (up < uplim) { 67 while (up < uplim) {
69 while (*cp) cp++; 68 while (*cp)
69 cp++;
70 sprintf(cp, "%02x", *up++); 70 sprintf(cp, "%02x", *up++);
71 } 71 }
72 cp = spectHex(cp2); 72 cp = spectHex(cp2);
@@ -79,23 +79,26 @@ ns_ntoa(addr)
79} 79}
80 80
81static char * 81static char *
82spectHex(p0) 82spectHex(char *p0)
83 char *p0;
84{ 83{
85 int ok = 0; 84 int ok = 0, nonzero = 0;
86 int nonzero = 0; 85 char *p = p0;
87 register char *p = p0;
88 for (; *p; p++) switch (*p) {
89 86
90 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 87 for (; *p; p++) {
91 *p += ('A' - 'a'); 88 switch (*p) {
92 /* fall into . . . */ 89 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
93 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 90 *p += ('A' - 'a');
94 ok = 1; 91 /* fall into . . . */
95 case '1': case '2': case '3': case '4': case '5': 92 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
96 case '6': case '7': case '8': case '9': 93 ok = 1;
97 nonzero = 1; 94 case '1': case '2': case '3': case '4': case '5':
95 case '6': case '7': case '8': case '9':
96 nonzero = 1;
97 }
98 }
99 if (nonzero && !ok) {
100 *p++ = 'H';
101 *p = 0;
98 } 102 }
99 if (nonzero && !ok) { *p++ = 'H'; *p = 0; }
100 return (p); 103 return (p);
101} 104}