Skip to content

Commit 9b566c3

Browse files
committed
dlpi: fix open_dlpi_device() to handle Solaris/HP-UX logical interfaces.
If handed the name of a logical interface, strip off the logical interface number. This means that in pcap_findalldevs() we won't skip the logical interfaces and will get the network addresses and netmasks they have. (It also mean that if you try to capture on a logical interface, it'll capture on the physical interface, but that might be the right thing to do.) We can't do it earlier in fad-gifc.c and fad-glifc.c, because we have to use the logical interface name when fetching the netmask, etc..
1 parent c3e5d0c commit 9b566c3

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ Friday, August 30, 2024 / The Tcpdump Group
197197
Allow attaching to links owned by a non-global zone. (Based on
198198
pull request #1202.)
199199
Fix AF_LINK handling on illumos.
200+
Fix not to ignore logical interfaces in fad-gifc.c and
201+
fad-glifc.c.
200202
macOS:
201203
Redid the availability macros to be closer to what Apple's doing
202204
in recent SDKs, including tagging pcap-namedb.h routines.

pcap-dlpi.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
320320
{
321321
int status;
322322
char dname[100];
323-
char *cp;
323+
char *cp, *cq;
324324
int fd;
325325
#ifdef HAVE_DEV_DLPI
326326
u_int unit;
@@ -338,6 +338,32 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
338338
else
339339
pcapint_strlcpy(dname, cp + 1, sizeof(dname));
340340

341+
/*
342+
* If this name has a colon followed by a number at
343+
* the end, it's a logical interface. Those are just
344+
* the way you assign multiple IP addresses to a real
345+
* interface, so an entry for a logical interface should
346+
* be treated like the entry for the real interface;
347+
* we do that by stripping off the ":" and the number.
348+
*/
349+
cp = strchr(dname, ':');
350+
if (cp != NULL) {
351+
/*
352+
* We have a ":"; is it followed by a number?
353+
*/
354+
cq = cp + 1;
355+
while (PCAP_ISDIGIT(*cq))
356+
cq++;
357+
if (*cq == '\0') {
358+
/*
359+
* All digits after the ":" until the end.
360+
* Strip off the ":" and everything after
361+
* it.
362+
*/
363+
*cp = '\0';
364+
}
365+
}
366+
341367
/*
342368
* Split the device name into a device type name and a unit number;
343369
* chop off the unit number, so "dname" is just a device type name.
@@ -399,6 +425,32 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
399425
snprintf(dname, sizeof(dname), "%s/%s", PCAP_DEV_PREFIX,
400426
name);
401427

428+
/*
429+
* If this name has a colon followed by a number at
430+
* the end, it's a logical interface. Those are just
431+
* the way you assign multiple IP addresses to a real
432+
* interface, so an entry for a logical interface should
433+
* be treated like the entry for the real interface;
434+
* we do that by stripping off the ":" and the number.
435+
*/
436+
cp = strchr(dname, ':');
437+
if (cp != NULL) {
438+
/*
439+
* We have a ":"; is it followed by a number?
440+
*/
441+
cq = cp + 1;
442+
while (PCAP_ISDIGIT(*cq))
443+
cq++;
444+
if (*cq == '\0') {
445+
/*
446+
* All digits after the ":" until the end.
447+
* Strip off the ":" and everything after
448+
* it.
449+
*/
450+
*cp = '\0';
451+
}
452+
}
453+
402454
/*
403455
* Get the unit number, and a pointer to the end of the device
404456
* type name.

0 commit comments

Comments
 (0)