Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / i4b / isdntrace / unknownl3.c
1 /*
2  * Copyright (c) 2000 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      unknownl3.c - print L3 packets with unknown PD
28  *      ----------------------------------------------
29  *
30  *      $Id: unknownl3.c,v 1.2 2000/02/13 15:26:52 hm Exp $
31  *
32  * $FreeBSD: src/usr.sbin/i4b/isdntrace/unknownl3.c,v 1.1.2.1 2001/08/01 23:07:06 obrien Exp $
33  * $DragonFly: src/usr.sbin/i4b/isdntrace/unknownl3.c,v 1.2 2003/06/17 04:29:55 dillon Exp $
34  *
35  *      last edit-date: [Sun Feb 13 14:16:44 2000]
36  *
37  *---------------------------------------------------------------------------*/
38
39 #include "trace.h"
40
41 /*---------------------------------------------------------------------------*
42  *      decode unknown protocol
43  *---------------------------------------------------------------------------*/
44 void
45 decode_unknownl3(char *pbuf, int n, int off, unsigned char *buf, int raw)
46 {
47         int pd;
48         int j;
49         int i;
50
51         if(n <= 0)
52                 return;
53
54         *pbuf = '\0';
55         
56         if(raw)
57         {
58                 for (i = 0; i < n; i += 16)
59                 {
60                         sprintf((pbuf+strlen(pbuf)),"Dump:%.3d  ", i+off);
61                         for (j = 0; j < 16; j++)
62                                 if (i + j < n)
63                                         sprintf((pbuf+strlen(pbuf)),"%02x ", buf[i + j]);
64                                 else
65                                         sprintf((pbuf+strlen(pbuf)),"   ");
66                         sprintf((pbuf+strlen(pbuf)),"      ");
67                         for (j = 0; j < 16 && i + j < n; j++)
68                                 if (isprint(buf[i + j]))
69                                         sprintf((pbuf+strlen(pbuf)),"%c", buf[i + j]);
70                                 else
71                                         sprintf((pbuf+strlen(pbuf)),".");
72                         sprintf((pbuf+strlen(pbuf)),"\n");
73                 }
74         }
75
76         i = 0;
77                 
78         /* protocol discriminator */
79
80         pd = buf[i];
81
82         sprintf((pbuf+strlen(pbuf)), "PD%02X: ", pd);   
83
84         if(pd >= 0x00 && pd <= 0x07)
85                 sprintf((pbuf+strlen(pbuf)), "pd=User-User (0x%02x)",pd);
86         else if(pd == 0x08)
87                 sprintf((pbuf+strlen(pbuf)), "pd=Q.931/I.451");
88         else if(pd >= 0x10 && pd <= 0x3f)
89                 sprintf((pbuf+strlen(pbuf)), "pd=Other Layer 3 or X.25 (0x%02x)",pd);
90         else if(pd >= 0x40 && pd <= 0x4f)
91                 sprintf((pbuf+strlen(pbuf)), "pd=National Use (0x%02x)",pd);
92         else if(pd >= 0x50 && pd <= 0xfe)
93                 sprintf((pbuf+strlen(pbuf)), "pd=Other Layer 3 or X.25 (0x%02x)",pd);
94         else
95                 sprintf((pbuf+strlen(pbuf)), "pd=Reserved (0x%02x)",pd);
96
97         sprintf((pbuf+strlen(pbuf)), "\n     [");       
98         for(j = 0; j < (n-i); j++)
99         {
100                 sprintf((pbuf+strlen(pbuf)),"0x%02x ", buf[j+i]);
101         }
102         
103         sprintf((pbuf+strlen(pbuf)),"]\n");
104 }
105
106 /* EOF */
107