net.c: fix printing AF_BLUETOOTH socket addresses

* xlat/hci_channels.in: New file.
* net.c (print_sockaddr_data_raw): New function.
(print_sockaddr): Use it.
[HAVE_BLUETOOTH_BLUETOOTH_H]: Include "xlat/hci_channels.h".
[HAVE_BLUETOOTH_BLUETOOTH_H] (print_sockaddr_data_bt): Fix printing
sockaddr_hci, sockaddr_sco, sockaddr_rc, and sockaddr_l2 structures.
This commit is contained in:
Дмитрий Левин 2016-06-23 21:06:54 +00:00
parent 102c8ca79e
commit 324f68d439
2 changed files with 60 additions and 28 deletions

83
net.c
View File

@ -96,6 +96,7 @@
#if defined(HAVE_BLUETOOTH_BLUETOOTH_H) #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
# include "xlat/bt_protocols.h" # include "xlat/bt_protocols.h"
# include "xlat/hci_channels.h"
#endif #endif
#include "xlat/msg_flags.h" #include "xlat/msg_flags.h"
@ -217,33 +218,63 @@ print_sockaddr_data_ll(const void *const buf, const int addrlen)
tprintf("%02x", sa_ll->sll_addr[i]); tprintf("%02x", sa_ll->sll_addr[i]);
} }
static void
print_sockaddr_data_raw(const void *const buf, const int addrlen)
{
const char *const data = buf + SIZEOF_SA_FAMILY;
const int datalen = addrlen - SIZEOF_SA_FAMILY;
tprints("sa_data=");
print_quoted_string(data, datalen, 0);
}
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
static void static void
print_sockaddr_data_bt(const void *const buf, const int addrlen) print_sockaddr_data_bt(const void *const buf, const int addrlen)
{ {
const union { switch (addrlen) {
struct sockaddr_hci hci; case sizeof(struct sockaddr_hci): {
struct sockaddr_l2 l2; const struct sockaddr_hci *const hci = buf;
struct sockaddr_rc rc; tprintf("hci_dev=htobs(%hu), hci_channel=",
struct sockaddr_sco sco; btohs(hci->hci_dev));
} *const addr = buf; printxval(hci_channels, hci->hci_channel,
"HCI_CHANNEL_???");
tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or " break;
"{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or " }
"{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or " case sizeof(struct sockaddr_sco): {
"{hci_dev=htobs(%d)}", const struct sockaddr_sco *const sco = buf;
addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1], tprintf("sco_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x",
addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3], sco->sco_bdaddr.b[0], sco->sco_bdaddr.b[1],
addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5], sco->sco_bdaddr.b[2], sco->sco_bdaddr.b[3],
addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1], sco->sco_bdaddr.b[4], sco->sco_bdaddr.b[5]);
addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3], break;
addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5], }
addr->rc.rc_channel, case sizeof(struct sockaddr_rc): {
btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0], const struct sockaddr_rc *const rc = buf;
addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2], tprintf("rc_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4], ", rc_channel=%u",
addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid), rc->rc_bdaddr.b[0], rc->rc_bdaddr.b[1],
btohs(addr->hci.hci_dev)); rc->rc_bdaddr.b[2], rc->rc_bdaddr.b[3],
rc->rc_bdaddr.b[4], rc->rc_bdaddr.b[5],
rc->rc_channel);
break;
}
case sizeof(struct sockaddr_l2): {
const struct sockaddr_l2 *const l2 = buf;
tprintf("l2_psm=htobs(%hu)"
", l2_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
", l2_cid=htobs(%hu), l2_bdaddr_type=%u",
btohs(l2->l2_psm),
l2->l2_bdaddr.b[0], l2->l2_bdaddr.b[1],
l2->l2_bdaddr.b[2], l2->l2_bdaddr.b[3],
l2->l2_bdaddr.b[4], l2->l2_bdaddr.b[5],
btohs(l2->l2_cid), l2->l2_bdaddr_type);
break;
}
default:
print_sockaddr_data_raw(buf, addrlen);
break;
}
} }
#endif /* HAVE_BLUETOOTH_BLUETOOTH_H */ #endif /* HAVE_BLUETOOTH_BLUETOOTH_H */
@ -276,11 +307,7 @@ print_sockaddr(struct tcb *tcp, const void *const buf, const int addrlen)
&& sa_printers[sa->sa_family]) { && sa_printers[sa->sa_family]) {
sa_printers[sa->sa_family](buf, addrlen); sa_printers[sa->sa_family](buf, addrlen);
} else { } else {
const char *const data = buf + sizeof(sa->sa_family); print_sockaddr_data_raw(buf, addrlen);
const int datalen = addrlen - sizeof(sa->sa_family);
tprints("sa_data=");
print_quoted_string(data, datalen, 0);
} }
} }

5
xlat/hci_channels.in Normal file
View File

@ -0,0 +1,5 @@
HCI_CHANNEL_RAW
HCI_CHANNEL_USER
HCI_CHANNEL_MONITOR
HCI_CHANNEL_CONTROL
HCI_CHANNEL_LOGGING