xref: /csrg-svn/sys/netiso/clnp_debug.c (revision 37536)
1 /***********************************************************
2 		Copyright IBM Corporation 1987
3 
4                       All Rights Reserved
5 
6 Permission to use, copy, modify, and distribute this software and its
7 documentation for any purpose and without fee is hereby granted,
8 provided that the above copyright notice appear in all copies and that
9 both that copyright notice and this permission notice appear in
10 supporting documentation, and that the name of IBM not be
11 used in advertising or publicity pertaining to distribution of the
12 software without specific, written prior permission.
13 
14 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
16 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
17 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
19 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20 SOFTWARE.
21 
22 ******************************************************************/
23 
24 /*
25  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
26  */
27 /* $Header: clnp_debug.c,v 4.2 88/06/29 14:58:34 hagens Exp $ */
28 /* $Source: /usr/argo/sys/netargo/RCS/clnp_debug.c,v $ */
29 
30 #ifndef lint
31 static char *rcsid = "$Header: clnp_debug.c,v 4.2 88/06/29 14:58:34 hagens Exp $";
32 #endif lint
33 
34 #include "types.h"
35 #include "param.h"
36 #include "mbuf.h"
37 #include "domain.h"
38 #include "protosw.h"
39 #include "socket.h"
40 #include "socketvar.h"
41 #include "errno.h"
42 
43 #include "../net/if.h"
44 #include "../net/route.h"
45 
46 #include "iso.h"
47 #include "clnp.h"
48 #include "clnp_stat.h"
49 #include "argo_debug.h"
50 
51 #ifdef	ARGO_DEBUG
52 
53 #ifdef	TESTDEBUG
54 #ifdef notdef
55 struct addr_37 u_37 = {
56 	{0x00, 0x02, 0x00, 0x10, 0x20, 0x30, 0x35},
57 	{0x01, 0x02, 0x03, 0x04, 0x50, 0x60, 0x70, 0x80, 0x90}
58 };
59 struct addr_osinet u_osinet = {
60 	{0x00, 0x04},
61 	{0x00, 0x02, 0x00, 0x01, 0x23, 0x42, 0x78, 0x20, 0x01, 0x05, 0x00}
62 };
63 #endif notdef
64 struct addr_rfc986 u_rfc986 = {
65 	{0x00, 0x06},
66 	{0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
67 };
68 struct addr_rfc986 u_bad = {
69 	{0x00, 0x01},
70 	{0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
71 };
72 #include <stdio.h>
73 main()
74 {
75 	struct iso_addr	a;
76 
77 	a.isoa_afi = AFI_37;
78 	a.isoa_u.addr_37 = u_37;
79 	a.isoa_len = 17;
80 	printf("type 37: %s\n", clnp_iso_addrp(&a));
81 
82 	a.isoa_afi = AFI_OSINET;
83 	a.isoa_u.addr_osinet = u_osinet;
84 	a.isoa_len = 14;
85 	printf("type osinet: %s\n", clnp_iso_addrp(&a));
86 
87 	a.isoa_afi = AFI_RFC986;
88 	a.isoa_u.addr_rfc986 = u_rfc986;
89 	a.isoa_len = 9;
90 	printf("type rfc986: %s\n", clnp_iso_addrp(&a));
91 
92 	a.isoa_afi = 12;
93 	a.isoa_u.addr_rfc986 = u_rfc986;
94 	a.isoa_len = 9;
95 	printf("type bad afi: %s\n", clnp_iso_addrp(&a));
96 
97 	a.isoa_afi = AFI_RFC986;
98 	a.isoa_u.addr_rfc986 = u_bad;
99 	a.isoa_len = 9;
100 	printf("type bad idi: %s\n", clnp_iso_addrp(&a));
101 }
102 #endif	TESTDEBUG
103 
104 unsigned int	clnp_debug;
105 static char letters[] = "0123456789abcdef";
106 
107 /*
108  *	Print buffer in hex, return addr of where we left off.
109  *	Do not null terminate.
110  */
111 char *
112 clnp_hexp(src, len, where)
113 char	*src;		/* src of data to print */
114 int		len;		/* lengthof src */
115 char	*where;		/* where to put data */
116 {
117 	int i;
118 
119 	for (i=0; i<len; i++) {
120 		*where++ = letters[src[i] >> 4];
121 		*where++ = letters[src[i] & 0x0f];
122 	}
123 	return where;
124 }
125 
126 /*
127  *	Return a ptr to a human readable form of an iso addr
128  */
129 static char iso_addr_b[50];
130 #define	DELIM	'.';
131 
132 char *
133 clnp_iso_addrp(isoa)
134 struct iso_addr *isoa;
135 {
136 	char	*cp;
137 
138 	/* print length */
139 	clnp_sprintf(iso_addr_b, "[%d] ", isoa->isoa_len);
140 
141 	/* set cp to end of what we have */
142 	cp = iso_addr_b;
143 	while (*cp)
144 		cp++;
145 
146 	/* print afi */
147 	cp = clnp_hexp(isoa->isoa_genaddr, (int)isoa->isoa_len, cp);
148 #ifdef notdef
149 	*cp++ = DELIM;
150 
151 	/* print type specific part */
152 	switch(isoa->isoa_afi) {
153 		case AFI_37:
154 			cp = clnp_hexp(isoa->t37_idi, ADDR37_IDI_LEN, cp);
155 			*cp++ = DELIM;
156 			cp = clnp_hexp(isoa->t37_dsp, ADDR37_DSP_LEN, cp);
157 			break;
158 
159 /* 		case AFI_OSINET:*/
160 		case AFI_RFC986: {
161 			u_short	idi;
162 
163 			/* osinet and rfc986 have idi in the same place */
164 			/* print idi */
165 			cp = clnp_hexp(isoa->rfc986_idi, ADDROSINET_IDI_LEN, cp);
166 			*cp++ = DELIM;
167 			CTOH(isoa->rfc986_idi[0], isoa->rfc986_idi[1], idi);
168 
169 			if (idi == IDI_OSINET) {
170 				struct ovl_osinet *oosi = (struct ovl_osinet *)isoa;
171 				cp = clnp_hexp(oosi->oosi_orgid, OVLOSINET_ORGID_LEN, cp);
172 				*cp++ = DELIM;
173 				cp = clnp_hexp(oosi->oosi_snetid, OVLOSINET_SNETID_LEN, cp);
174 				*cp++ = DELIM;
175 				cp = clnp_hexp(oosi->oosi_snpa, OVLOSINET_SNPA_LEN, cp);
176 				*cp++ = DELIM;
177 				cp = clnp_hexp(oosi->oosi_nsap, OVLOSINET_NSAP_LEN, cp);
178 			} else if (idi == IDI_RFC986) {
179 				struct ovl_rfc986 *o986 = (struct ovl_rfc986 *)isoa;
180 				cp = clnp_hexp(&o986->o986_vers, 1, cp);
181 				*cp++ = DELIM;
182 #ifdef  vax
183 				clnp_sprintf(cp, "%d.%d.%d.%d.%d",
184 				o986->o986_inetaddr[0] & 0xff,
185 				o986->o986_inetaddr[1] & 0xff,
186 				o986->o986_inetaddr[2] & 0xff,
187 				o986->o986_inetaddr[3] & 0xff,
188 				o986->o986_upid & 0xff);
189 				return(iso_addr_b);
190 #else
191 				cp = clnp_hexp(&o986->o986_inetaddr[0], 1, cp);
192 				*cp++ = DELIM;
193 				cp = clnp_hexp(&o986->o986_inetaddr[1], 1, cp);
194 				*cp++ = DELIM;
195 				cp = clnp_hexp(&o986->o986_inetaddr[2], 1, cp);
196 				*cp++ = DELIM;
197 				cp = clnp_hexp(&o986->o986_inetaddr[3], 1, cp);
198 				*cp++ = DELIM;
199 				cp = clnp_hexp(&o986->o986_upid, 1, cp);
200 #endif vax
201 			}
202 
203 		} break;
204 
205 		default:
206 			*cp++ = '?';
207 			break;
208 	}
209 #endif notdef
210 	*cp = (char)0;
211 
212 	return(iso_addr_b);
213 }
214 
215 char *
216 clnp_saddr_isop(s)
217 register struct sockaddr_iso *s;
218 {
219 	register char	*cp = clnp_iso_addrp(&s->siso_addr);
220 
221 	while (*cp) cp++;
222 	*cp++ = '(';
223 	cp = clnp_hexp(TSEL(s), (int)s->siso_tsuffixlen, cp);
224 	*cp++ = ')';
225 	*cp++ = 0;
226 	return (iso_addr_b);
227 }
228 
229 
230 /*
231  *		The following hacks are a trimmed down version of sprintf.
232  */
233 /*VARARGS1*/
234 /*ARGSUSED*/
235 clnp_sprintf(buf, fmt, x1, x2)
236 	register char *buf, *fmt;
237 	unsigned x1, x2;
238 {
239 	clnp_prf(buf, fmt, (unsigned int *)&x1);
240 }
241 
242 clnp_prf(buf, fmt, adx)
243 	register char	*buf;
244 	register char *fmt;
245 	register unsigned int *adx;
246 {
247 	register int b, c, i;
248 	char *s;
249 	char *clnp_printn();
250 
251 loop:
252 	while ((c = *fmt++) != '%') {
253 		if(c == '\0') {
254 			*buf++ = (char)0;
255 			return;
256 		}
257 		*buf++ = c;
258 	}
259 again:
260 	c = *fmt++;
261 	switch (c) {
262 	case 'l':
263 		goto again;
264 	case 'x': case 'X':
265 		b = 16;
266 		goto number;
267 	case 'd': case 'D':
268 	case 'u':		/* what a joke */
269 		b = 10;
270 		goto number;
271 	case 'o': case 'O':
272 		b = 8;
273 number:
274 		buf = clnp_printn((unsigned long)*adx, b, buf);
275 		break;
276 	case 'c':
277 		b = *adx;
278 		for (i = 24; i >= 0; i -= 8)
279 			if (c = (b >> i) & 0x7f)
280 				*buf++ = c;
281 		break;
282 
283 	case 's':
284 		s = (char *)*adx;
285 		while (*s)
286 			*buf++ = *s++;
287 		break;
288 
289 	case '%':
290 		*buf++ = '%';
291 		break;
292 	}
293 	adx++;
294 	goto loop;
295 }
296 
297 char *
298 clnp_printn(n, b, where)
299 unsigned long	n;
300 int		b;
301 char	*where;
302 {
303 	char prbuf[11];
304 	register char *cp;
305 
306 	if (b == 10 && (int)n < 0) {
307 		*where++ = '-';
308 		n = (unsigned)(-(int)n);
309 	}
310 	cp = prbuf;
311 	do {
312 		*cp++ = "0123456789abcdef"[n%b];
313 		n /= b;
314 	} while (n);
315 	do {
316 		*where++ = *--cp;
317 	} while (cp > prbuf);
318 	return(where);
319 }
320 #endif	ARGO_DEBUG
321