source: rtems-libbsd/freebsd/contrib/tcpdump/print-token.c @ 8440506

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8440506 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.7 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
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 * Hacked version of print-ether.c  Larry Lile <lile@stdio.com>
24 *
25 * Further tweaked to more closely resemble print-fddi.c
26 *      Guy Harris <guy@alum.mit.edu>
27 *
28 * $FreeBSD$
29 */
30#ifndef lint
31static const char rcsid[] _U_ =
32    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.27 2005-11-13 12:12:43 guy Exp $";
33#endif
34
35#ifdef HAVE_CONFIG_H
36#include "config.h"
37#endif
38
39#include <tcpdump-stdinc.h>
40
41#include <pcap.h>
42#include <stdio.h>
43#include <string.h>
44
45#include "interface.h"
46#include "extract.h"
47#include "addrtoname.h"
48#include "ethertype.h"
49
50#include "ether.h"
51#include "token.h"
52
53/* Extract src, dst addresses */
54static inline void
55extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst)
56{
57        memcpy(fdst, (const char *)trp->token_dhost, 6);
58        memcpy(fsrc, (const char *)trp->token_shost, 6);
59}
60
61/*
62 * Print the TR MAC header
63 */
64static inline void
65token_hdr_print(register const struct token_header *trp, register u_int length,
66           register const u_char *fsrc, register const u_char *fdst)
67{
68        const char *srcname, *dstname;
69
70        srcname = etheraddr_string(fsrc);
71        dstname = etheraddr_string(fdst);
72
73        if (vflag)
74                (void) printf("%02x %02x %s %s %d: ",
75                       trp->token_ac,
76                       trp->token_fc,
77                       srcname, dstname,
78                       length);
79        else
80                printf("%s %s %d: ", srcname, dstname, length);
81}
82
83static const char *broadcast_indicator[] = {
84        "Non-Broadcast", "Non-Broadcast",
85        "Non-Broadcast", "Non-Broadcast",
86        "All-routes",    "All-routes",
87        "Single-route",  "Single-route"
88};
89
90static const char *direction[] = {
91        "Forward", "Backward"
92};
93
94static const char *largest_frame[] = {
95        "516",
96        "1500",
97        "2052",
98        "4472",
99        "8144",
100        "11407",
101        "17800",
102        "??"
103};
104
105u_int
106token_print(const u_char *p, u_int length, u_int caplen)
107{
108        const struct token_header *trp;
109        u_short extracted_ethertype;
110        struct ether_header ehdr;
111        u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
112        int seg;
113
114        trp = (const struct token_header *)p;
115
116        if (caplen < TOKEN_HDRLEN) {
117                printf("[|token-ring]");
118                return hdr_len;
119        }
120
121        /*
122         * Get the TR addresses into a canonical form
123         */
124        extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr));
125
126        /* Adjust for source routing information in the MAC header */
127        if (IS_SOURCE_ROUTED(trp)) {
128                /* Clear source-routed bit */
129                *ESRC(&ehdr) &= 0x7f;
130
131                if (eflag)
132                        token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
133
134                if (caplen < TOKEN_HDRLEN + 2) {
135                        printf("[|token-ring]");
136                        return hdr_len;
137                }
138                route_len = RIF_LENGTH(trp);
139                hdr_len += route_len;
140                if (caplen < hdr_len) {
141                        printf("[|token-ring]");
142                        return hdr_len;
143                }
144                if (vflag) {
145                        printf("%s ", broadcast_indicator[BROADCAST(trp)]);
146                        printf("%s", direction[DIRECTION(trp)]);
147
148                        for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
149                                printf(" [%d:%d]", RING_NUMBER(trp, seg),
150                                    BRIDGE_NUMBER(trp, seg));
151                } else {
152                        printf("rt = %x", EXTRACT_16BITS(&trp->token_rcf));
153
154                        for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
155                                printf(":%x", EXTRACT_16BITS(&trp->token_rseg[seg]));
156                }
157                printf(" (%s) ", largest_frame[LARGEST_FRAME(trp)]);
158        } else {
159                if (eflag)
160                        token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr));
161        }
162
163        /* Skip over token ring MAC header and routing information */
164        length -= hdr_len;
165        p += hdr_len;
166        caplen -= hdr_len;
167
168        /* Frame Control field determines interpretation of packet */
169        if (FRAME_TYPE(trp) == TOKEN_FC_LLC) {
170                /* Try to print the LLC-layer header & higher layers */
171                if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr),
172                    &extracted_ethertype) == 0) {
173                        /* ether_type not known, print raw packet */
174                        if (!eflag)
175                                token_hdr_print(trp,
176                                    length + TOKEN_HDRLEN + route_len,
177                                    ESRC(&ehdr), EDST(&ehdr));
178                        if (extracted_ethertype) {
179                                printf("(LLC %s) ",
180                        etherproto_string(htons(extracted_ethertype)));
181                        }
182                        if (!suppress_default_print)
183                                default_print(p, caplen);
184                }
185        } else {
186                /* Some kinds of TR packet we cannot handle intelligently */
187                /* XXX - dissect MAC packets if frame type is 0 */
188                if (!eflag)
189                        token_hdr_print(trp, length + TOKEN_HDRLEN + route_len,
190                            ESRC(&ehdr), EDST(&ehdr));
191                if (!suppress_default_print)
192                        default_print(p, caplen);
193        }
194        return (hdr_len);
195}
196
197/*
198 * This is the top level routine of the printer.  'p' points
199 * to the TR header of the packet, 'h->ts' is the timestamp,
200 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
201 * is the number of bytes actually captured.
202 */
203u_int
204token_if_print(const struct pcap_pkthdr *h, const u_char *p)
205{
206        return (token_print(p, h->len, h->caplen));
207}
Note: See TracBrowser for help on using the repository browser.