Skip to content

Commit 08e40fd

Browse files
committed
The last 2 bytes of an Ethernet header are the "length/type field".
Call it that, to indicate that it's not necessarily a type field. While we're at it, get rid of references to "DEC/Intel/Xerox" and "802.3" Ethernet headers in comments; since 802.3y, the 802.3 standard supports both "DIX" frames, with a type field, and earlier 802.3 frames, with a length field, so there's only one version of Ethernet, 802.3, which supports frames with type fields and frames with length fields.
1 parent b713410 commit 08e40fd

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

ether.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@
4141
#define ETHER_ADDR_LEN 6
4242

4343
/*
44-
* Structure of a DEC/Intel/Xerox or 802.3 Ethernet header.
44+
* Structure of an Ethernet header.
4545
*/
4646
struct ether_header {
4747
uint8_t ether_dhost[ETHER_ADDR_LEN];
4848
uint8_t ether_shost[ETHER_ADDR_LEN];
49-
uint16_t ether_type;
49+
uint16_t ether_length_type;
5050
};
5151

5252
/*
53-
* Length of a DEC/Intel/Xerox or 802.3 Ethernet header; note that some
54-
* compilers may pad "struct ether_header" to a multiple of 4 bytes,
55-
* for example, so "sizeof (struct ether_header)" may not give the right
56-
* answer.
53+
* Length of an Ethernet header; note that some compilers may pad
54+
* "struct ether_header" to a multiple of 4 bytes, for example, so
55+
* "sizeof (struct ether_header)" may not give the right answer.
5756
*/
5857
#define ETHER_HDRLEN 14

print-ether.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,29 @@ ether_hdr_print(netdissect_options *ndo,
9191
const u_char *bp, u_int length)
9292
{
9393
register const struct ether_header *ep;
94-
uint16_t ether_type;
94+
uint16_t length_type;
9595

9696
ep = (const struct ether_header *)bp;
9797

9898
ND_PRINT((ndo, "%s > %s",
9999
etheraddr_string(ndo, ESRC(ep)),
100100
etheraddr_string(ndo, EDST(ep))));
101101

102-
ether_type = EXTRACT_16BITS(&ep->ether_type);
102+
length_type = EXTRACT_16BITS(&ep->ether_length_type);
103103
if (!ndo->ndo_qflag) {
104-
if (ether_type <= ETHERMTU) {
104+
if (length_type <= ETHERMTU) {
105105
ND_PRINT((ndo, ", 802.3"));
106-
length = ether_type;
106+
length = length_type;
107107
} else
108108
ND_PRINT((ndo, ", ethertype %s (0x%04x)",
109-
tok2str(ethertype_values,"Unknown", ether_type),
110-
ether_type));
109+
tok2str(ethertype_values,"Unknown", length_type),
110+
length_type));
111111
} else {
112-
if (ether_type <= ETHERMTU) {
112+
if (length_type <= ETHERMTU) {
113113
ND_PRINT((ndo, ", 802.3"));
114-
length = ether_type;
114+
length = length_type;
115115
} else
116-
ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type)));
116+
ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", length_type)));
117117
}
118118

119119
ND_PRINT((ndo, ", length %u: ", length));
@@ -132,7 +132,7 @@ ether_print(netdissect_options *ndo,
132132
{
133133
const struct ether_header *ep;
134134
u_int orig_length;
135-
u_short ether_type;
135+
u_short length_type;
136136
u_int hdrlen;
137137
int llc_hdrlen;
138138

@@ -158,13 +158,13 @@ ether_print(netdissect_options *ndo,
158158
p += ETHER_HDRLEN;
159159
hdrlen = ETHER_HDRLEN;
160160

161-
ether_type = EXTRACT_16BITS(&ep->ether_type);
161+
length_type = EXTRACT_16BITS(&ep->ether_length_type);
162162

163163
recurse:
164164
/*
165165
* Is it (gag) an 802.3 encapsulation?
166166
*/
167-
if (ether_type <= ETHERMTU) {
167+
if (length_type <= ETHERMTU) {
168168
/* Try to print the LLC-layer header & higher layers */
169169
llc_hdrlen = llc_print(ndo, p, length, caplen, ESRC(ep), EDST(ep));
170170
if (llc_hdrlen < 0) {
@@ -174,10 +174,10 @@ ether_print(netdissect_options *ndo,
174174
llc_hdrlen = -llc_hdrlen;
175175
}
176176
hdrlen += llc_hdrlen;
177-
} else if (ether_type == ETHERTYPE_8021Q ||
178-
ether_type == ETHERTYPE_8021Q9100 ||
179-
ether_type == ETHERTYPE_8021Q9200 ||
180-
ether_type == ETHERTYPE_8021QinQ) {
177+
} else if (length_type == ETHERTYPE_8021Q ||
178+
length_type == ETHERTYPE_8021Q9100 ||
179+
length_type == ETHERTYPE_8021Q9200 ||
180+
length_type == ETHERTYPE_8021QinQ) {
181181
/*
182182
* Print VLAN information, and then go back and process
183183
* the enclosed type field.
@@ -196,15 +196,15 @@ ether_print(netdissect_options *ndo,
196196
ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag)));
197197
}
198198

199-
ether_type = EXTRACT_16BITS(p + 2);
200-
if (ndo->ndo_eflag && ether_type > ETHERMTU)
201-
ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type)));
199+
length_type = EXTRACT_16BITS(p + 2);
200+
if (ndo->ndo_eflag && length_type > ETHERMTU)
201+
ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", length_type)));
202202
p += 4;
203203
length -= 4;
204204
caplen -= 4;
205205
hdrlen += 4;
206206
goto recurse;
207-
} else if (ether_type == ETHERTYPE_JUMBO) {
207+
} else if (length_type == ETHERTYPE_JUMBO) {
208208
/*
209209
* Alteon jumbo frames.
210210
* See
@@ -224,8 +224,8 @@ ether_print(netdissect_options *ndo,
224224
}
225225
hdrlen += llc_hdrlen;
226226
} else {
227-
if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) {
228-
/* ether_type not known, print raw packet */
227+
if (ethertype_print(ndo, length_type, p, length, caplen) == 0) {
228+
/* type not known, print raw packet */
229229
if (!ndo->ndo_eflag) {
230230
if (print_encap_header != NULL)
231231
(*print_encap_header)(ndo, encap_header_arg);

0 commit comments

Comments
 (0)