|
|
| version 1.1.2.5, 2013/06/25 16:53:15 | version 1.1.2.7, 2013/06/25 17:16:37 |
|---|---|
| Line 300 main(int argc, char **argv) | Line 300 main(int argc, char **argv) |
| strlcpy(szStr, *argv, sizeof szStr); | strlcpy(szStr, *argv, sizeof szStr); |
| #ifdef __FreeBSD__ | #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) | 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 | #else |
| dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, NULL); | dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, NULL); |
| #endif | #endif |
| Line 312 main(int argc, char **argv) | Line 312 main(int argc, char **argv) |
| } else | } else |
| printf("dev=%d(%s)\n", dev, szStr); | printf("dev=%d(%s)\n", dev, szStr); |
| if (ioctl(dev, BIOCGBLEN, &n) == -1) { | if (ioctl(dev, BIOCGBLEN, &siz) == -1) { |
| perror("ioctl(BIOCGBLEN)"); | perror("ioctl(BIOCGBLEN)"); |
| io_etherClose(dev, &bz); | io_etherClose(dev, &bz); |
| return 1; | return 1; |
| } else | } else |
| printf("BPF buffer len=%d\n", n); | printf("BPF buffer len=%d\n", siz); |
| if (!flg) { | if (*szMap) { |
| if (*szMap) { | fd = open(szMap, O_RDWR); |
| fd = open(szMap, O_RDWR); | if (fd == -1) { |
| if (fd == -1) { | perror("open(map)"); |
| perror("open(map)"); | |
| io_etherClose(dev, &bz); | |
| return 1; | |
| } | |
| buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | |
| close(fd); | |
| } else | |
| buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); | |
| if (buffer == MAP_FAILED) { | |
| perror("mmap()"); | |
| io_etherClose(dev, &bz); | io_etherClose(dev, &bz); |
| return 1; | return 1; |
| } | } |
| buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | |
| close(fd); | |
| } else | |
| buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); | |
| if (buffer == MAP_FAILED) { | |
| perror("mmap()"); | |
| io_etherClose(dev, &bz); | |
| return 1; | |
| } | } |
| pfd.fd = dev; | pfd.fd = dev; |
| Line 346 main(int argc, char **argv) | Line 344 main(int argc, char **argv) |
| if (poll(&pfd, 1, -1) == -1) | if (poll(&pfd, 1, -1) == -1) |
| break; | break; |
| #if 0 | ret = io_etherRecv(dev, buffer, siz, NULL); |
| #ifdef __FreeBSD__ | if (ret == -1) |
| if (flg) { | printf("%d) io_etherRecv(%d) #%d - %s\n", i, ret, |
| if (!NEXT_zbuf((void**) &buffer, &bz, &ret)) | io_GetErrno(), io_GetError()); |
| continue; | if (Verbose) { |
| if (Verbose) { | printf("%d) +readed %d bytes\n", i, ret); |
| printf("+readed %d bytes\n", ret); | pthread_create(&tid, NULL, ShowPkt, buffer); |
| pthread_create(&tid, NULL, ShowPkt, buffer); | pthread_join(tid, NULL); |
| } | |
| } else { | |
| #endif | |
| ret = read(dev, buffer, siz); | |
| if (ret == -1) | |
| printf("%d) read(%d) #%d - %s\n", i, ret, errno, strerror(errno)); | |
| if (Verbose) { | |
| printf("%d) +readed %d bytes\n", i, ret); | |
| pthread_create(&tid, NULL, ShowPkt, buffer); | |
| } | |
| #ifdef __FreeBSD__ | |
| } | } |
| #endif | |
| #endif | |
| } | } |
| } else { | } else { |
| pfd.events = POLLOUT; | pfd.events = POLLOUT; |
| Line 384 main(int argc, char **argv) | Line 369 main(int argc, char **argv) |
| } | } |
| assert(!clock_gettime(CLOCK_REALTIME, &ts_end)); | assert(!clock_gettime(CLOCK_REALTIME, &ts_end)); |
| if (!flg) | munmap(buffer, siz); |
| munmap(buffer, siz); | |
| io_etherClose(dev, &bz); | io_etherClose(dev, &bz); |
| time_spec_sub(&ts_end, &ts_start); | time_spec_sub(&ts_end, &ts_start); |