summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhenning <>2005-06-17 20:36:16 +0000
committerhenning <>2005-06-17 20:36:16 +0000
commita92e3b95173517780038be86107a02ae3c711085 (patch)
tree44cd6fe679bb20e63ea0c863477aeb6376856dcd
parentc55b7004c82eba00f9d9ea859c9648787dae9b24 (diff)
downloadopenbsd-a92e3b95173517780038be86107a02ae3c711085.tar.gz
openbsd-a92e3b95173517780038be86107a02ae3c711085.tar.bz2
openbsd-a92e3b95173517780038be86107a02ae3c711085.zip
remove netns stuff, ok millert
libc major bump by espie in a few
-rw-r--r--src/lib/libc/net/Makefile.inc9
-rw-r--r--src/lib/libc/net/net_addrcmp.c7
-rw-r--r--src/lib/libc/net/ns.3127
-rw-r--r--src/lib/libc/net/ns_addr.c214
-rw-r--r--src/lib/libc/net/ns_ntoa.c106
5 files changed, 4 insertions, 459 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc
index 6b7740195f..da746b97b1 100644
--- a/src/lib/libc/net/Makefile.inc
+++ b/src/lib/libc/net/Makefile.inc
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile.inc,v 1.39 2005/01/06 04:24:14 itojun Exp $ 1# $OpenBSD: Makefile.inc,v 1.40 2005/06/17 20:36:16 henning Exp $
2 2
3# net sources 3# net sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net
@@ -12,9 +12,7 @@ SRCS+= base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c gethostnamadr.c \
12 herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ 12 herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \
13 inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ 13 inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \
14 inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ 14 inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \
15 ipx_addr.c ipx_ntoa.c linkaddr.c ns_addr.c ns_ntoa.c \ 15 ipx_addr.c ipx_ntoa.c linkaddr.c net_addrcmp.c nsap_addr.c \
16 nsap_addr.c \
17 net_addrcmp.c \
18 rcmd.c rresvport.c recv.c res_comp.c res_data.c res_debug.c \ 16 rcmd.c rresvport.c recv.c res_comp.c res_data.c res_debug.c \
19 res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \ 17 res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \
20 sethostent.c ethers.c rcmdsh.c 18 sethostent.c ethers.c rcmdsh.c
@@ -32,7 +30,7 @@ MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \
32 getifaddrs.3 getnameinfo.3 getnetent.3 getprotoent.3 \ 30 getifaddrs.3 getnameinfo.3 getnetent.3 getprotoent.3 \
33 getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \ 31 getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \
34 inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \ 32 inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \
35 ipx.3 link_addr.3 net_addrcmp.3 ns.3 \ 33 ipx.3 link_addr.3 net_addrcmp.3 \
36 rcmd.3 rcmdsh.3 resolver.3 34 rcmd.3 rcmdsh.3 resolver.3
37 35
38MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ 36MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \
@@ -71,7 +69,6 @@ MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \
71MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 69MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3
72MLINKS+=link_addr.3 link_ntoa.3 70MLINKS+=link_addr.3 link_ntoa.3
73MLINKS+=ipx.3 ipx_addr.3 ipx.3 ipx_ntoa.3 71MLINKS+=ipx.3 ipx_addr.3 ipx.3 ipx_ntoa.3
74MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3
75MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ 72MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \
76 rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3 73 rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3
77MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ 74MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \
diff --git a/src/lib/libc/net/net_addrcmp.c b/src/lib/libc/net/net_addrcmp.c
index 8f8f694f4c..c2630a5265 100644
--- a/src/lib/libc/net/net_addrcmp.c
+++ b/src/lib/libc/net/net_addrcmp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: net_addrcmp.c,v 1.9 2005/03/25 13:24:12 otto Exp $ */ 1/* $OpenBSD: net_addrcmp.c,v 1.10 2005/06/17 20:36:16 henning Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999 Theo de Raadt 4 * Copyright (c) 1999 Theo de Raadt
@@ -29,7 +29,6 @@
29#include <sys/socket.h> 29#include <sys/socket.h>
30#include <sys/un.h> 30#include <sys/un.h>
31#include <netinet/in.h> 31#include <netinet/in.h>
32#include <netns/ns.h>
33#include <string.h> 32#include <string.h>
34 33
35int 34int
@@ -55,10 +54,6 @@ net_addrcmp(struct sockaddr *sa1, struct sockaddr *sa2)
55 return memcmp(&((struct sockaddr_in6 *)sa1)->sin6_addr, 54 return memcmp(&((struct sockaddr_in6 *)sa1)->sin6_addr,
56 &((struct sockaddr_in6 *)sa2)->sin6_addr, 55 &((struct sockaddr_in6 *)sa2)->sin6_addr,
57 sizeof(struct in6_addr)); 56 sizeof(struct in6_addr));
58 case AF_NS:
59 return (memcmp(&((struct sockaddr_ns *)sa1)->sns_addr,
60 &((struct sockaddr_ns *)sa2)->sns_addr,
61 sizeof(struct ns_addr)));
62 case AF_LOCAL: 57 case AF_LOCAL:
63 return (strcmp(((struct sockaddr_un *)sa1)->sun_path, 58 return (strcmp(((struct sockaddr_un *)sa1)->sun_path,
64 ((struct sockaddr_un *)sa1)->sun_path)); 59 ((struct sockaddr_un *)sa1)->sun_path));
diff --git a/src/lib/libc/net/ns.3 b/src/lib/libc/net/ns.3
deleted file mode 100644
index 9c7aeab312..0000000000
--- a/src/lib/libc/net/ns.3
+++ /dev/null
@@ -1,127 +0,0 @@
1.\" $OpenBSD: ns.3,v 1.9 2003/06/02 20:18:35 millert Exp $
2.\"
3.\" Copyright (c) 1986, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd June 4, 1993
31.Dt NS 3
32.Os
33.Sh NAME
34.Nm ns_addr ,
35.Nm ns_ntoa
36.Nd Xerox
37.Tn NS Ns (tm)
38address conversion routines
39.Sh SYNOPSIS
40.Fd #include <sys/types.h>
41.Fd #include <netns/ns.h>
42.Ft struct ns_addr
43.Fn ns_addr "char *cp"
44.Ft char *
45.Fn ns_ntoa "struct ns_addr ns"
46.Sh DESCRIPTION
47The routine
48.Fn ns_addr
49interprets character strings representing
50.Tn XNS
51addresses, returning binary information suitable
52for use in system calls.
53The routine
54.Fn ns_ntoa
55takes
56.Tn XNS
57addresses and returns
58.Tn ASCII
59strings representing the address in a
60notation in common use in the Xerox Development Environment:
61.Bd -filled -offset indent
62<network number>.<host number>.<port number>
63.Ed
64.Pp
65Trailing zero fields are suppressed, and each number is printed in hexadecimal,
66in a format suitable for input to
67.Fn ns_addr .
68Any fields lacking super-decimal digits will have a
69trailing
70.Sq H
71appended.
72.Pp
73Unfortunately, no universal standard exists for representing
74.Tn XNS
75addresses.
76An effort has been made to ensure that
77.Fn ns_addr
78be compatible with most formats in common use.
79It will first separate an address into 1 to 3 fields using a single delimiter
80chosen from
81period
82.Pq Ql \&. ,
83colon
84.Pq Ql \&: ,
85or pound-sign
86.Ql # .
87Each field is then examined for byte separators (colon or period).
88If there are byte separators, each subfield separated is taken to be
89a small hexadecimal number, and the entirety is taken as a network-byte-ordered
90quantity to be zero extended in the high-network-order bytes.
91Next, the field is inspected for hyphens, in which case
92the field is assumed to be a number in decimal notation
93with hyphens separating the millenia.
94Next, the field is assumed to be a number:
95It is interpreted
96as hexadecimal if there is a leading
97.Ql 0x
98(as in C),
99a trailing
100.Sq H
101(as in Mesa), or there are any super-decimal digits present.
102It is interpreted as octal if there is a leading
103.Ql 0
104and there are no super-octal digits.
105Otherwise, it is converted as a decimal number.
106.Sh RETURN VALUES
107None.
108(See
109.Sx BUGS . )
110.Sh SEE ALSO
111.Xr hosts 5 ,
112.Xr networks 5
113.Sh HISTORY
114The
115.Fn ns_addr
116and
117.Fn ns_toa
118functions appeared in
119.Bx 4.3 .
120.Sh BUGS
121The string returned by
122.Fn ns_ntoa
123resides in a static memory area.
124The function
125.Fn ns_addr
126should diagnose improperly formed input, and there should be an unambiguous
127way to recognize this.
diff --git a/src/lib/libc/net/ns_addr.c b/src/lib/libc/net/ns_addr.c
deleted file mode 100644
index 03b14909c5..0000000000
--- a/src/lib/libc/net/ns_addr.c
+++ /dev/null
@@ -1,214 +0,0 @@
1/*
2 * Copyright (c) 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * J.Q. Johnson.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char rcsid[] = "$OpenBSD: ns_addr.c,v 1.9 2005/03/25 13:24:12 otto Exp $";
35#endif /* LIBC_SCCS and not lint */
36
37#include <sys/param.h>
38#include <netns/ns.h>
39#include <stdio.h>
40#include <string.h>
41
42static struct ns_addr addr, zero_addr;
43
44static void Field(char *, u_int8_t *, int);
45static void cvtbase(long, int, int[], int, u_int8_t[], int);
46
47struct ns_addr
48ns_addr(const char *name)
49{
50 char separator;
51 char *hostname, *socketname, *cp;
52 char buf[50];
53
54 strlcpy(buf, name, sizeof(buf));
55
56 /*
57 * First, figure out what he intends as a field separtor.
58 * Despite the way this routine is written, the prefered
59 * form 2-272.AA001234H.01777, i.e. XDE standard.
60 * Great efforts are made to insure backward compatibility.
61 */
62 if ((hostname = strchr(buf, '#')))
63 separator = '#';
64 else {
65 hostname = strchr(buf, '.');
66 if ((cp = strchr(buf, ':')) &&
67 ((hostname && cp < hostname) || (hostname == 0))) {
68 hostname = cp;
69 separator = ':';
70 } else
71 separator = '.';
72 }
73 if (hostname)
74 *hostname++ = 0;
75
76 addr = zero_addr;
77 Field(buf, addr.x_net.c_net, 4);
78 if (hostname == 0)
79 return (addr); /* No separator means net only */
80
81 socketname = strchr(hostname, separator);
82 if (socketname) {
83 *socketname++ = 0;
84 Field(socketname, (u_char *)&addr.x_port, 2);
85 }
86
87 Field(hostname, (u_char *)addr.x_host.c_host, 6);
88
89 return (addr);
90}
91
92static void
93Field(char *buf, u_char *out, int len)
94{
95 char *bp = buf;
96 int i, ibase, base16 = 0, base10 = 0, clen = 0;
97 int hb[6], *hp;
98 char *fmt;
99
100 /*
101 * first try 2-273#2-852-151-014#socket
102 */
103 if ((*buf != '-') &&
104 (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d",
105 &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) {
106 cvtbase(1000L, 256, hb, i, out, len);
107 return;
108 }
109 /*
110 * try form 8E1#0.0.AA.0.5E.E6#socket
111 */
112 if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x",
113 &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
114 cvtbase(256L, 256, hb, i, out, len);
115 return;
116 }
117 /*
118 * try form 8E1#0:0:AA:0:5E:E6#socket
119 */
120 if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x",
121 &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
122 cvtbase(256L, 256, hb, i, out, len);
123 return;
124 }
125 /*
126 * This is REALLY stretching it but there was a
127 * comma notation separting shorts -- definitely non standard
128 */
129 if (1 < (i = sscanf(buf,"%x,%x,%x",
130 &hb[0], &hb[1], &hb[2]))) {
131 hb[0] = htons(hb[0]); hb[1] = htons(hb[1]);
132 hb[2] = htons(hb[2]);
133 cvtbase(65536L, 256, hb, i, out, len);
134 return;
135 }
136
137 /* Need to decide if base 10, 16 or 8 */
138 while (*bp) switch (*bp++) {
139
140 case '0': case '1': case '2': case '3': case '4': case '5':
141 case '6': case '7': case '-':
142 break;
143
144 case '8': case '9':
145 base10 = 1;
146 break;
147
148 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
149 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
150 base16 = 1;
151 break;
152
153 case 'x': case 'X':
154 *--bp = '0';
155 base16 = 1;
156 break;
157
158 case 'h': case 'H':
159 base16 = 1;
160 /* fall into */
161
162 default:
163 *--bp = 0; /* Ends Loop */
164 }
165 if (base16) {
166 fmt = "%3x";
167 ibase = 4096;
168 } else if (base10 == 0 && *buf == '0') {
169 fmt = "%3o";
170 ibase = 512;
171 } else {
172 fmt = "%3d";
173 ibase = 1000;
174 }
175
176 for (bp = buf; *bp++; ) clen++;
177 if (clen == 0) clen++;
178 if (clen > 18) clen = 18;
179 i = ((clen - 1) / 3) + 1;
180 bp = clen + buf - 3;
181 hp = hb + i - 1;
182
183 while (hp > hb) {
184 (void)sscanf(bp, fmt, hp);
185 bp[0] = 0;
186 hp--;
187 bp -= 3;
188 }
189 (void)sscanf(buf, fmt, hp);
190 cvtbase((long)ibase, 256, hb, i, out, len);
191}
192
193static void
194cvtbase(long int oldbase, int newbase, int *input, int inlen,
195 unsigned char *result, int reslen)
196{
197 int d, e;
198 long sum;
199
200 e = 1;
201 while (e > 0 && reslen > 0) {
202 d = 0; e = 0; sum = 0;
203 /* long division: input=input/newbase */
204 while (d < inlen) {
205 sum = sum*oldbase + (long) input[d];
206 e += (sum > 0);
207 input[d++] = sum / newbase;
208 sum %= newbase;
209 }
210 result[--reslen] = sum; /* accumulate remainder */
211 }
212 for (d=0; d < reslen; d++)
213 result[d] = 0;
214}
diff --git a/src/lib/libc/net/ns_ntoa.c b/src/lib/libc/net/ns_ntoa.c
deleted file mode 100644
index fd67e459da..0000000000
--- a/src/lib/libc/net/ns_ntoa.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/*
2 * Copyright (c) 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.13 2003/09/25 21:14:46 millert Exp $";
32#endif /* LIBC_SCCS and not lint */
33
34#include <sys/param.h>
35#include <netns/ns.h>
36#include <stdio.h>
37
38static char *spectHex(char *);
39
40char *
41ns_ntoa(struct ns_addr addr)
42{
43 static char obuf[40];
44 union { union ns_net net_e; u_int32_t long_e; } net;
45 in_port_t port = htons(addr.x_port);
46 char *cp, *cp2;
47 u_char *up = addr.x_host.c_host;
48 u_char *uplim = up + 6;
49 size_t rem;
50
51 net.net_e = addr.x_net;
52 snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e));
53 cp = spectHex(obuf);
54 rem = sizeof(obuf) - (cp - obuf);
55 cp2 = cp + 1;
56 while (up < uplim && *up==0)
57 up++;
58 if (up == uplim) {
59 if (port) {
60 snprintf(cp, rem, ".0");
61 cp += 2;
62 rem -= 2;
63 }
64 } else {
65 snprintf(cp, rem, ".%x", *up++);
66 while (up < uplim) {
67 while (*cp) {
68 cp++;
69 rem--;
70 }
71 snprintf(cp, rem, "%02x", *up++);
72 }
73 cp = spectHex(cp2);
74 rem = sizeof(obuf) - (cp - obuf);
75 }
76 if (port) {
77 snprintf(cp, rem, ".%x", port);
78 spectHex(cp + 1);
79 }
80 return (obuf);
81}
82
83static char *
84spectHex(char *p0)
85{
86 int ok = 0, nonzero = 0;
87 char *p = p0;
88
89 for (; *p; p++) {
90 switch (*p) {
91 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
92 *p += ('A' - 'a');
93 /* fall into . . . */
94 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
95 ok = 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;
104 }
105 return (p);
106}