Skip to content

Commit 77694ea

Browse files
committed
Clean up handling of EUI-64 addresses.
Add an nd_eui64 type, and use it. Have routines to convert EUI-64s to a string for both the "rightmost octet first" and "rightmost octet last" format. Use the former for IEEE 802.14.4 addresses and the latter for IEEE 1394 addresses in the "Apple IP over FireWire" header.
1 parent f21fe72 commit 77694ea

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

addrtoname.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,16 @@ etheraddr_string(netdissect_options *ndo, const uint8_t *ep)
641641
}
642642

643643
const char *
644-
le64addr_string(netdissect_options *ndo, const uint8_t *ep)
644+
eui64_string(netdissect_options *ndo, const uint8_t *ep)
645+
{
646+
return (linkaddr_string(ndo, ep, LINKADDR_EUI64, EUI64_LEN));
647+
}
648+
649+
/*
650+
* EUI-64 with the rightmost octet first.
651+
*/
652+
const char *
653+
eui64le_string(netdissect_options *ndo, const uint8_t *ep)
645654
{
646655
const unsigned int len = 8;
647656
u_int i;

addrtoname.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern cap_channel_t *capdns;
3939
enum {
4040
LINKADDR_ETHER,
4141
LINKADDR_FRELAY,
42-
LINKADDR_IEEE1394,
42+
LINKADDR_EUI64,
4343
LINKADDR_ATM,
4444
LINKADDR_OTHER
4545
};
@@ -48,7 +48,8 @@ enum {
4848

4949
extern const char *linkaddr_string(netdissect_options *, const uint8_t *, const unsigned int, const unsigned int);
5050
extern const char *etheraddr_string(netdissect_options *, const uint8_t *);
51-
extern const char *le64addr_string(netdissect_options *, const uint8_t *);
51+
extern const char *eui64_string(netdissect_options *, const uint8_t *);
52+
extern const char *eui64le_string(netdissect_options *, const uint8_t *);
5253
extern const char *tcpport_string(netdissect_options *, u_short);
5354
extern const char *udpport_string(netdissect_options *, u_short);
5455
extern const char *isonsap_string(netdissect_options *, const uint8_t *, u_int);
@@ -86,11 +87,19 @@ get_etheraddr_string(netdissect_options *ndo, const uint8_t *p)
8687
}
8788

8889
static inline const char *
89-
get_le64addr_string(netdissect_options *ndo, const u_char *p)
90+
get_eui64_string(netdissect_options *ndo, const uint8_t *p)
9091
{
91-
if (!ND_TTEST_8(p))
92+
if (!ND_TTEST_LEN(p, EUI64_LEN))
9293
nd_trunc_longjmp(ndo);
93-
return le64addr_string(ndo, p);
94+
return eui64_string(ndo, p);
95+
}
96+
97+
static inline const char *
98+
get_eui64le_string(netdissect_options *ndo, const uint8_t *p)
99+
{
100+
if (!ND_TTEST_LEN(p, EUI64_LEN))
101+
nd_trunc_longjmp(ndo);
102+
return eui64le_string(ndo, p);
94103
}
95104

96105
static inline const char *
@@ -120,7 +129,8 @@ get_ip6addr_string(netdissect_options *ndo, const u_char *p)
120129

121130
#define GET_LINKADDR_STRING(p, type, len) get_linkaddr_string(ndo, (const u_char *)(p), type, len)
122131
#define GET_ETHERADDR_STRING(p) get_etheraddr_string(ndo, (const u_char *)(p))
123-
#define GET_LE64ADDR_STRING(p) get_le64addr_string(ndo, (const u_char *)(p))
132+
#define GET_EUI64_STRING(p) get_eui64_string(ndo, (const u_char *)(p))
133+
#define GET_EUI64LE_STRING(p) get_eui64le_string(ndo, (const u_char *)(p))
124134
#define GET_ISONSAP_STRING(nsap, nsap_length) get_isonsap_string(ndo, (const u_char *)(nsap), nsap_length)
125135
#define GET_IPADDR_STRING(p) get_ipaddr_string(ndo, (const u_char *)(p))
126136
#define GET_IP6ADDR_STRING(p) get_ip6addr_string(ndo, (const u_char *)(p))

netdissect.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ typedef unsigned char nd_ipv6[16];
105105
#define MAC_ADDR_LEN 6U /* length of MAC addresses */
106106
typedef unsigned char nd_mac_addr[MAC_ADDR_LEN];
107107

108+
/*
109+
* Use this for EUI64s.
110+
*/
111+
#define EUI64_LEN 8U
112+
typedef unsigned char nd_eui64[EUI64_LEN];
113+
108114
/*
109115
* Use this for blobs of bytes; make them arrays of nd_byte.
110116
*/

print-802_15_4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ ieee802_15_4_print_addr(netdissect_options *ndo, const u_char *p,
546546
ND_PRINT("%04x", GET_LE_U_2(p));
547547
break;
548548
case 8:
549-
ND_PRINT("%s", GET_LE64ADDR_STRING(p));
549+
ND_PRINT("%s", GET_EUI64LE_STRING(p));
550550
break;
551551
}
552552
}
@@ -1576,7 +1576,7 @@ ieee802_15_4_print_aux_sec_header(netdissect_options *ndo,
15761576
return -1;
15771577
}
15781578
if (ndo->ndo_vflag > 1) {
1579-
ND_PRINT("KeySource %s, ", GET_LE64ADDR_STRING(p));
1579+
ND_PRINT("KeySource %s, ", GET_EUI64LE_STRING(p));
15801580
}
15811581
p += 4;
15821582
caplen -= 4;

