--- libaitio/example/bpf.c 2013/06/25 17:06:02 1.1.2.6 +++ libaitio/example/bpf.c 2013/06/26 13:33:55 1.1.2.10 @@ -78,15 +78,9 @@ ShowPkt(void *buffer) assert(buffer); -#ifdef __FreeBSD__ - snprintf(szLine, BUFSIZ, "#Packet length: %d\n>>> Ethernet ...\n", flg ? bzh->bzh_kernel_len : bpf->bh_datalen); - strlcat(szShow, szLine, USHRT_MAX); - eth = (struct ether_header *) (buffer + (flg ? bzh->bzh_kernel_len : bpf->bh_hdrlen)); -#else snprintf(szLine, BUFSIZ, "#Packet length: %d\n>>> Ethernet ...\n", bpf->bh_datalen); strlcat(szShow, szLine, USHRT_MAX); eth = (struct ether_header *) (buffer + bpf->bh_hdrlen); -#endif switch (ntohs(eth->ether_type)) { case ETHERTYPE_ARP: @@ -300,9 +294,9 @@ main(int argc, char **argv) strlcpy(szStr, *argv, sizeof szStr); #ifdef __FreeBSD__ - dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, &bz); + dev = io_etherOpen(szStr, O_RDWR | O_NONBLOCK, 42, (u_int*) &siz, (flg) ? &bz : NULL); if (dev == -1) - dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, NULL); + dev = io_etherOpen(szStr, O_RDWR | O_NONBLOCK, 42, (u_int*) &siz, NULL); #else dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, NULL); #endif @@ -341,10 +335,12 @@ main(int argc, char **argv) if (mode == 'R') { pfd.events = POLLIN; for (i = 0; i < count; i++) { - if (poll(&pfd, 1, -1) == -1) + if ((ret = poll(&pfd, 1, -1)) == -1) break; ret = io_etherRecv(dev, buffer, siz, bz); + if (!ret) + continue; if (ret == -1) printf("%d) io_etherRecv(%d) #%d - %s\n", i, ret, io_GetErrno(), io_GetError());