source: rtems-libbsd/freebsd/contrib/tcpdump/print-chdlc.c @ 084d4db

4.11
Last change on this file since 084d4db was 8440506, checked in by Chris Johns <chrisj@…>, on 06/15/15 at 07:42:23

Add tcpdump and libpcap.

  • Update the file builder generator to handle generator specific cflags and includes. The tcpdump and libpcap have localised headers and need specific headers paths to see them. There are also module specific flags and these need to be passed to the lex and yacc generators.
  • Add the tcpdump support.
  • Property mode set to 100644
File size: 5.8 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
5 *      The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#ifndef lint
25static const char rcsid[] _U_ =
26    "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.43 2005-11-29 08:56:19 hannes Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tcpdump-stdinc.h>
34
35#include <pcap.h>
36#include <stdio.h>
37
38#include "interface.h"
39#include "addrtoname.h"
40#include "ethertype.h"
41#include "extract.h"
42#include "ppp.h"
43#include "chdlc.h"
44
45static void chdlc_slarp_print(const u_char *, u_int);
46
47const struct tok chdlc_cast_values[] = {
48    { CHDLC_UNICAST, "unicast" },
49    { CHDLC_BCAST, "bcast" },
50    { 0, NULL}
51};
52
53
54/* Standard CHDLC printer */
55u_int
56chdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
57{
58        register u_int length = h->len;
59        register u_int caplen = h->caplen;
60
61        if (caplen < CHDLC_HDRLEN) {
62                printf("[|chdlc]");
63                return (caplen);
64        }
65        return (chdlc_print(p,length));
66}
67
68u_int
69chdlc_print(register const u_char *p, u_int length) {
70        u_int proto;
71
72        proto = EXTRACT_16BITS(&p[2]);
73        if (eflag) {
74                printf("%s, ethertype %s (0x%04x), length %u: ",
75                       tok2str(chdlc_cast_values, "0x%02x", p[0]),
76                       tok2str(ethertype_values, "Unknown", proto),
77                       proto,
78                       length);
79        }
80
81        length -= CHDLC_HDRLEN;
82        p += CHDLC_HDRLEN;
83
84        switch (proto) {
85        case ETHERTYPE_IP:
86                ip_print(gndo, p, length);
87                break;
88#ifdef INET6
89        case ETHERTYPE_IPV6:
90                ip6_print(gndo, p, length);
91                break;
92#endif
93        case CHDLC_TYPE_SLARP:
94                chdlc_slarp_print(p, length);
95                break;
96#if 0
97        case CHDLC_TYPE_CDP:
98                chdlc_cdp_print(p, length);
99                break;
100#endif
101        case ETHERTYPE_MPLS:
102        case ETHERTYPE_MPLS_MULTI:
103                mpls_print(p, length);
104                break;
105        case ETHERTYPE_ISO:
106                /* is the fudge byte set ? lets verify by spotting ISO headers */
107                if (*(p+1) == 0x81 ||
108                    *(p+1) == 0x82 ||
109                    *(p+1) == 0x83)
110                    isoclns_print(p+1, length-1, length-1);
111                else
112                    isoclns_print(p, length, length);
113                break;
114        default:
115                if (!eflag)
116                        printf("unknown CHDLC protocol (0x%04x)", proto);
117                break;
118        }
119
120        return (CHDLC_HDRLEN);
121}
122
123/*
124 * The fixed-length portion of a SLARP packet.
125 */
126struct cisco_slarp {
127        u_int8_t code[4];
128#define SLARP_REQUEST   0
129#define SLARP_REPLY     1
130#define SLARP_KEEPALIVE 2
131        union {
132                struct {
133                        u_int8_t addr[4];
134                        u_int8_t mask[4];
135                } addr;
136                struct {
137                        u_int8_t myseq[4];
138                        u_int8_t yourseq[4];
139                        u_int8_t rel[2];
140                } keep;
141        } un;
142};
143
144#define SLARP_MIN_LEN   14
145#define SLARP_MAX_LEN   18
146
147static void
148chdlc_slarp_print(const u_char *cp, u_int length)
149{
150        const struct cisco_slarp *slarp;
151        u_int sec,min,hrs,days;
152
153        printf("SLARP (length: %u), ",length);
154        if (length < SLARP_MIN_LEN)
155                goto trunc;
156
157        slarp = (const struct cisco_slarp *)cp;
158        TCHECK2(*slarp, SLARP_MIN_LEN);
159        switch (EXTRACT_32BITS(&slarp->code)) {
160        case SLARP_REQUEST:
161                printf("request");
162                /*
163                 * At least according to William "Chops" Westfield's
164                 * message in
165                 *
166                 *      http://www.nethelp.no/net/cisco-hdlc.txt
167                 *
168                 * the address and mask aren't used in requests -
169                 * they're just zero.
170                 */
171                break;
172        case SLARP_REPLY:
173                printf("reply %s/%s",
174                        ipaddr_string(&slarp->un.addr.addr),
175                        ipaddr_string(&slarp->un.addr.mask));
176                break;
177        case SLARP_KEEPALIVE:
178                printf("keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
179                       EXTRACT_32BITS(&slarp->un.keep.myseq),
180                       EXTRACT_32BITS(&slarp->un.keep.yourseq),
181                       EXTRACT_16BITS(&slarp->un.keep.rel));
182
183                if (length >= SLARP_MAX_LEN) { /* uptime-stamp is optional */
184                        cp += SLARP_MIN_LEN;
185                        if (!TTEST2(*cp, 4))
186                                goto trunc;
187                        sec = EXTRACT_32BITS(cp) / 1000;
188                        min = sec / 60; sec -= min * 60;
189                        hrs = min / 60; min -= hrs * 60;
190                        days = hrs / 24; hrs -= days * 24;
191                        printf(", link uptime=%ud%uh%um%us",days,hrs,min,sec);
192                }
193                break;
194        default:
195                printf("0x%02x unknown", EXTRACT_32BITS(&slarp->code));
196                if (vflag <= 1)
197                    print_unknown_data(cp+4,"\n\t",length-4);
198                break;
199        }
200
201        if (SLARP_MAX_LEN < length && vflag)
202                printf(", (trailing junk: %d bytes)", length - SLARP_MAX_LEN);
203        if (vflag > 1)
204            print_unknown_data(cp+4,"\n\t",length-4);
205        return;
206
207trunc:
208        printf("[|slarp]");
209}
210
211
212/*
213 * Local Variables:
214 * c-style: whitesmith
215 * c-basic-offset: 8
216 * End:
217 */
Note: See TracBrowser for help on using the repository browser.