-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
In pcap_activate_haiku() retrieve Haiku interface type for the device and either use a correct DLT value for a supported type or reject the interface. Comment on what currently works and what does not. This will likely require follow-up changes after more testing, but on a WIP development snapshot of Haiku this works correctly, including packet capture and decoding. > ./tcpdump -D 1.tap/0 [Up, Connection status unknown] 2.tun/0 [Up, Connection status unknown] 3./dev/net/ipro1000/0 [Up, Connection status unknown] 4.loop [Up, Loopback] > ./tcpdump -i 1 -L Data link types for tap/0 (use option -y to set): EN10MB (Ethernet) > ./tcpdump -i 2 -L Data link types for tun/0 (use option -y to set): RAW (Raw IP) > ./tcpdump -i 3 -L Data link types for /dev/net/ipro1000/0 (use option -y to set): EN10MB (Ethernet) > ./tcpdump -i 4 -L Data link types for loop (use option -y to set): RAW (Raw IP)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,8 @@ pcap_activate_haiku(pcap_t *handle) | |
goto error; | ||
|
||
// pcap_stats_haiku() will need a baseline for ps_ifdrop. | ||
// At the time of this writing SIOCGIFSTATS returns EINVAL for AF_LINK | ||
// sockets. | ||
if (ioctl_ifreq(handle, handlep->aux_socket, SIOCGIFSTATS, "SIOCGIFSTATS") < 0) { | ||
// Detect a non-existent network interface at least at the | ||
// first ioctl() use. | ||
|
@@ -202,6 +204,36 @@ pcap_activate_haiku(pcap_t *handle) | |
if ((handle->fd = dgram_socket(handle, AF_LINK)) < 0) | ||
goto error; | ||
|
||
// Derive a DLT from the interface type. | ||
// At the time of this writing SIOCGIFTYPE cannot be used for this | ||
// purpose: it returns EINVAL for AF_LINK sockets and sets ifr_type to | ||
// 0 for AF_INET sockets. Use the same method as Haiku ifconfig does | ||
// (SIOCGIFADDR and AF_LINK). | ||
if (ioctl_ifreq(handle, handle->fd, SIOCGIFADDR, "SIOCGIFADDR") < 0) | ||
goto error; | ||
struct sockaddr_dl *sdl = (struct sockaddr_dl *)&handlep->ifreq.ifr_addr; | ||
if (sdl->sdl_family != AF_LINK) { | ||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, | ||
"Got AF %d instead of AF_LINK for interface \"%s\".", | ||
sdl->sdl_family, handle->opt.device); | ||
goto error; | ||
} | ||
switch (sdl->sdl_type) { | ||
case IFT_ETHER: | ||
// This includes tap (L2) mode tunnels too. | ||
handle->linktype = DLT_EN10MB; | ||
break; | ||
case IFT_LOOP: | ||
case IFT_TUNNEL: // This means tun (L3) mode tunnels only. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
infrastation
Author
Member
|
||
handle->linktype = DLT_RAW; | ||
break; | ||
default: | ||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, | ||
"Unknown interface type 0x%0x for interface \"%s\".", | ||
sdl->sdl_type, handle->opt.device); | ||
goto error; | ||
} | ||
|
||
// start monitoring | ||
if (ioctl_ifreq(handle, handle->fd, SIOCSPACKETCAP, "SIOCSPACKETCAP") < 0) | ||
goto error; | ||
|
@@ -240,8 +272,6 @@ pcap_activate_haiku(pcap_t *handle) | |
} | ||
|
||
handle->offset = 0; | ||
handle->linktype = DLT_EN10MB; | ||
// TODO: check interface type! | ||
|
||
return 0; | ||
error: | ||
|
@infrastation IFT_TUNNEL isn't defined on r1beta4. For compatibility: