xref: /original-bsd/sys/netiso/clnp_debug.c (revision fcafb5d3)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)clnp_debug.c	7.9 (Berkeley) 02/14/92
8  */
9 
10 /***********************************************************
11 		Copyright IBM Corporation 1987
12 
13                       All Rights Reserved
14 
15 Permission to use, copy, modify, and distribute this software and its
16 documentation for any purpose and without fee is hereby granted,
17 provided that the above copyright notice appear in all copies and that
18 both that copyright notice and this permission notice appear in
19 supporting documentation, and that the name of IBM not be
20 used in advertising or publicity pertaining to distribution of the
21 software without specific, written prior permission.
22 
23 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 SOFTWARE.
30 
31 ******************************************************************/
32 
33 /*
34  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
35  */
36 /* $Header: clnp_debug.c,v 4.2 88/06/29 14:58:34 hagens Exp $ */
37 /* $Source: /usr/argo/sys/netargo/RCS/clnp_debug.c,v $ */
38 
39 #include "types.h"
40 #include "param.h"
41 #include "mbuf.h"
42 #include "domain.h"
43 #include "protosw.h"
44 #include "socket.h"
45 #include "socketvar.h"
46 #include "errno.h"
47 
48 #include "../net/if.h"
49 #include "../net/route.h"
50 
51 #include "iso.h"
52 #include "clnp.h"
53 #include "clnp_stat.h"
54 #include "argo_debug.h"
55 
56 #ifdef	ARGO_DEBUG
57 
58 #ifdef	TESTDEBUG
59 #ifdef notdef
60 struct addr_37 u_37 = {
61 	{0x00, 0x02, 0x00, 0x10, 0x20, 0x30, 0x35},
62 	{0x01, 0x02, 0x03, 0x04, 0x50, 0x60, 0x70, 0x80, 0x90}
63 };
64 struct addr_osinet u_osinet = {
65 	{0x00, 0x04},
66 	{0x00, 0x02, 0x00, 0x01, 0x23, 0x42, 0x78, 0x20, 0x01, 0x05, 0x00}
67 };
68 #endif notdef
69 struct addr_rfc986 u_rfc986 = {
70 	{0x00, 0x06},
71 	{0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
72 };
73 struct addr_rfc986 u_bad = {
74 	{0x00, 0x01},
75 	{0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
76 };
77 #include <stdio.h>
78 main()
79 {
80 	struct iso_addr	a;
81 
82 	a.isoa_afi = AFI_37;
83 	a.isoa_u.addr_37 = u_37;
84 	a.isoa_len = 17;
85 	printf("type 37: %s\n", clnp_iso_addrp(&a));
86 
87 	a.isoa_afi = AFI_OSINET;
88 	a.isoa_u.addr_osinet = u_osinet;
89 	a.isoa_len = 14;
90 	printf("type osinet: %s\n", clnp_iso_addrp(&a));
91 
92 	a.isoa_afi = AFI_RFC986;
93 	a.isoa_u.addr_rfc986 = u_rfc986;
94 	a.isoa_len = 9;
95 	printf("type rfc986: %s\n", clnp_iso_addrp(&a));
96 
97 	a.isoa_afi = 12;
98 	a.isoa_u.addr_rfc986 = u_rfc986;
99 	a.isoa_len = 9;
100 	printf("type bad afi: %s\n", clnp_iso_addrp(&a));
101 
102 	a.isoa_afi = AFI_RFC986;
103 	a.isoa_u.addr_rfc986 = u_bad;
104 	a.isoa_len = 9;
105 	printf("type bad idi: %s\n", clnp_iso_addrp(&a));
106 }
107 #endif	TESTDEBUG
108 
109 unsigned int	clnp_debug;
110 static char letters[] = "0123456789abcdef";
111 
112 /*
113  *	Print buffer in hex, return addr of where we left off.
114  *	Do not null terminate.
115  */
116 char *
117 clnp_hexp(src, len, where)
118 char	*src;		/* src of data to print */
119 int		len;				/* lengthof src */
120 char	*where;		/* where to put data */
121 {
122 	int i;
123 
124 	for (i=0; i<len; i++) {
125 		register int j = ((u_char *)src)[i];
126 		*where++ = letters[j >> 4];
127 		*where++ = letters[j & 0x0f];
128 	}
129 	return where;
130 }
131 
132 /*
133  *	Return a ptr to a human readable form of an iso addr
134  */
135 static char iso_addr_b[50];
136 #define	DELIM	'.';
137 
138 char *
139 clnp_iso_addrp(isoa)
140 struct iso_addr *isoa;
141 {
142 	char	*cp;
143 
144 	/* print length */
145 	sprintf(iso_addr_b, "[%d] ", isoa->isoa_len);
146 
147 	/* set cp to end of what we have */
148 	cp = iso_addr_b;
149 	while (*cp)
150 		cp++;
151 
152 	/* print afi */
153 	cp = clnp_hexp(isoa->isoa_genaddr, (int)isoa->isoa_len, cp);
154 #ifdef notdef
155 	*cp++ = DELIM;
156 
157 	/* print type specific part */
158 	switch(isoa->isoa_afi) {
159 		case AFI_37:
160 			cp = clnp_hexp(isoa->t37_idi, ADDR37_IDI_LEN, cp);
161 			*cp++ = DELIM;
162 			cp = clnp_hexp(isoa->t37_dsp, ADDR37_DSP_LEN, cp);
163 			break;
164 
165 /* 		case AFI_OSINET:*/
166 		case AFI_RFC986: {
167 			u_short	idi;
168 
169 			/* osinet and rfc986 have idi in the same place */
170 			/* print idi */
171 			cp = clnp_hexp(isoa->rfc986_idi, ADDROSINET_IDI_LEN, cp);
172 			*cp++ = DELIM;
173 			CTOH(isoa->rfc986_idi[0], isoa->rfc986_idi[1], idi);
174 
175 			if (idi == IDI_OSINET) {
176 				struct ovl_osinet *oosi = (struct ovl_osinet *)isoa;
177 				cp = clnp_hexp(oosi->oosi_orgid, OVLOSINET_ORGID_LEN, cp);
178 				*cp++ = DELIM;
179 				cp = clnp_hexp(oosi->oosi_snetid, OVLOSINET_SNETID_LEN, cp);
180 				*cp++ = DELIM;
181 				cp = clnp_hexp(oosi->oosi_snpa, OVLOSINET_SNPA_LEN, cp);
182 				*cp++ = DELIM;
183 				cp = clnp_hexp(oosi->oosi_nsap, OVLOSINET_NSAP_LEN, cp);
184 			} else if (idi == IDI_RFC986) {
185 				struct ovl_rfc986 *o986 = (struct ovl_rfc986 *)isoa;
186 				cp = clnp_hexp(&o986->o986_vers, 1, cp);
187 				*cp++ = DELIM;
188 #ifdef  vax
189 				sprintf(cp, "%d.%d.%d.%d.%d",
190 				o986->o986_inetaddr[0] & 0xff,
191 				o986->o986_inetaddr[1] & 0xff,
192 				o986->o986_inetaddr[2] & 0xff,
193 				o986->o986_inetaddr[3] & 0xff,
194 				o986->o986_upid & 0xff);
195 				return(iso_addr_b);
196 #else
197 				cp = clnp_hexp(&o986->o986_inetaddr[0], 1, cp);
198 				*cp++ = DELIM;
199 				cp = clnp_hexp(&o986->o986_inetaddr[1], 1, cp);
200 				*cp++ = DELIM;
201 				cp = clnp_hexp(&o986->o986_inetaddr[2], 1, cp);
202 				*cp++ = DELIM;
203 				cp = clnp_hexp(&o986->o986_inetaddr[3], 1, cp);
204 				*cp++ = DELIM;
205 				cp = clnp_hexp(&o986->o986_upid, 1, cp);
206 #endif vax
207 			}
208 
209 		} break;
210 
211 		default:
212 			*cp++ = '?';
213 			break;
214 	}
215 #endif notdef
216 	*cp = (char)0;
217 
218 	return(iso_addr_b);
219 }
220 
221 char *
222 clnp_saddr_isop(s)
223 register struct sockaddr_iso *s;
224 {
225 	register char	*cp = clnp_iso_addrp(&s->siso_addr);
226 
227 	while (*cp) cp++;
228 	*cp++ = '(';
229 	cp = clnp_hexp(TSEL(s), (int)s->siso_tlen, cp);
230 	*cp++ = ')';
231 	*cp++ = 0;
232 	return (iso_addr_b);
233 }
234 
235 #endif	ARGO_DEBUG
236