Skip to content

Commit 1cead82

Browse files
committed
reworked print-ether to use netdissect
1 parent 5341239 commit 1cead82

File tree

13 files changed

+82
-72
lines changed

13 files changed

+82
-72
lines changed

interface.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ extern void hex_and_ascii_print(const char *, const u_char *, u_int);
162162
extern void hex_print_with_offset(const char *, const u_char *, u_int, u_int);
163163
extern void hex_print(const char *, const u_char *, u_int);
164164
extern void telnet_print(const u_char *, u_int);
165-
extern int ethertype_print(u_short, const u_char *, u_int, u_int);
166165
extern int llc_print(const u_char *, u_int, u_int, const u_char *,
167166
const u_char *, u_short *);
168167
extern int snap_print(const u_char *, u_int, u_int, u_int);
@@ -185,9 +184,6 @@ extern u_int enc_if_print(const struct pcap_pkthdr *, const u_char *);
185184
extern u_int pflog_if_print(const struct pcap_pkthdr *, const u_char *);
186185
extern u_int arcnet_if_print(const struct pcap_pkthdr *, const u_char *);
187186
extern u_int arcnet_linux_if_print(const struct pcap_pkthdr *, const u_char *);
188-
extern void ether_print(const u_char *, u_int, u_int,
189-
void (*)(const u_char *), const u_char *);
190-
extern u_int ether_if_print(const struct pcap_pkthdr *, const u_char *);
191187
extern u_int token_print(const u_char *, u_int, u_int);
192188
extern u_int token_if_print(const struct pcap_pkthdr *, const u_char *);
193189
extern void fddi_print(const u_char *, u_int, u_int);

netdissect.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,17 @@ extern void ip_print_inner(netdissect_options *ndo,
283283
const u_char *bp2);
284284
extern void rrcp_print(netdissect_options *,const u_char *, u_int);
285285

286+
extern void ether_print(netdissect_options *,
287+
const u_char *, u_int, u_int,
288+
void (*)(netdissect_options *, const u_char *),
289+
const u_char *);
290+
291+
extern u_int ether_if_print(netdissect_options *,
292+
const struct pcap_pkthdr *,const u_char *);
293+
294+
extern int ethertype_print(netdissect_options *,u_short, const u_char *,
295+
u_int, u_int);
296+
286297
/* stuff that has not yet been rototiled */
287298
#if 0
288299
extern void ascii_print(netdissect_options *,u_int);
@@ -293,8 +304,6 @@ extern void hex_print_with_offset(netdissect_options *,const char *,
293304
u_int, u_int);
294305
extern void hex_print(netdissect_options *,const char *, u_int);
295306
extern void telnet_print(netdissect_options *,const u_char *, u_int);
296-
extern int ethertype_print(netdissect_options *,u_short, const u_char *,
297-
u_int, u_int);
298307
extern int llc_print(netdissect_options *,
299308
const u_char *, u_int, u_int, const u_char *,
300309
const u_char *, u_short *);
@@ -321,7 +330,6 @@ extern void egp_print(netdissect_options *,const u_char *, u_int,
321330
const u_char *);
322331

323332
extern void arcnet_if_print(u_char*,const struct pcap_pkthdr *,const u_char *);
324-
extern void ether_if_print(u_char *,const struct pcap_pkthdr *,const u_char *);
325333
extern void token_if_print(u_char *,const struct pcap_pkthdr *,const u_char *);
326334
extern void fddi_if_print(u_char *,const struct pcap_pkthdr *, const u_char *);
327335

print-ap1394.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ap1394_if_print(const struct pcap_pkthdr *h, const u_char *p)
106106
p += FIREWIRE_HDRLEN;
107107

