Commit 07fc9b14 authored by Alessandro Rubini's avatar Alessandro Rubini

tools/ptpdump: bring inter-frame output into main

Since dump-funcs.c is going to be used within ppsi itself, print the
empty separating lines, as well as the time difference from the
previous frame in main, not in dumping functions.

This has no effect on ptpdump itself, it's only a preparation for reuse
of the code.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f00ec9b4
......@@ -24,24 +24,9 @@ static int dumpstruct(char *prefix, char *name, void *ptr, int size)
static void dump_eth(struct ethhdr *eth, struct TimeInternal *ti)
{
static struct TimeInternal prev_ti;
unsigned char *d = eth->h_dest;
unsigned char *s = eth->h_source;
if (prev_ti.seconds) {
int i;
int diffms;
diffms = (ti->seconds - prev_ti.seconds) * 1000
+ (ti->nanoseconds / 1000 / 1000)
- (prev_ti.nanoseconds / 1000 / 1000);
/* empty lines, one every .25 seconds, at most 10 of them */
for (i = 250; i < 2500 && i < diffms; i += 250)
printf("\n");
printf("TIMEDELTA: %i ms\n", diffms);
}
prev_ti = *ti;
#if __STDC_HOSTED__
{
struct timeval tv;
......@@ -265,7 +250,6 @@ int dump_udppkt(void *buf, int len, struct TimeInternal *ti)
dump_ip(ip);
dump_udp(udp);
dump_payload(payload, len - (payload - buf));
putchar('\n');
return 0;
}
......@@ -276,6 +260,5 @@ int dump_1588pkt(void *buf, int len, struct TimeInternal *ti)
dump_eth(eth, ti);
dump_payload(payload, len - (payload - buf));
putchar('\n');
return 0;
}
......@@ -26,9 +26,28 @@
#define ETH_P_1588 0x88F7
#endif
void print_spaces(struct TimeInternal *ti)
{
static struct TimeInternal prev_ti;
int i, diffms;
if (prev_ti.seconds) {
diffms = (ti->seconds - prev_ti.seconds) * 1000
+ (ti->nanoseconds / 1000 / 1000)
- (prev_ti.nanoseconds / 1000 / 1000);
/* empty lines, one every .25 seconds, at most 10 of them */
for (i = 250; i < 2500 && i < diffms; i += 250)
printf("\n");
printf("TIMEDELTA: %i ms\n", diffms);
}
prev_ti = *ti;
}
int main(int argc, char **argv)
{
int sock;
int sock, ret;
struct packet_mreq req;
struct ifreq ifr;
char *ifname = "eth0";
......@@ -101,14 +120,19 @@ int main(int argc, char **argv)
continue;
if (ip->protocol != IPPROTO_UDP)
continue;
dump_udppkt(buf, len, &ti);
print_spaces(&ti);
ret = dump_udppkt(buf, len, &ti);
break;
case ETH_P_1588:
dump_1588pkt(buf, len, &ti);
print_spaces(&ti);
ret = dump_1588pkt(buf, len, &ti);
break;
default:
ret = -1;
continue;
}
if (ret == 0)
putchar('\n');
fflush(stdout);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment