diff options
Diffstat (limited to 'src/lib/libc/net/ipx_addr.c')
-rw-r--r-- | src/lib/libc/net/ipx_addr.c | 213 |
1 files changed, 0 insertions, 213 deletions
diff --git a/src/lib/libc/net/ipx_addr.c b/src/lib/libc/net/ipx_addr.c deleted file mode 100644 index b65d5f6cfd..0000000000 --- a/src/lib/libc/net/ipx_addr.c +++ /dev/null | |||
@@ -1,213 +0,0 @@ | |||
1 | /* $OpenBSD: ipx_addr.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 1986, 1993 | ||
4 | * The Regents of the University of California. All rights reserved. | ||
5 | * | ||
6 | * This code is derived from software contributed to Berkeley by | ||
7 | * J.Q. Johnson. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the distribution. | ||
17 | * 3. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
31 | * SUCH DAMAGE. | ||
32 | * | ||
33 | * from @(#)ipx_addr.c | ||
34 | */ | ||
35 | |||
36 | #include <sys/param.h> | ||
37 | #include <netipx/ipx.h> | ||
38 | #include <stdio.h> | ||
39 | #include <string.h> | ||
40 | |||
41 | static struct ipx_addr addr, zero_addr; | ||
42 | |||
43 | static void Field(char *, u_char *, int); | ||
44 | static void cvtbase(long, int, int *, int, unsigned char *, int); | ||
45 | |||
46 | struct ipx_addr | ||
47 | ipx_addr(const char *name) | ||
48 | { | ||
49 | char separator; | ||
50 | char *hostname, *socketname, *cp; | ||
51 | char buf[50]; | ||
52 | |||
53 | strlcpy(buf, name, sizeof(buf)); | ||
54 | |||
55 | /* | ||
56 | * First, figure out what he intends as a field separtor. | ||
57 | * Despite the way this routine is written, the prefered | ||
58 | * form 2-272.AA001234H.01777, i.e. XDE standard. | ||
59 | * Great efforts are made to insure backward compatibility. | ||
60 | */ | ||
61 | if ((hostname = strchr(buf, '#'))) | ||
62 | separator = '#'; | ||
63 | else { | ||
64 | hostname = strchr(buf, '.'); | ||
65 | if ((cp = strchr(buf, ':')) && | ||
66 | ((hostname && cp < hostname) || (hostname == 0))) { | ||
67 | hostname = cp; | ||
68 | separator = ':'; | ||
69 | } else | ||
70 | separator = '.'; | ||
71 | } | ||
72 | if (hostname) | ||
73 | *hostname++ = 0; | ||
74 | |||
75 | addr = zero_addr; | ||
76 | Field(buf, addr.ipx_net.c_net, 4); | ||
77 | if (hostname == 0) | ||
78 | return (addr); /* No separator means net only */ | ||
79 | |||
80 | socketname = strchr(hostname, separator); | ||
81 | if (socketname) { | ||
82 | *socketname++ = 0; | ||
83 | Field(socketname, (u_char *)&addr.ipx_port, 2); | ||
84 | } | ||
85 | |||
86 | Field(hostname, addr.ipx_host.c_host, 6); | ||
87 | |||
88 | return (addr); | ||
89 | } | ||
90 | |||
91 | static void | ||
92 | Field(char *buf, u_char *out, int len) | ||
93 | { | ||
94 | char *bp = buf; | ||
95 | int i, ibase, base16 = 0, base10 = 0, clen = 0; | ||
96 | int hb[6], *hp; | ||
97 | char *fmt; | ||
98 | |||
99 | /* | ||
100 | * first try 2-273#2-852-151-014#socket | ||
101 | */ | ||
102 | if ((*buf != '-') && | ||
103 | (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d", | ||
104 | &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) { | ||
105 | cvtbase(1000L, 256, hb, i, out, len); | ||
106 | return; | ||
107 | } | ||
108 | /* | ||
109 | * try form 8E1#0.0.AA.0.5E.E6#socket | ||
110 | */ | ||
111 | if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x", | ||
112 | &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { | ||
113 | cvtbase(256L, 256, hb, i, out, len); | ||
114 | return; | ||
115 | } | ||
116 | /* | ||
117 | * try form 8E1#0:0:AA:0:5E:E6#socket | ||
118 | */ | ||
119 | if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x", | ||
120 | &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { | ||
121 | cvtbase(256L, 256, hb, i, out, len); | ||
122 | return; | ||
123 | } | ||
124 | /* | ||
125 | * This is REALLY stretching it but there was a | ||
126 | * comma notation separting shorts -- definitely non standard | ||
127 | */ | ||
128 | if (1 < (i = sscanf(buf,"%x,%x,%x", | ||
129 | &hb[0], &hb[1], &hb[2]))) { | ||
130 | hb[0] = htons(hb[0]); hb[1] = htons(hb[1]); | ||
131 | hb[2] = htons(hb[2]); | ||
132 | cvtbase(65536L, 256, hb, i, out, len); | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | /* Need to decide if base 10, 16 or 8 */ | ||
137 | while (*bp) switch (*bp++) { | ||
138 | |||
139 | case '0': case '1': case '2': case '3': case '4': case '5': | ||
140 | case '6': case '7': case '-': | ||
141 | break; | ||
142 | |||
143 | case '8': case '9': | ||
144 | base10 = 1; | ||
145 | break; | ||
146 | |||
147 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': | ||
148 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': | ||
149 | base16 = 1; | ||
150 | break; | ||
151 | |||
152 | case 'x': case 'X': | ||
153 | *--bp = '0'; | ||
154 | base16 = 1; | ||
155 | break; | ||
156 | |||
157 | case 'h': case 'H': | ||
158 | base16 = 1; | ||
159 | /* fall into */ | ||
160 | |||
161 | default: | ||
162 | *--bp = 0; /* Ends Loop */ | ||
163 | } | ||
164 | if (base16) { | ||
165 | fmt = "%3x"; | ||
166 | ibase = 4096; | ||
167 | } else if (base10 == 0 && *buf == '0') { | ||
168 | fmt = "%3o"; | ||
169 | ibase = 512; | ||
170 | } else { | ||
171 | fmt = "%3d"; | ||
172 | ibase = 1000; | ||
173 | } | ||
174 | |||
175 | for (bp = buf; *bp++; ) clen++; | ||
176 | if (clen == 0) clen++; | ||
177 | if (clen > 18) clen = 18; | ||
178 | i = ((clen - 1) / 3) + 1; | ||
179 | bp = clen + buf - 3; | ||
180 | hp = hb + i - 1; | ||
181 | |||
182 | while (hp > hb) { | ||
183 | (void)sscanf(bp, fmt, hp); | ||
184 | bp[0] = 0; | ||
185 | hp--; | ||
186 | bp -= 3; | ||
187 | } | ||
188 | (void)sscanf(buf, fmt, hp); | ||
189 | cvtbase((long)ibase, 256, hb, i, out, len); | ||
190 | } | ||
191 | |||
192 | static void | ||
193 | cvtbase(long oldbase, int newbase, int *input, int inlen, | ||
194 | unsigned char *result, int reslen) | ||
195 | { | ||
196 | int d, e; | ||
197 | long sum; | ||
198 | |||
199 | e = 1; | ||
200 | while (e > 0 && reslen > 0) { | ||
201 | d = 0; e = 0; sum = 0; | ||
202 | /* long division: input=input/newbase */ | ||
203 | while (d < inlen) { | ||
204 | sum = sum*oldbase + (long) input[d]; | ||
205 | e += (sum > 0); | ||
206 | input[d++] = sum / newbase; | ||
207 | sum %= newbase; | ||
208 | } | ||
209 | result[--reslen] = sum; /* accumulate remainder */ | ||
210 | } | ||
211 | for (d=0; d < reslen; d++) | ||
212 | result[d] = 0; | ||
213 | } | ||