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.11 (Berkeley) 05/25/93 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 <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> 46 47 #include <net/if.h> 48 #include <net/route.h> 49 50 #include <netiso/iso.h> 51 #include <netiso/clnp.h> 52 #include <netiso/clnp_stat.h> 53 #include <netiso/argo_debug.h> 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 }; 67 #endif /* notdef */ 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 } 106 #endif /* TESTDEBUG */ 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 */ 118 int len; /* lengthof src */ 119 char *where; /* where to put data */ 120 { 121 int i; 122 123 for (i=0; i<len; i++) { 124 register int j = ((u_char *)src)[i]; 125 *where++ = letters[j >> 4]; 126 *where++ = letters[j & 0x0f]; 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 */ 144 sprintf(iso_addr_b, "[%d] ", isoa->isoa_len); 145 146 /* set cp to end of what we have */ 147 cp = iso_addr_b; 148 while (*cp) 149 cp++; 150 151 /* print afi */ 152 cp = clnp_hexp(isoa->isoa_genaddr, (int)isoa->isoa_len, cp); 153 #ifdef notdef 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 188 sprintf(cp, "%d.%d.%d.%d.%d", 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); 205 #endif /* vax */ 206 } 207 208 } break; 209 210 default: 211 *cp++ = '?'; 212 break; 213 } 214 #endif /* notdef */ 215 *cp = (char)0; 216 217 return(iso_addr_b); 218 } 219 220 char * 221 clnp_saddr_isop(s) 222 register struct sockaddr_iso *s; 223 { 224 register char *cp = clnp_iso_addrp(&s->siso_addr); 225 226 while (*cp) cp++; 227 *cp++ = '('; 228 cp = clnp_hexp(TSEL(s), (int)s->siso_tlen, cp); 229 *cp++ = ')'; 230 *cp++ = 0; 231 return (iso_addr_b); 232 } 233 234 #endif /* ARGO_DEBUG */ 235