version 1.1.2.1, 2013/06/25 09:08:10
|
version 1.1.2.5, 2013/06/25 16:53:15
|
Line 37
|
Line 37
|
#include <netinet/if_ether.h> |
#include <netinet/if_ether.h> |
#endif |
#endif |
|
|
|
#include <aitio.h> |
|
|
#ifndef roundup |
#ifndef roundup |
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) /* to any y */ |
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) /* to any y */ |
#endif |
#endif |
Line 261 main(int argc, char **argv)
|
Line 263 main(int argc, char **argv)
|
pthread_t tid; |
pthread_t tid; |
char ch, mode = 'R'; |
char ch, mode = 'R'; |
struct timespec ts_start, ts_end; |
struct timespec ts_start, ts_end; |
#ifdef __FreeBSD__ | void *bz = NULL; |
struct bpf_zbuf *bz; | |
#endif | |
|
|
while ((ch = getopt(argc, argv, "hvwzs:p:f:")) != -1) |
while ((ch = getopt(argc, argv, "hvwzs:p:f:")) != -1) |
switch (ch) { |
switch (ch) { |
Line 299 main(int argc, char **argv)
|
Line 299 main(int argc, char **argv)
|
else |
else |
strlcpy(szStr, *argv, sizeof szStr); |
strlcpy(szStr, *argv, sizeof szStr); |
|
|
#ifdef __FreeBSD_ | #ifdef __FreeBSD__ |
dev = io_etherOpen(szStr, O_RDWR | O_NONBLOCK, 42, &siz, &bz); | dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, &bz); |
| if (dev == -1) |
| dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, NULL); |
#else |
#else |
dev = io_etherOpen(szStr, O_RDWR | O_NONBLOCK, 42, &siz, NULL); | dev = io_etherOpen(szStr, O_RDWR, 42, (u_int*) &siz, NULL); |
#endif |
#endif |
if (dev == -1) { |
if (dev == -1) { |
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError()); |
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError()); |
Line 312 main(int argc, char **argv)
|
Line 314 main(int argc, char **argv)
|
|
|
if (ioctl(dev, BIOCGBLEN, &n) == -1) { |
if (ioctl(dev, BIOCGBLEN, &n) == -1) { |
perror("ioctl(BIOCGBLEN)"); |
perror("ioctl(BIOCGBLEN)"); |
close(dev); | io_etherClose(dev, &bz); |
return 1; |
return 1; |
} else |
} else |
printf("BPF buffer len=%d\n", n); |
printf("BPF buffer len=%d\n", n); |
|
|
#if 0 |
|
#ifdef __FreeBSD__ |
|
ret = BPF_BUFMODE_ZBUF; |
|
if (flg && !ioctl(dev, BIOCSETBUFMODE, (u_int*) &ret)) { |
|
if (ioctl(dev, BIOCGETZMAX, &ret) == -1) { |
|
perror("ioctl(BIOCGETZMAX)"); |
|
close(dev); |
|
return 1; |
|
} |
|
memset(&bz, 0, sizeof bz); |
|
bz.bz_buflen = roundup(MIN(n, ret), getpagesize()); |
|
bz.bz_bufa = mmap(NULL, bz.bz_buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); |
|
bz.bz_bufb = mmap(NULL, bz.bz_buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); |
|
if (bz.bz_bufa == MAP_FAILED || bz.bz_bufb == MAP_FAILED) { |
|
perror("mmap()"); |
|
close(dev); |
|
return 1; |
|
} |
|
|
|
if (ioctl(dev, BIOCSETZBUF, &bz) == -1) { |
|
perror("ioctl(BIOCSETZBUF)"); |
|
munmap(bz.bz_bufa, bz.bz_buflen); |
|
munmap(bz.bz_bufb, bz.bz_buflen); |
|
close(dev); |
|
return 1; |
|
} else |
|
siz = bz.bz_buflen; |
|
} else { |
|
#endif |
|
flg = 0; |
|
if (siz) { |
|
if (ioctl(dev, BIOCSBLEN, &siz) == -1) { |
|
perror("ioctl(BIOCSBLEN)"); |
|
close(dev); |
|
return 1; |
|
} |
|
} else |
|
siz = n; |
|
#ifdef __FreeBSD__ |
|
} |
|
#endif |
|
printf("Set buffer len to %d\n", siz); |
|
|
|
if (!flg) { |
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)"); |
close(dev); | io_etherClose(dev, &bz); |
return 1; |
return 1; |
} |
} |
buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); |
buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); |
Line 374 main(int argc, char **argv)
|
Line 333 main(int argc, char **argv)
|
buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); |
buffer = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); |
if (buffer == MAP_FAILED) { |
if (buffer == MAP_FAILED) { |
perror("mmap()"); |
perror("mmap()"); |
close(dev); | io_etherClose(dev, &bz); |
return 1; |
return 1; |
} |
} |
} |
} |
|
|
memset(&ifr, 0, sizeof ifr); |
|
strlcpy(ifr.ifr_name, szStr, sizeof ifr.ifr_name); |
|
if (ioctl(dev, BIOCSETIF, (char*) &ifr) == -1) { |
|
perror("ioctl(BIOCSETIF)"); |
|
close(dev); |
|
#ifdef __FreeBSD__ |
|
if (flg) { |
|
munmap(bz.bz_bufa, bz.bz_buflen); |
|
munmap(bz.bz_bufb, bz.bz_buflen); |
|
} else |
|
#endif |
|
munmap(buffer, siz); |
|
return 1; |
|
} |
|
n = 1; |
|
if (ioctl(dev, BIOCSHDRCMPLT, &n) == -1) { |
|
perror("ioctl(BIOCSHDRCMPLT)"); |
|
close(dev); |
|
#ifdef __FreeBSD__ |
|
if (flg) { |
|
munmap(bz.bz_bufa, bz.bz_buflen); |
|
munmap(bz.bz_bufb, bz.bz_buflen); |
|
} else |
|
#endif |
|
munmap(buffer, siz); |
|
return 1; |
|
} |
|
if (ioctl(dev, BIOCIMMEDIATE, &n) == -1) { |
|
perror("ioctl(BIOCIMMEDIATE)"); |
|
close(dev); |
|
#ifdef __FreeBSD__ |
|
if (flg) { |
|
munmap(bz.bz_bufa, bz.bz_buflen); |
|
munmap(bz.bz_bufb, bz.bz_buflen); |
|
} else |
|
#endif |
|
munmap(buffer, siz); |
|
return 1; |
|
} |
|
|
|
pfd.fd = dev; |
pfd.fd = dev; |
assert(!clock_gettime(CLOCK_REALTIME, &ts_start)); |
assert(!clock_gettime(CLOCK_REALTIME, &ts_start)); |
if (mode == 'R') { |
if (mode == 'R') { |
Line 427 main(int argc, char **argv)
|
Line 346 main(int argc, char **argv)
|
if (poll(&pfd, 1, -1) == -1) |
if (poll(&pfd, 1, -1) == -1) |
break; |
break; |
|
|
|
#if 0 |
#ifdef __FreeBSD__ |
#ifdef __FreeBSD__ |
if (flg) { |
if (flg) { |
if (!NEXT_zbuf((void**) &buffer, &bz, &ret)) |
if (!NEXT_zbuf((void**) &buffer, &bz, &ret)) |
Line 447 main(int argc, char **argv)
|
Line 367 main(int argc, char **argv)
|
#ifdef __FreeBSD__ |
#ifdef __FreeBSD__ |
} |
} |
#endif |
#endif |
|
#endif |
} |
} |
} else { |
} else { |
pfd.events = POLLOUT; |
pfd.events = POLLOUT; |
for (i = 0; i < count; i++) { |
for (i = 0; i < count; i++) { |
#ifdef __FreeBSD__ |
|
if (poll(&pfd, 1, -1) == -1) |
if (poll(&pfd, 1, -1) == -1) |
break; |
break; |
#endif |
|
|
|
ret = write(dev, buffer, siz); | ret = io_etherSend(dev, buffer, siz); |
if (ret == -1) |
if (ret == -1) |
printf("write(%d) #%d - %s\n", ret, errno, strerror(errno)); | printf("io_etherSend(%d) #%d - %s\n", ret, io_GetErrno(), io_GetError()); |
if (Verbose) |
if (Verbose) |
printf("+writed %d bytes\n", ret); |
printf("+writed %d bytes\n", ret); |
} |
} |
} |
} |
assert(!clock_gettime(CLOCK_REALTIME, &ts_end)); |
assert(!clock_gettime(CLOCK_REALTIME, &ts_end)); |
#endif |
|
// munmap(buffer, siz); |
|
|
|
|
if (!flg) |
|
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); |