Slightly improve dumping packets

Add a function for dumping iovecs, and make hexdumps clearer by
adding spaces between bytes.

Bug: 8276725
Change-Id: Ifb2f8317613d05fa6bd600700090a6df258cde08
This commit is contained in:
Lorenzo Colitti 2013-04-08 18:30:55 +09:00
commit f913fe4927
2 changed files with 14 additions and 4 deletions

17
dump.c
View file

@ -216,15 +216,24 @@ void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, const char *
/* generic hex dump */
void logcat_hexdump(const char *info, const char *data, size_t len) {
char output[PACKETLEN*2+1];
char output[PACKETLEN*3+2];
size_t i;
for(i = 0; i < len && i < PACKETLEN; i++) {
snprintf(output + i*2, 3, "%02x", (uint8_t)data[i]);
snprintf(output + i*3, 4, " %02x", (uint8_t)data[i]);
}
output[len*2+2] = '\0';
output[len*3+3] = '\0';
logmsg(ANDROID_LOG_WARN,"info %s len %d data %s", info, len, output);
logmsg(ANDROID_LOG_WARN,"info %s len %d data%s", info, len, output);
}
void dump_iovec(const struct iovec *iov, int iov_len) {
int i;
char *str;
for (i = 0; i < iov_len; i++) {
asprintf(&str, "iov[%d]: ", i);
logcat_hexdump(str, iov[i].iov_base, iov[i].iov_len);
free(str);
}
}
#endif // CLAT_DEBUG

1
dump.h
View file

@ -29,5 +29,6 @@ void dump_udp6(const struct udphdr *udp, const struct ip6_hdr *ip6, const char *
void dump_tcp6(const struct tcphdr *tcp, const struct ip6_hdr *ip6, const char *payload, size_t payload_size, const char *options, size_t options_size);
void logcat_hexdump(const char *info, const char *data, size_t len);
void dump_iovec(const struct iovec *iov, int iov_len);
#endif /* __DUMP_H__ */