108108
ether_type = EXTRACT_16BITS(&fp->firewire_type);
109-
if (ethertype_print(ether_type, p, length, caplen) == 0) {
109+
if (ethertype_print(gndo, ether_type, p, length, caplen) == 0) {
110110
/* ether_type not known, print raw packet */
111111
if (!eflag)
112112
ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN);

print-ether.c

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static const char rcsid[] _U_ =
2323
"@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.106 2008-02-06 10:47:53 guy Exp $ (LBL)";
2424
#endif
2525

26+
#define NETDISSECT_REWORKED
2627
#ifdef HAVE_CONFIG_H
2728
#include "config.h"
2829
#endif
@@ -84,7 +85,8 @@ const struct tok ethertype_values[] = {
8485
};
8586

8687
static inline void
87-
ether_hdr_print(register const u_char *bp, u_int length)
88+
ether_hdr_print(netdissect_options *ndo,
89+
const u_char *bp, u_int length)
8890
{
8991
register const struct ether_header *ep;
9092
u_int16_t ether_type;
@@ -96,7 +98,7 @@ ether_hdr_print(register const u_char *bp, u_int length)
9698
etheraddr_string(EDST(ep)));
9799

98100
ether_type = EXTRACT_16BITS(&ep->ether_type);
99-
if (!qflag) {
101+
if (!ndo->ndo_qflag) {
100102
if (ether_type <= ETHERMTU)
101103
(void)printf(", 802.3");
102104
else
@@ -120,8 +122,9 @@ ether_hdr_print(register const u_char *bp, u_int length)
120122
* frame's protocol, and an argument to pass to that function.
121123
*/
122124
void
123-
ether_print(const u_char *p, u_int length, u_int caplen,
124-
void (*print_encap_header)(const u_char *), const u_char *encap_header_arg)
125+
ether_print(netdissect_options *ndo,
126+
const u_char *p, u_int length, u_int caplen,
127+
void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg)
125128
{
126129
struct ether_header *ep;
127130
u_int orig_length;
@@ -133,10 +136,10 @@ ether_print(const u_char *p, u_int length, u_int caplen,
133136
return;
134137
}
135138

136-
if (eflag) {
139+
if (ndo->ndo_eflag) {
137140
if (print_encap_header != NULL)
138-
(*print_encap_header)(encap_header_arg);
139-
ether_hdr_print(p, length);
141+
(*print_encap_header)(ndo, encap_header_arg);
142+
ether_hdr_print(ndo, p, length);
140143
}
141144
orig_length = length;
142145

@@ -156,14 +159,14 @@ ether_print(const u_char *p, u_int length, u_int caplen,
156159
if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
157160
&extracted_ether_type) == 0) {
158161
/* ether_type not known, print raw packet */
159-
if (!eflag) {
162+
if (!ndo->ndo_eflag) {
160163
if (print_encap_header != NULL)
161-
(*print_encap_header)(encap_header_arg);
162-
ether_hdr_print((u_char *)ep, orig_length);
164+
(*print_encap_header)(ndo, encap_header_arg);
165+
ether_hdr_print(ndo, (u_char *)ep, orig_length);
163166
}
164167

165-
if (!suppress_default_print)
166-
default_print(p, caplen);
168+
if (!ndo->ndo_suppress_default_print)
169+
ndo->ndo_default_print(ndo, p, caplen);
167170
}
168171
} else if (ether_type == ETHERTYPE_8021Q) {
169172
/*
@@ -174,7 +177,7 @@ ether_print(const u_char *p, u_int length, u_int caplen,
174177
printf("[|vlan]");
175178
return;
176179
}
177-
if (eflag) {
180+
if (ndo->ndo_eflag) {
178181
u_int16_t tag = EXTRACT_16BITS(p);
179182

180183
printf("vlan %u, p %u%s, ",
@@ -184,7 +187,7 @@ ether_print(const u_char *p, u_int length, u_int caplen,
184187
}
185188

186189
ether_type = EXTRACT_16BITS(p + 2);
187-
if (eflag && ether_type > ETHERMTU)
190+
if (ndo->ndo_eflag && ether_type > ETHERMTU)
188191
printf("ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type));
189192
p += 4;
190193
length -= 4;
@@ -204,26 +207,26 @@ ether_print(const u_char *p, u_int length, u_int caplen,
204207
if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
205208
&extracted_ether_type) == 0) {
206209
/* ether_type not known, print raw packet */
207-
if (!eflag) {
210+
if (!ndo->ndo_eflag) {
208211
if (print_encap_header != NULL)
209-
(*print_encap_header)(encap_header_arg);
210-
ether_hdr_print((u_char *)ep, orig_length);
212+
(*print_encap_header)(ndo, encap_header_arg);
213+
ether_hdr_print(ndo, (u_char *)ep, orig_length);
211214
}
212215

213-
if (!suppress_default_print)
214-
default_print(p, caplen);
216+
if (!ndo->ndo_suppress_default_print)
217+
ndo->ndo_default_print(ndo, p, caplen);
215218
}
216219
} else {
217-
if (ethertype_print(ether_type, p, length, caplen) == 0) {
220+
if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) {
218221
/* ether_type not known, print raw packet */
219-
if (!eflag) {
222+
if (!ndo->ndo_eflag) {
220223
if (print_encap_header != NULL)
221-
(*print_encap_header)(encap_header_arg);
222-
ether_hdr_print((u_char *)ep, orig_length);
224+
(*print_encap_header)(ndo, encap_header_arg);
225+
ether_hdr_print(ndo, (u_char *)ep, orig_length);
223226
}
224227

225-
if (!suppress_default_print)
226-
default_print(p, caplen);
228+
if (!ndo->ndo_suppress_default_print)
229+
ndo->ndo_default_print(ndo, p, caplen);
227230
}
228231
}
229232
}
@@ -235,9 +238,10 @@ ether_print(const u_char *p, u_int length, u_int caplen,
235238
* is the number of bytes actually captured.
236239
*/
237240
u_int
238-
ether_if_print(const struct pcap_pkthdr *h, const u_char *p)
241+
ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
242+
const u_char *p)
239243
{
240-
ether_print(p, h->len, h->caplen, NULL, NULL);
244+
ether_print(ndo, p, h->len, h->caplen, NULL, NULL);
241245

242246
return (ETHER_HDRLEN);
243247
}
@@ -250,93 +254,95 @@ ether_if_print(const struct pcap_pkthdr *h, const u_char *p)
250254
*/
251255

252256
int
253-
ethertype_print(u_short ether_type, const u_char *p, u_int length, u_int caplen)
257+
ethertype_print(netdissect_options *ndo,
258+
u_short ether_type, const u_char *p,
259+
u_int length, u_int caplen)
254260
{
255261
switch (ether_type) {
256262

257263
case ETHERTYPE_IP:
258-
ip_print(gndo, p, length);
264+
ip_print(ndo, p, length);
259265
return (1);
260266

261267
#ifdef INET6
262268
case ETHERTYPE_IPV6:
263-
ip6_print(p, length);
269+
ip6_print(/*ndo,*/ p, length);
264270
return (1);
265271
#endif /*INET6*/
266272

267273
case ETHERTYPE_ARP:
268274
case ETHERTYPE_REVARP:
269-
arp_print(gndo, p, length, caplen);
275+
arp_print(ndo, p, length, caplen);
270276
return (1);
271277

272278
case ETHERTYPE_DN:
273-
decnet_print(p, length, caplen);
279+
decnet_print(/*ndo,*/p, length, caplen);
274280
return (1);
275281

276282
case ETHERTYPE_ATALK:
277-
if (vflag)
283+
if (ndo->ndo_vflag)
278284
fputs("et1 ", stdout);
279-
atalk_print(p, length);
285+
atalk_print(/*ndo,*/p, length);
280286
return (1);
281287

282288
case ETHERTYPE_AARP:
283-
aarp_print(p, length);
289+
aarp_print(/*ndo,*/p, length);
284290
return (1);
285291

286292
case ETHERTYPE_IPX:
287293
printf("(NOV-ETHII) ");
288-
ipx_print(p, length);
294+
ipx_print(/*ndo,*/p, length);
289295
return (1);
290296

291297
case ETHERTYPE_ISO:
292-
isoclns_print(p+1, length-1, length-1);
298+
isoclns_print(/*ndo,*/p+1, length-1, length-1);
293299
return(1);
294300

295301
case ETHERTYPE_PPPOED:
296302
case ETHERTYPE_PPPOES:
297303
case ETHERTYPE_PPPOED2:
298304
case ETHERTYPE_PPPOES2:
299-
pppoe_print(p, length);
305+
pppoe_print(/*ndo,*/p, length);
300306
return (1);
301307

302308
case ETHERTYPE_EAPOL:
303-
eap_print(gndo, p, length);
309+
eap_print(ndo, p, length);
304310
return (1);
305311

306312
case ETHERTYPE_RRCP:
307-
rrcp_print(gndo, p - 14 , length + 14);
313+
rrcp_print(ndo, p - 14 , length + 14);
308314
return (1);
309315

310316
case ETHERTYPE_PPP:
311317
if (length) {
312318
printf(": ");
313-
ppp_print(p, length);
319+
ppp_print(/*ndo,*/p, length);
314320
}
315321
return (1);
316322

317323
case ETHERTYPE_MPCP:
318-
mpcp_print(p, length);
324+
mpcp_print(/*ndo,*/p, length);
319325
return (1);
320326

321327
case ETHERTYPE_SLOW:
322-
slow_print(p, length);
328+
slow_print(/*ndo,*/p, length);
323329
return (1);
324330

325331
case ETHERTYPE_CFM:
326332
case ETHERTYPE_CFM_OLD:
327-
cfm_print(p, length);
333+
cfm_print(/*ndo,*/p, length);
328334
return (1);
329335

330336
case ETHERTYPE_LLDP:
331-
lldp_print(p, length);
337+
lldp_print(/*ndo,*/p, length);
332338
return (1);
333339

334340
case ETHERTYPE_LOOPBACK:
335341
return (1);
336342

337343
case ETHERTYPE_MPLS:
338344
case ETHERTYPE_MPLS_MULTI:
339-
mpls_print(p, length);
345+
mpls_print(/*ndo,*/p, length);
340346
return (1);
341347

342348
case ETHERTYPE_LAT:

print-fr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fr_print(register const u_char *p, u_int length)
256256
if (eflag)
257257
fr_hdr_print(length, addr_len, dlci, flags, extracted_ethertype);
258258

259-
if (ethertype_print(extracted_ethertype,
259+
if (ethertype_print(gndo, extracted_ethertype,
260260
p+addr_len+ETHERTYPE_LEN,
261261
length-addr_len-ETHERTYPE_LEN,
262262
length-addr_len-ETHERTYPE_LEN) == 0)

print-gre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ gre_print_0(const u_char *bp, u_int length)
226226
isoclns_print(bp, len, len);
227227
break;
228228
case ETHERTYPE_TEB:
229-
ether_print(bp, len, len, NULL, NULL);
229+
ether_print(gndo, bp, len, len, NULL, NULL);
230230
break;
231231
default:
232232
printf("gre-proto-0x%x", prot);

print-ip.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ ip_print(netdissect_options *ndo,
573573
else if (!eflag)
574574
printf("IP ");
575575

576-
if ((u_char *)(ipds->ip + 1) > snapend) {
576+
if ((u_char *)(ipds->ip + 1) > ndo->ndo_snapend) {
577577
printf("[|ip]");
578578
return;
579579
}
@@ -611,8 +611,8 @@ ip_print(netdissect_options *ndo,
611611
* Cut off the snapshot length to the end of the IP payload.
612612
*/
613613
ipend = bp + ipds->len;
614-
if (ipend < snapend)
615-
snapend = ipend;
614+
if (ipend < ndo->ndo_snapend)
615+
ndo->ndo_snapend = ipend;
616616

617617
ipds->len -= hlen;
618618

@@ -658,7 +658,7 @@ ip_print(netdissect_options *ndo,
658658
printf(")");
659659
}
660660

661-
if (!Kflag && (u_char *)ipds->ip + hlen <= snapend) {
661+
if (!Kflag && (u_char *)ipds->ip + hlen <= ndo->ndo_snapend) {
662662
sum = in_cksum((const u_short *)ipds->ip, hlen, 0);
663663
if (sum != 0) {
664664
ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum);

0 commit comments

Comments
 (0)