| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- # include <stdio.h>
- # include <stdint.h>
- # include <stdlib.h>
- # include <unistd.h>
- # include <string.h>
- # include <errno.h>
- # include <sys/types.h>
- # include <sys/stat.h>
- # include <fcntl.h>
- # include <arpa/inet.h>
- # include <getopt.h>
- struct fpv
- {
- uint32_t len;
- uint8_t type;
- uint32_t ms;
- uint8_t pad[8];
- } __attribute__((packed));
- static const char short_options[] = "s:e:";
- static const struct option long_options[] =
- {
- { "start", required_argument, NULL, 's' },
- { "end", required_argument, NULL, 'e' },
- { 0, 0, NULL, 0 }
- };
- static int opt_s = 0;
- static int opt_e = 0;
- size_t in(int fd, uint8_t *data, size_t len)
- {
- int res = 0;
- while (len > 0) {
- size_t n = read(fd, data, len);
- if (n > 0) {
- len -= n;
- data += n;
- res += n;
- } else {
- if (n < 0) {
- if (errno != EAGAIN) {
- printf("read: %s\n", strerror(errno));
- } else {
- continue;
- }
- }
- break;
- }
- }
- return res;
- }
- int main(int argc, char *argv[])
- {
- struct fpv fpv;
- static uint8_t data[8 * 1024 * 1024];
- int i;
- for (;;) {
- int c;
- if ((c = getopt_long_only(argc, argv, short_options, long_options, &i)) == -1) {
- break;
- }
- switch (c) {
- case 's':
- opt_s = atoi(optarg);
- break;
- case 'e':
- opt_e = atoi(optarg);
- break;
- case 0:
- break;
- default:
- return 1;
- }
- }
- if ((argc - optind) < 1) {
- return 1;
- }
- for (i = 0; (optind + i) < argc; i++) {
- int fd = open(argv[optind + i], O_RDONLY);
- if (fd >= 0) {
- while (1) {
- if (in(fd, (uint8_t*)&fpv, sizeof(fpv)) > 0) {
- if (in(fd, data, fpv.len) > 0) {
- if (fpv.ms >= opt_s) {
- printf("%1u %10u %10u\n", fpv.type, fpv.ms, fpv.len);
- }
- continue;
- }
- }
- break;
- }
- close(fd);
- }
- }
- return 0;
- }
|