Commit | Line | Data |
---|---|---|
7bcd1bb8 KB |
1 | /*- |
2 | * Copyright (c) 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | * | |
4d8170e5 | 7 | * @(#)clnp_debug.c 7.11 (Berkeley) %G% |
7bcd1bb8 KB |
8 | */ |
9 | ||
011444fe KS |
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 $ */ | |
011444fe | 38 | |
5548a02f KB |
39 | #include <sys/param.h> |
40 | #include <sys/mbuf.h> | |
41 | #include <sys/domain.h> | |
42 | #include <sys/protosw.h> | |
43 | #include <sys/socket.h> | |
44 | #include <sys/socketvar.h> | |
45 | #include <sys/errno.h> | |
011444fe | 46 | |
5548a02f KB |
47 | #include <net/if.h> |
48 | #include <net/route.h> | |
011444fe | 49 | |
5548a02f KB |
50 | #include <netiso/iso.h> |
51 | #include <netiso/clnp.h> | |
52 | #include <netiso/clnp_stat.h> | |
53 | #include <netiso/argo_debug.h> | |
011444fe KS |
54 | |
55 | #ifdef ARGO_DEBUG | |
56 | ||
57 | #ifdef TESTDEBUG | |
58 | #ifdef notdef | |
59 | struct addr_37 u_37 = { | |
60 | {0x00, 0x02, 0x00, 0x10, 0x20, 0x30, 0x35}, | |
61 | {0x01, 0x02, 0x03, 0x04, 0x50, 0x60, 0x70, 0x80, 0x90} | |
62 | }; | |
63 | struct addr_osinet u_osinet = { | |
64 | {0x00, 0x04}, | |
65 | {0x00, 0x02, 0x00, 0x01, 0x23, 0x42, 0x78, 0x20, 0x01, 0x05, 0x00} | |
66 | }; | |
4d8170e5 | 67 | #endif /* notdef */ |
011444fe KS |
68 | struct addr_rfc986 u_rfc986 = { |
69 | {0x00, 0x06}, | |
70 | {0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11} | |
71 | }; | |
72 | struct addr_rfc986 u_bad = { | |
73 | {0x00, 0x01}, | |
74 | {0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11} | |
75 | }; | |
76 | #include <stdio.h> | |
77 | main() | |
78 | { | |
79 | struct iso_addr a; | |
80 | ||
81 | a.isoa_afi = AFI_37; | |
82 | a.isoa_u.addr_37 = u_37; | |
83 | a.isoa_len = 17; | |
84 | printf("type 37: %s\n", clnp_iso_addrp(&a)); | |
85 | ||
86 | a.isoa_afi = AFI_OSINET; | |
87 | a.isoa_u.addr_osinet = u_osinet; | |
88 | a.isoa_len = 14; | |
89 | printf("type osinet: %s\n", clnp_iso_addrp(&a)); | |
90 | ||
91 | a.isoa_afi = AFI_RFC986; | |
92 | a.isoa_u.addr_rfc986 = u_rfc986; | |
93 | a.isoa_len = 9; | |
94 | printf("type rfc986: %s\n", clnp_iso_addrp(&a)); | |
95 | ||
96 | a.isoa_afi = 12; | |
97 | a.isoa_u.addr_rfc986 = u_rfc986; | |
98 | a.isoa_len = 9; | |
99 | printf("type bad afi: %s\n", clnp_iso_addrp(&a)); | |
100 | ||
101 | a.isoa_afi = AFI_RFC986; | |
102 | a.isoa_u.addr_rfc986 = u_bad; | |
103 | a.isoa_len = 9; | |
104 | printf("type bad idi: %s\n", clnp_iso_addrp(&a)); | |
105 | } | |
4d8170e5 | 106 | #endif /* TESTDEBUG */ |
011444fe KS |
107 | |
108 | unsigned int clnp_debug; | |
109 | static char letters[] = "0123456789abcdef"; | |
110 | ||
111 | /* | |
112 | * Print buffer in hex, return addr of where we left off. | |
113 | * Do not null terminate. | |
114 | */ | |
115 | char * | |
116 | clnp_hexp(src, len, where) | |
117 | char *src; /* src of data to print */ | |
52ac7ba2 | 118 | int len; /* lengthof src */ |
011444fe KS |
119 | char *where; /* where to put data */ |
120 | { | |
121 | int i; | |
122 | ||
123 | for (i=0; i<len; i++) { | |
52ac7ba2 KS |
124 | register int j = ((u_char *)src)[i]; |
125 | *where++ = letters[j >> 4]; | |
126 | *where++ = letters[j & 0x0f]; | |
011444fe KS |
127 | } |
128 | return where; | |
129 | } | |
130 | ||
131 | /* | |
132 | * Return a ptr to a human readable form of an iso addr | |
133 | */ | |
134 | static char iso_addr_b[50]; | |
135 | #define DELIM '.'; | |
136 | ||
137 | char * | |
138 | clnp_iso_addrp(isoa) | |
139 | struct iso_addr *isoa; | |
140 | { | |
141 | char *cp; | |
142 | ||
143 | /* print length */ | |
66c6c4df | 144 | sprintf(iso_addr_b, "[%d] ", isoa->isoa_len); |
011444fe KS |
145 | |
146 | /* set cp to end of what we have */ | |
147 | cp = iso_addr_b; | |
148 | while (*cp) | |
149 | cp++; | |
150 | ||
151 | /* print afi */ | |
a50e2bc0 KS |
152 | cp = clnp_hexp(isoa->isoa_genaddr, (int)isoa->isoa_len, cp); |
153 | #ifdef notdef | |
011444fe KS |
154 | *cp++ = DELIM; |
155 | ||
156 | /* print type specific part */ | |
157 | switch(isoa->isoa_afi) { | |
158 | case AFI_37: | |
159 | cp = clnp_hexp(isoa->t37_idi, ADDR37_IDI_LEN, cp); | |
160 | *cp++ = DELIM; | |
161 | cp = clnp_hexp(isoa->t37_dsp, ADDR37_DSP_LEN, cp); | |
162 | break; | |
163 | ||
164 | /* case AFI_OSINET:*/ | |
165 | case AFI_RFC986: { | |
166 | u_short idi; | |
167 | ||
168 | /* osinet and rfc986 have idi in the same place */ | |
169 | /* print idi */ | |
170 | cp = clnp_hexp(isoa->rfc986_idi, ADDROSINET_IDI_LEN, cp); | |
171 | *cp++ = DELIM; | |
172 | CTOH(isoa->rfc986_idi[0], isoa->rfc986_idi[1], idi); | |
173 | ||
174 | if (idi == IDI_OSINET) { | |
175 | struct ovl_osinet *oosi = (struct ovl_osinet *)isoa; | |
176 | cp = clnp_hexp(oosi->oosi_orgid, OVLOSINET_ORGID_LEN, cp); | |
177 | *cp++ = DELIM; | |
178 | cp = clnp_hexp(oosi->oosi_snetid, OVLOSINET_SNETID_LEN, cp); | |
179 | *cp++ = DELIM; | |
180 | cp = clnp_hexp(oosi->oosi_snpa, OVLOSINET_SNPA_LEN, cp); | |
181 | *cp++ = DELIM; | |
182 | cp = clnp_hexp(oosi->oosi_nsap, OVLOSINET_NSAP_LEN, cp); | |
183 | } else if (idi == IDI_RFC986) { | |
184 | struct ovl_rfc986 *o986 = (struct ovl_rfc986 *)isoa; | |
185 | cp = clnp_hexp(&o986->o986_vers, 1, cp); | |
186 | *cp++ = DELIM; | |
187 | #ifdef vax | |
66c6c4df | 188 | sprintf(cp, "%d.%d.%d.%d.%d", |
011444fe KS |
189 | o986->o986_inetaddr[0] & 0xff, |
190 | o986->o986_inetaddr[1] & 0xff, | |
191 | o986->o986_inetaddr[2] & 0xff, | |
192 | o986->o986_inetaddr[3] & 0xff, | |
193 | o986->o986_upid & 0xff); | |
194 | return(iso_addr_b); | |
195 | #else | |
196 | cp = clnp_hexp(&o986->o986_inetaddr[0], 1, cp); | |
197 | *cp++ = DELIM; | |
198 | cp = clnp_hexp(&o986->o986_inetaddr[1], 1, cp); | |
199 | *cp++ = DELIM; | |
200 | cp = clnp_hexp(&o986->o986_inetaddr[2], 1, cp); | |
201 | *cp++ = DELIM; | |
202 | cp = clnp_hexp(&o986->o986_inetaddr[3], 1, cp); | |
203 | *cp++ = DELIM; | |
204 | cp = clnp_hexp(&o986->o986_upid, 1, cp); | |
4d8170e5 | 205 | #endif /* vax */ |
011444fe KS |
206 | } |
207 | ||
208 | } break; | |
209 | ||
210 | default: | |
211 | *cp++ = '?'; | |
212 | break; | |
213 | } | |
4d8170e5 | 214 | #endif /* notdef */ |
011444fe KS |
215 | *cp = (char)0; |
216 | ||
217 | return(iso_addr_b); | |
218 | } | |
219 | ||
a50e2bc0 KS |
220 | char * |
221 | clnp_saddr_isop(s) | |
222 | register struct sockaddr_iso *s; | |
011444fe | 223 | { |
a50e2bc0 KS |
224 | register char *cp = clnp_iso_addrp(&s->siso_addr); |
225 | ||
226 | while (*cp) cp++; | |
227 | *cp++ = '('; | |
44f52ea5 | 228 | cp = clnp_hexp(TSEL(s), (int)s->siso_tlen, cp); |
a50e2bc0 KS |
229 | *cp++ = ')'; |
230 | *cp++ = 0; | |
231 | return (iso_addr_b); | |
011444fe KS |
232 | } |
233 | ||
4d8170e5 | 234 | #endif /* ARGO_DEBUG */ |