Annotation of 43BSDReno/sys/netiso/clnp_debug.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.