* Applied a patch by James Woodcock that fixes the pcap_platform_finddevs()

function to use pcap_add_if() instead of maintaining that list manually.
  This also seem to have caused problems with this functionality in case the
  loop device came first. Thanks!
* Some changes to that patch by myself: removed comment about pseudo device,
  as Haiku doesn't have that, and probably will never get it either. Moved
  declaration of "flags" to where it belongs.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25601 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-05-22 07:49:54 +00:00
parent d129070196
commit c25cbc530f
2 changed files with 13 additions and 23 deletions

View File

@ -192,10 +192,10 @@
/* #undef HAVE_PCAP_DUMP_FLUSH */
/* Define to 1 if you have the `pcap_findalldevs' function. */
/* #undef HAVE_PCAP_FINDALLDEVS */
#define HAVE_PCAP_FINDALLDEVS 1
/* Define to 1 if the system has the type `pcap_if_t'. */
/* #undef HAVE_PCAP_IF_T */
#define HAVE_PCAP_IF_T 1
/* Define to 1 if you have the `pcap_lib_version' function. */
/* #undef HAVE_PCAP_LIB_VERSION */

View File

@ -38,7 +38,8 @@ prepare_request(struct ifreq& request, const char* name)
static int
pcap_read_haiku(pcap_t* handle, int maxPackets, pcap_handler callback, u_char* userdata)
pcap_read_haiku(pcap_t* handle, int maxPackets, pcap_handler callback,
u_char* userdata)
{
// Receive a single packet
@ -47,7 +48,8 @@ pcap_read_haiku(pcap_t* handle, int maxPackets, pcap_handler callback, u_char* u
ssize_t bytesReceived;
do {
if (handle->break_loop) {
// Clear the break loop flag, and return -2 to indicate our reasoning
// Clear the break loop flag, and return -2 to indicate our
// reasoning
handle->break_loop = 0;
return -2;
}
@ -275,7 +277,7 @@ pcap_platform_finddevs(pcap_if_t** _allDevices, char* errorBuffer)
return -1;
}
void *buffer = malloc(count * sizeof(struct ifreq));
void* buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL) {
snprintf(errorBuffer, PCAP_ERRBUF_SIZE, "Out of memory.\n");
close(socket);
@ -289,24 +291,10 @@ pcap_platform_finddevs(pcap_if_t** _allDevices, char* errorBuffer)
return -1;
}
ifreq *interface = (ifreq *)buffer;
pcap_if_t* last = NULL;
ifreq* interface = (ifreq*)buffer;
for (uint32 i = 0; i < count; i++) {
pcap_if_t* pcapInterface = (pcap_if_t*)malloc(sizeof(pcap_if_t));
if (pcapInterface == NULL)
continue;
if (last == NULL)
*_allDevices = pcapInterface;
else
last->next = pcapInterface;
pcapInterface->next = NULL;
pcapInterface->name = strdup(interface->ifr_name);
pcapInterface->description = NULL;
pcapInterface->addresses = NULL;
pcapInterface->flags = 0;
int flags = 0;
// get interface type
@ -328,15 +316,17 @@ pcap_platform_finddevs(pcap_if_t** _allDevices, char* errorBuffer)
prepare_request(request, request.ifr_parameter.device);
if (ioctl(linkSocket, SIOCGIFADDR, &request,
sizeof(struct ifreq)) == 0) {
sockaddr_dl &link = *(sockaddr_dl *)&request.ifr_addr;
sockaddr_dl &link = *(sockaddr_dl*)&request.ifr_addr;
if (link.sdl_type == IFT_LOOP)
pcapInterface->flags = PCAP_IF_LOOPBACK;
flags = IFF_LOOPBACK;
}
}
close(linkSocket);
}
pcap_add_if(_allDevices, interface->ifr_name, flags, NULL, errorBuffer);
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
+ interface->ifr_addr.sa_len);
}