1 /* $NetBSD: clnp_debug.c,v 1.18 2007/02/17 22:34:16 dyoung Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)clnp_debug.c 8.1 (Berkeley) 6/10/93
34 /***********************************************************
35 Copyright IBM Corporation 1987
39 Permission to use, copy, modify, and distribute this software and its
40 documentation for any purpose and without fee is hereby granted,
41 provided that the above copyright notice appear in all copies and that
42 both that copyright notice and this permission notice appear in
43 supporting documentation, and that the name of IBM not be
44 used in advertising or publicity pertaining to distribution of the
45 software without specific, written prior permission.
47 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
48 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
49 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
50 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
51 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
52 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 ******************************************************************/
58 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
61 #include <sys/cdefs.h>
62 __KERNEL_RCSID(0, "$NetBSD: clnp_debug.c,v 1.18 2007/02/17 22:34:16 dyoung Exp $");
64 #include <sys/param.h>
66 #include <sys/domain.h>
67 #include <sys/protosw.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
70 #include <sys/errno.h>
71 #include <sys/systm.h>
74 #include <net/route.h>
76 #include <netiso/iso.h>
77 #include <netiso/clnp.h>
78 #include <netiso/clnp_stat.h>
79 #include <netiso/argo_debug.h>
85 struct addr_37 u_37
= {
86 {0x00, 0x02, 0x00, 0x10, 0x20, 0x30, 0x35},
87 {0x01, 0x02, 0x03, 0x04, 0x50, 0x60, 0x70, 0x80, 0x90}
89 struct addr_osinet u_osinet
= {
91 {0x00, 0x02, 0x00, 0x01, 0x23, 0x42, 0x78, 0x20, 0x01, 0x05, 0x00}
94 struct addr_rfc986 u_rfc986
= {
96 {0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
98 struct addr_rfc986 u_bad
= {
100 {0x01, 0xc0, 0x0c, 0x0c, 0xab, 0x11}
111 a
.isoa_u
.addr_37
= u_37
;
113 printf("type 37: %s\n", clnp_iso_addrp(&a
));
115 a
.isoa_afi
= AFI_OSINET
;
116 a
.isoa_u
.addr_osinet
= u_osinet
;
118 printf("type osinet: %s\n", clnp_iso_addrp(&a
));
120 a
.isoa_afi
= AFI_RFC986
;
121 a
.isoa_u
.addr_rfc986
= u_rfc986
;
123 printf("type rfc986: %s\n", clnp_iso_addrp(&a
));
126 a
.isoa_u
.addr_rfc986
= u_rfc986
;
128 printf("type bad afi: %s\n", clnp_iso_addrp(&a
));
130 a
.isoa_afi
= AFI_RFC986
;
131 a
.isoa_u
.addr_rfc986
= u_bad
;
133 printf("type bad idi: %s\n", clnp_iso_addrp(&a
));
136 #endif /* TESTDEBUG */
138 unsigned int clnp_debug
;
140 char *clnp_hexp (const char *, int, char *);
141 char *clnp_iso_addrp(const struct iso_addr
*);
142 char *clnp_saddr_isop(const struct sockaddr_iso
*);
145 * Print buffer in hex, return addr of where we left off.
146 * Do not null terminate.
149 clnp_hexp(const char *src
, int len
, char *where
)
153 for (i
= 0; i
< len
; i
++) {
154 int j
= ((const u_char
*) src
)[i
];
155 *where
++ = hexdigits
[j
>> 4];
156 *where
++ = hexdigits
[j
& 0x0f];
162 * Return a ptr to a human readable form of an iso addr
164 static char iso_addr_b
[50];
168 clnp_iso_addrp(const struct iso_addr
*isoa
)
176 snprintf(iso_addr_b
, sizeof(iso_addr_b
), "[%d] ", isoa
->isoa_len
);
178 /* set cp to end of what we have */
184 cp
= clnp_hexp(isoa
->isoa_genaddr
, (int) isoa
->isoa_len
, cp
);
188 /* print type specific part */
189 switch (isoa
->isoa_afi
) {
191 cp
= clnp_hexp(isoa
->t37_idi
, ADDR37_IDI_LEN
, cp
);
193 cp
= clnp_hexp(isoa
->t37_dsp
, ADDR37_DSP_LEN
, cp
);
196 /* case AFI_OSINET: */
199 /* osinet and rfc986 have idi in the same place */
201 cp
= clnp_hexp(isoa
->rfc986_idi
,
202 ADDROSINET_IDI_LEN
, cp
);
204 CTOH(isoa
->rfc986_idi
[0], isoa
->rfc986_idi
[1], idi
);
206 if (idi
== IDI_OSINET
) {
207 struct ovl_osinet
*oosi
= (struct ovl_osinet
*) isoa
;
208 cp
= clnp_hexp(oosi
->oosi_orgid
,
209 OVLOSINET_ORGID_LEN
, cp
);
211 cp
= clnp_hexp(oosi
->oosi_snetid
,
212 OVLOSINET_SNETID_LEN
, cp
);
214 cp
= clnp_hexp(oosi
->oosi_snpa
, OVLOSINET_SNPA_LEN
, cp
);
216 cp
= clnp_hexp(oosi
->oosi_nsap
, OVLOSINET_NSAP_LEN
, cp
);
217 } else if (idi
== IDI_RFC986
) {
218 struct ovl_rfc986
*o986
= (struct ovl_rfc986
*) isoa
;
219 cp
= clnp_hexp(&o986
->o986_vers
, 1, cp
);
222 sprintf(cp
, "%d.%d.%d.%d.%d",
223 o986
->o986_inetaddr
[0] & 0xff,
224 o986
->o986_inetaddr
[1] & 0xff,
225 o986
->o986_inetaddr
[2] & 0xff,
226 o986
->o986_inetaddr
[3] & 0xff,
227 o986
->o986_upid
& 0xff);
230 cp
= clnp_hexp(&o986
->o986_inetaddr
[0], 1, cp
);
232 cp
= clnp_hexp(&o986
->o986_inetaddr
[1], 1, cp
);
234 cp
= clnp_hexp(&o986
->o986_inetaddr
[2], 1, cp
);
236 cp
= clnp_hexp(&o986
->o986_inetaddr
[3], 1, cp
);
238 cp
= clnp_hexp(&o986
->o986_upid
, 1, cp
);
254 clnp_saddr_isop(const struct sockaddr_iso
*s
)
256 char *cp
= clnp_iso_addrp(&s
->siso_addr
);
261 cp
= clnp_hexp(TSEL(s
), (int) s
->siso_tlen
, cp
);
267 #endif /* ARGO_DEBUG */