mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 15:41:54 +00:00
Socktest: Minor change in code style
Move printing out received packet into own function
This commit is contained in:
parent
2bd35b0609
commit
a6e111ae54
@ -1,11 +1,48 @@
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
/*
|
||||
* Print out:
|
||||
* <src>:<port> -> <dst> ifa(<id>) <name>: pkt <value>/<count>, ttl <ttl>
|
||||
*/
|
||||
static void
|
||||
rcv_print(sock *sk, struct my_packet *pkt)
|
||||
{
|
||||
char ifa_name[IF_NAMESIZE];
|
||||
char buf[1024];
|
||||
char *pos;
|
||||
int unused_size;
|
||||
|
||||
if (!if_indextoname(sk->lifindex, ifa_name))
|
||||
{
|
||||
perror("if_indextoname");
|
||||
snprintf(ifa_name, sizeof(ifa_name), "???");
|
||||
}
|
||||
|
||||
bsnprintf(buf, sizeof(buf), "%I", sk->faddr);
|
||||
pos = buf + strlen(buf);
|
||||
unused_size = sizeof(buf) - (pos - buf);
|
||||
|
||||
if (sk->type != SK_IP)
|
||||
bsnprintf(pos, unused_size, ":%u", sk->fport);
|
||||
pos = buf + strlen(buf);
|
||||
unused_size = sizeof(buf) - (pos - buf);
|
||||
|
||||
bsnprintf(pos, unused_size, " -> %I ifa(%u) %s: ", sk->laddr, sk->lifindex, ifa_name);
|
||||
pos = buf + strlen(buf);
|
||||
unused_size = sizeof(buf) - (pos - buf);
|
||||
|
||||
if (pkt->magic == (u32)PKT_MAGIC)
|
||||
bsnprintf(pos, unused_size, "pkt %d/%d, ttl %d", pkt->value, pkt->count, sk->rcv_ttl);
|
||||
else
|
||||
bsnprintf(pos, unused_size, "magic value does not pass: recv %u, expected %u", pkt->magic, (u32)PKT_MAGIC);
|
||||
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
|
||||
static int
|
||||
rcv_hook(sock *sk, int size)
|
||||
{
|
||||
struct my_packet *raw;
|
||||
char ifa_name[IF_NAMESIZE];
|
||||
char buf[1024];
|
||||
|
||||
if (cf_count && ++counter > cf_count)
|
||||
exit(0);
|
||||
@ -27,20 +64,7 @@ rcv_hook(sock *sk, int size)
|
||||
.count = ntohl(raw->count),
|
||||
};
|
||||
|
||||
if (!if_indextoname(sk->lifindex, ifa_name))
|
||||
{
|
||||
perror("if_indextoname");
|
||||
snprintf(ifa_name, sizeof(ifa_name), "???");
|
||||
}
|
||||
|
||||
bsnprintf(buf, sizeof(buf), "%I:%u -> %I ifa(%u) %s: ", sk->faddr, sk->fport, sk->laddr, sk->lifindex, ifa_name);
|
||||
char *pos = buf + strlen(buf);
|
||||
if (pkt.magic == (u32)PKT_MAGIC)
|
||||
bsnprintf(pos, pos-buf, "pkt %d/%d, ttl %d", pkt.value, pkt.count, sk->rcv_ttl);
|
||||
else
|
||||
bsnprintf(pos, pos-buf, "magic value does not pass: recv %u, expected %u", pkt.magic, (u32)PKT_MAGIC);
|
||||
|
||||
printf("%s\n", buf);
|
||||
rcv_print(sk, &pkt);
|
||||
|
||||
/* Clear receive buffer */
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user