add ssize_t, required by POSIX 1003.1
[unix-history] / usr / src / sys / netiso / clnp_debug.c
CommitLineData
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 *
fc380c2d 7 * @(#)clnp_debug.c 7.8 (Berkeley) %G%
7bcd1bb8
KB
8 */
9
011444fe
KS
10/***********************************************************
11 Copyright IBM Corporation 1987
12
13 All Rights Reserved
14
15Permission to use, copy, modify, and distribute this software and its
16documentation for any purpose and without fee is hereby granted,
17provided that the above copyright notice appear in all copies and that
18both that copyright notice and this permission notice appear in
19supporting documentation, and that the name of IBM not be
20used in advertising or publicity pertaining to distribution of the
21software without specific, written prior permission.
22
23IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29SOFTWARE.
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
e663c139
KM
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"
011444fe
KS
47
48#include "../net/if.h"
49#include "../net/route.h"
50
a50e2bc0
KS
51#include "iso.h"
52#include "clnp.h"
53#include "clnp_stat.h"
54#include "argo_debug.h"
011444fe
KS
55
56#ifdef ARGO_DEBUG
57
58#ifdef TESTDEBUG
59#ifdef notdef
60struct addr_37 u_37 = {
61 {0x00, 0x02, 0x00, 0x10, 0x20, 0x30, 0x35},
62 {0x01, 0x02, 0x03, 0x04, 0x50, 0x60, 0x70, 0x80, 0x90}
63};
64struct addr_osinet u_osinet = {
65 {0x00, 0x04},
66 {0x00, 0x02, 0x00, 0x01, 0x23, 0x42, 0x78, 0x20, 0x01, 0x05, 0x00}
67};
68#endif notdef
69struct addr_rfc986 u_rfc986 = {
70 {0x00, 0x06},
71 {0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
72};
73struct addr_rfc986 u_bad = {
74 {0x00, 0x01},
75 {0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
76};
77#include <stdio.h>
78main()
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
109unsigned int clnp_debug;
110static char letters[] = "0123456789abcdef";
111
112/*
113 * Print buffer in hex, return addr of where we left off.
114 * Do not null terminate.
115 */
116char *
117clnp_hexp(src, len, where)
118char *src; /* src of data to print */
119int len; /* lengthof src */
120char *where; /* where to put data */
121{
122 int i;
123
124 for (i=0; i<len; i++) {
125 *where++ = letters[src[i] >> 4];
126 *where++ = letters[src[i] & 0x0f];
127 }
128 return where;
129}
130
131/*
132 * Return a ptr to a human readable form of an iso addr
133 */
134static char iso_addr_b[50];
135#define DELIM '.';
136
137char *
138clnp_iso_addrp(isoa)
139struct 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);
205#endif vax
206 }
207
208 } break;
209
210 default:
211 *cp++ = '?';
212 break;
213 }
a50e2bc0 214#endif notdef
011444fe
KS
215 *cp = (char)0;
216
217 return(iso_addr_b);
218}
219
a50e2bc0
KS
220char *
221clnp_saddr_isop(s)
222register 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
011444fe 234#endif ARGO_DEBUG