summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/ns_ntoa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/ns_ntoa.c')
-rw-r--r--src/lib/libc/net/ns_ntoa.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/lib/libc/net/ns_ntoa.c b/src/lib/libc/net/ns_ntoa.c
index ad3265399b..fd67e459da 100644
--- a/src/lib/libc/net/ns_ntoa.c
+++ b/src/lib/libc/net/ns_ntoa.c
@@ -1,5 +1,3 @@
1/* $NetBSD: ns_ntoa.c,v 1.4 1995/02/25 06:20:51 cgd Exp $ */
2
3/* 1/*
4 * Copyright (c) 1986, 1993 2 * Copyright (c) 1986, 1993
5 * The Regents of the University of California. All rights reserved. 3 * The Regents of the University of California. All rights reserved.
@@ -12,11 +10,7 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 13 * 3. Neither the name of the University nor the names of its contributors
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software 14 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission. 15 * without specific prior written permission.
22 * 16 *
@@ -34,73 +28,79 @@
34 */ 28 */
35 29
36#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
37#if 0 31static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.13 2003/09/25 21:14:46 millert Exp $";
38static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93";
39#else
40static char rcsid[] = "$NetBSD: ns_ntoa.c,v 1.4 1995/02/25 06:20:51 cgd Exp $";
41#endif
42#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
43 33
44#include <sys/param.h> 34#include <sys/param.h>
45#include <netns/ns.h> 35#include <netns/ns.h>
46#include <stdio.h> 36#include <stdio.h>
47 37
38static char *spectHex(char *);
39
48char * 40char *
49ns_ntoa(addr) 41ns_ntoa(struct ns_addr addr)
50 struct ns_addr addr;
51{ 42{
52 static char obuf[40]; 43 static char obuf[40];
53 union { union ns_net net_e; u_long long_e; } net; 44 union { union ns_net net_e; u_int32_t long_e; } net;
54 u_short port = htons(addr.x_port); 45 in_port_t port = htons(addr.x_port);
55 register char *cp; 46 char *cp, *cp2;
56 char *cp2; 47 u_char *up = addr.x_host.c_host;
57 register u_char *up = addr.x_host.c_host;
58 u_char *uplim = up + 6; 48 u_char *uplim = up + 6;
59 static char *spectHex(); 49 size_t rem;
60 50
61 net.net_e = addr.x_net; 51 net.net_e = addr.x_net;
62 sprintf(obuf, "%lx", ntohl(net.long_e)); 52 snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e));
63 cp = spectHex(obuf); 53 cp = spectHex(obuf);
54 rem = sizeof(obuf) - (cp - obuf);
64 cp2 = cp + 1; 55 cp2 = cp + 1;
65 while (*up==0 && up < uplim) up++; 56 while (up < uplim && *up==0)
57 up++;
66 if (up == uplim) { 58 if (up == uplim) {
67 if (port) { 59 if (port) {
68 sprintf(cp, ".0"); 60 snprintf(cp, rem, ".0");
69 cp += 2; 61 cp += 2;
62 rem -= 2;
70 } 63 }
71 } else { 64 } else {
72 sprintf(cp, ".%x", *up++); 65 snprintf(cp, rem, ".%x", *up++);
73 while (up < uplim) { 66 while (up < uplim) {
74 while (*cp) cp++; 67 while (*cp) {
75 sprintf(cp, "%02x", *up++); 68 cp++;
69 rem--;
70 }
71 snprintf(cp, rem, "%02x", *up++);
76 } 72 }
77 cp = spectHex(cp2); 73 cp = spectHex(cp2);
74 rem = sizeof(obuf) - (cp - obuf);
78 } 75 }
79 if (port) { 76 if (port) {
80 sprintf(cp, ".%x", port); 77 snprintf(cp, rem, ".%x", port);
81 spectHex(cp + 1); 78 spectHex(cp + 1);
82 } 79 }
83 return (obuf); 80 return (obuf);
84} 81}
85 82
86static char * 83static char *
87spectHex(p0) 84spectHex(char *p0)
88 char *p0;
89{ 85{
90 int ok = 0; 86 int ok = 0, nonzero = 0;
91 int nonzero = 0; 87 char *p = p0;
92 register char *p = p0;
93 for (; *p; p++) switch (*p) {
94 88
95 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 89 for (; *p; p++) {
96 *p += ('A' - 'a'); 90 switch (*p) {
97 /* fall into . . . */ 91 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
98 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 92 *p += ('A' - 'a');
99 ok = 1; 93 /* fall into . . . */
100 case '1': case '2': case '3': case '4': case '5': 94 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
101 case '6': case '7': case '8': case '9': 95 ok = 1;
102 nonzero = 1; 96 case '1': case '2': case '3': case '4': case '5':
97 case '6': case '7': case '8': case '9':
98 nonzero = 1;
99 }
100 }
101 if (nonzero && !ok) {
102 *p++ = 'H';
103 *p = 0;
103 } 104 }
104 if (nonzero && !ok) { *p++ = 'H'; *p = 0; }
105 return (p); 105 return (p);
106} 106}