Dump packets
This commit is contained in:
parent
fc9ec0e213
commit
6034def186
2 changed files with 42 additions and 0 deletions
39
src/packet.c
39
src/packet.c
|
@ -39,6 +39,7 @@ enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp) {
|
|||
enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp) {
|
||||
ssize_t nwrite;
|
||||
|
||||
dump_buffer_packet (bp);
|
||||
if (bp->mode != BP_WRITING) return FDS_ERR;
|
||||
while (bp->awrite < get_full_size(bp)) {
|
||||
nwrite = send(fd, &(bp->ip.ap.raw) + bp->awrite, get_full_size(bp) - bp->awrite, 0);
|
||||
|
@ -126,3 +127,41 @@ enum FD_STATE read_packet_from_udp (int fd, struct buffer_packet* bp, struct udp
|
|||
return FDS_READY;
|
||||
}
|
||||
|
||||
void dump_buffer_packet(struct buffer_packet* bp) {
|
||||
printf("<Buffer Packet>\n");
|
||||
printf(" mode=%d, aread=%d, awrite=%d, ap_count=%d\n", bp->mode, bp->aread, bp->awrite, bp->ap_count);
|
||||
union abstract_packet* ap = &bp->ip.ap;
|
||||
for (int i = 0; i < bp->ap_count; i++) {
|
||||
dump_abstract_packet(ap);
|
||||
ap = (union abstract_packet*)(&ap->raw + ap->fmt.headers.size);
|
||||
}
|
||||
printf("</Buffer Packet>\n");
|
||||
}
|
||||
|
||||
void dump_abstract_packet(union abstract_packet* ap) {
|
||||
printf("<Abstract Packet>\n");
|
||||
printf(" size=%d, cmd=%d\n", ap->fmt.headers.size, ap->fmt.headers.cmd);
|
||||
switch (ap->fmt.headers.cmd) {
|
||||
case CMD_HEALTH:
|
||||
printf(" <Health>id=%d, deltat=%d, prevlink=%d, min_blocked_pkt=%d, bitfield=%08x</Health>\n",
|
||||
ap->fmt.content.health.id,
|
||||
ap->fmt.content.health.deltat,
|
||||
ap->fmt.content.health.prevlink,
|
||||
ap->fmt.content.health.min_blocked_pkt,
|
||||
ap->fmt.content.health.bitfield);
|
||||
break;
|
||||
case CMD_CLEAR:
|
||||
printf(" <Clear>id=%d, port=%d</Clear>\n",
|
||||
ap->fmt.content.clear.id,
|
||||
ap->fmt.content.clear.port);
|
||||
break;
|
||||
case CMD_XOR:
|
||||
printf(" <Xor>Unimplemented</Xor>\n");
|
||||
break;
|
||||
default:
|
||||
printf(" <Unknown/>");
|
||||
break;
|
||||
|
||||
}
|
||||
printf("</Abstract Packet>");
|
||||
}
|
||||
|
|
|
@ -84,3 +84,6 @@ enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp);
|
|||
enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp);
|
||||
enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct udp_target* udp_t);
|
||||
enum FD_STATE read_packet_from_udp (int fd, struct buffer_packet* bp, struct udp_target* udp_t);
|
||||
|
||||
void dump_buffer_packet(struct buffer_packet* bp);
|
||||
void dump_abstract_packet(union abstract_packet* ap);
|
||||
|
|
Loading…
Reference in a new issue