print-ap1394.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,21 @@
3636
/*
3737
* Structure of a header for Apple's IP-over-IEEE 1384 BPF header.
3838
*/
39-
#define FIREWIRE_EUI64_LEN 8
4039
struct firewire_header {
41-
nd_byte firewire_dhost[FIREWIRE_EUI64_LEN];
42-
nd_byte firewire_shost[FIREWIRE_EUI64_LEN];
40+
nd_eui64 firewire_dhost;
41+
nd_eui64 firewire_shost;
4342
nd_uint16_t firewire_type;
4443
};
4544

4645
/*
4746
* Length of that header; note that some compilers may pad
4847
* "struct firewire_header" to a multiple of 4 bytes, for example, so
4948
* "sizeof (struct firewire_header)" may not give the right answer.
49+
* (That could be true even though we're using nd_ types, none of
50+
* which should require anything more than byte alignment.)
5051
*/
5152
#define FIREWIRE_HDRLEN 18
5253

53-
static const char *
54-
fwaddr_string(netdissect_options *ndo, const u_char *addr)
55-
{
56-
return GET_LINKADDR_STRING(addr, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN);
57-
}
58-
5954
static void
6055
ap1394_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
6156
{
@@ -65,8 +60,8 @@ ap1394_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
6560
fp = (const struct firewire_header *)bp;
6661

6762
ND_PRINT("%s > %s",
68-
fwaddr_string(ndo, fp->firewire_shost),
69-
fwaddr_string(ndo, fp->firewire_dhost));
63+
eui64_string(ndo, fp->firewire_shost),
64+
eui64_string(ndo, fp->firewire_dhost));
7065

7166
firewire_type = GET_BE_U_2(fp->firewire_type);
7267
if (!ndo->ndo_qflag) {
@@ -109,9 +104,9 @@ ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
109104

110105
ether_type = GET_BE_U_2(fp->firewire_type);
111106
src.addr = fp->firewire_shost;
112-
src.addr_string = fwaddr_string;
107+
src.addr_string = eui64_string;
113108
dst.addr = fp->firewire_dhost;
114-
dst.addr_string = fwaddr_string;
109+
dst.addr_string = eui64_string;
115110
if (ethertype_print(ndo, ether_type, p, length, caplen, &src, &dst) == 0) {
116111
/* ether_type not known, print raw packet */
117112
if (!ndo->ndo_eflag)

0 commit comments

Comments
 (0)