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 "../h/types.h" 35 #include "../h/param.h" 36 #include "../h/mbuf.h" 37 #include "../h/domain.h" 38 #include "../h/protosw.h" 39 #include "../h/socket.h" 40 #include "../h/socketvar.h" 41 #include "../h/errno.h" 42 43 #include "../net/if.h" 44 #include "../net/route.h" 45 46 #include "../netiso/iso.h" 47 #include "../netiso/clnp.h" 48 #include "../netiso/clnp_stat.h" 49 #include "../netiso/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_afi, 1, cp); 148 *cp++ = DELIM; 149 150 /* print type specific part */ 151 switch(isoa->isoa_afi) { 152 case AFI_37: 153 cp = clnp_hexp(isoa->t37_idi, ADDR37_IDI_LEN, cp); 154 *cp++ = DELIM; 155 cp = clnp_hexp(isoa->t37_dsp, ADDR37_DSP_LEN, cp); 156 break; 157 158 /* case AFI_OSINET:*/ 159 case AFI_RFC986: { 160 u_short idi; 161 162 /* osinet and rfc986 have idi in the same place */ 163 /* print idi */ 164 cp = clnp_hexp(isoa->rfc986_idi, ADDROSINET_IDI_LEN, cp); 165 *cp++ = DELIM; 166 CTOH(isoa->rfc986_idi[0], isoa->rfc986_idi[1], idi); 167 168 if (idi == IDI_OSINET) { 169 struct ovl_osinet *oosi = (struct ovl_osinet *)isoa; 170 cp = clnp_hexp(oosi->oosi_orgid, OVLOSINET_ORGID_LEN, cp); 171 *cp++ = DELIM; 172 cp = clnp_hexp(oosi->oosi_snetid, OVLOSINET_SNETID_LEN, cp); 173 *cp++ = DELIM; 174 cp = clnp_hexp(oosi->oosi_snpa, OVLOSINET_SNPA_LEN, cp); 175 *cp++ = DELIM; 176 cp = clnp_hexp(oosi->oosi_nsap, OVLOSINET_NSAP_LEN, cp); 177 } else if (idi == IDI_RFC986) { 178 struct ovl_rfc986 *o986 = (struct ovl_rfc986 *)isoa; 179 cp = clnp_hexp(&o986->o986_vers, 1, cp); 180 *cp++ = DELIM; 181 #ifdef vax 182 clnp_sprintf(cp, "%d.%d.%d.%d.%d", 183 o986->o986_inetaddr[0] & 0xff, 184 o986->o986_inetaddr[1] & 0xff, 185 o986->o986_inetaddr[2] & 0xff, 186 o986->o986_inetaddr[3] & 0xff, 187 o986->o986_upid & 0xff); 188 return(iso_addr_b); 189 #else 190 cp = clnp_hexp(&o986->o986_inetaddr[0], 1, cp); 191 *cp++ = DELIM; 192 cp = clnp_hexp(&o986->o986_inetaddr[1], 1, cp); 193 *cp++ = DELIM; 194 cp = clnp_hexp(&o986->o986_inetaddr[2], 1, cp); 195 *cp++ = DELIM; 196 cp = clnp_hexp(&o986->o986_inetaddr[3], 1, cp); 197 *cp++ = DELIM; 198 cp = clnp_hexp(&o986->o986_upid, 1, cp); 199 #endif vax 200 } 201 202 } break; 203 204 default: 205 *cp++ = '?'; 206 break; 207 } 208 *cp = (char)0; 209 210 return(iso_addr_b); 211 } 212 213 #define MAX_COLUMNS 8 214 /* 215 * Dump the buffer to the screen in a readable format. Format is: 216 * 217 * hex/dec where hex is the hex format, dec is the decimal format. 218 * columns of hex/dec numbers will be printed, followed by the 219 * character representations (if printable). 220 */ 221 dump_buf(buf, len) 222 char *buf; 223 int len; 224 { 225 int i,j; 226 227 printf("Dump buf 0x%x len 0x%x\n", buf, len); 228 for (i = 0; i < len; i += MAX_COLUMNS) { 229 printf("+%d:\t", i); 230 for (j = 0; j < MAX_COLUMNS; j++) { 231 if (i + j < len) { 232 printf("%x/%d\t", buf[i+j]&0xff, buf[i+j]); 233 } else { 234 printf(" "); 235 } 236 } 237 238 for (j = 0; j < MAX_COLUMNS; j++) { 239 if (i + j < len) { 240 if (((buf[i+j]) > 31) && ((buf[i+j]) < 128)) 241 printf("%c", buf[i+j]&0xff); 242 else 243 printf("."); 244 } 245 } 246 printf("\n"); 247 } 248 } 249 250 251 /* 252 * The following hacks are a trimmed down version of sprintf. 253 */ 254 /*VARARGS1*/ 255 clnp_sprintf(buf, fmt, x1, x2) 256 register char *fmt; 257 unsigned x1, x2; 258 { 259 clnp_prf(buf, fmt, &x1, 0); 260 } 261 262 clnp_prf(buf, fmt, adx, dummy) 263 register char *buf; 264 register char *fmt; 265 register unsigned int *adx; 266 int dummy; 267 { 268 register int b, c, i; 269 char *s; 270 char *clnp_printn(); 271 272 loop: 273 while ((c = *fmt++) != '%') { 274 if(c == '\0') { 275 *buf++ = (char)0; 276 return; 277 } 278 *buf++ = c; 279 } 280 again: 281 c = *fmt++; 282 switch (c) { 283 case 'l': 284 goto again; 285 case 'x': case 'X': 286 b = 16; 287 goto number; 288 case 'd': case 'D': 289 case 'u': /* what a joke */ 290 b = 10; 291 goto number; 292 case 'o': case 'O': 293 b = 8; 294 number: 295 buf = clnp_printn((unsigned long)*adx, b, buf); 296 break; 297 case 'c': 298 b = *adx; 299 for (i = 24; i >= 0; i -= 8) 300 if (c = (b >> i) & 0x7f) 301 *buf++ = c; 302 break; 303 304 case 's': 305 s = (char *)*adx; 306 while (*s) 307 *buf++ = *s++; 308 break; 309 310 case '%': 311 *buf++ = '%'; 312 break; 313 } 314 adx++; 315 goto loop; 316 } 317 318 char * 319 clnp_printn(n, b, where) 320 unsigned long n; 321 int b; 322 char *where; 323 { 324 char prbuf[11]; 325 register char *cp; 326 327 if (b == 10 && (int)n < 0) { 328 *where++ = '-'; 329 n = (unsigned)(-(int)n); 330 } 331 cp = prbuf; 332 do { 333 *cp++ = "0123456789abcdef"[n%b]; 334 n /= b; 335 } while (n); 336 do { 337 *where++ = *--cp; 338 } while (cp > prbuf); 339 return(where); 340 } 341 #endif ARGO_DEBUG 342