net: shell: conn: Dump local/remote ports for contexts.
Without port numbers, information printed by net shell's "conn" command is unclear and non-differentiating. Also, improve handling of unknown address families - don't abort early, still pring context address, iface address, etc. Example of "conn" output with these changes from echo_server sample: net> conn Context Iface Flags Local Remote [ 1] 0x001126e0 0x001121a0 6DU [::]:4242 [::]:0 [ 2] 0x00112738 0x001121a0 4DU 0.0.0.0:4242 0.0.0.0:0 [ 3] 0x00112790 0x001121a0 6ST [::]:4242 [::]:0 [ 4] 0x001127e8 0x001121a0 4ST 0.0.0.0:4242 0.0.0.0:0 TCP Src port Dst port Send-Seq Send-Ack MSS State 0x00112b00 4242 0 497073352 0 1280 0x00112b98 4242 0 497543793 0 1460 Change-Id: I2f03efd933979b5571f608c28a7a7a4bd7f5346a Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
parent
99a7168b08
commit
52e3e5c68d
1 changed files with 18 additions and 16 deletions
|
@ -423,37 +423,39 @@ static void context_cb(struct net_context *context, void *user_data)
|
|||
#endif
|
||||
|
||||
int *count = user_data;
|
||||
char addr_local[ADDR_LEN];
|
||||
char addr_remote[ADDR_LEN];
|
||||
/* +7 for []:port */
|
||||
char addr_local[ADDR_LEN + 7];
|
||||
char addr_remote[ADDR_LEN + 7] = "";
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
if (context->local.family == AF_INET6) {
|
||||
snprintk(addr_local, ADDR_LEN, "%s",
|
||||
snprintk(addr_local, sizeof(addr_local), "[%s]:%u",
|
||||
net_sprint_ipv6_addr(
|
||||
net_sin6_ptr(&context->local)->sin6_addr));
|
||||
snprintk(addr_remote, ADDR_LEN, "%s",
|
||||
net_sin6_ptr(&context->local)->sin6_addr),
|
||||
ntohs(net_sin6_ptr(&context->local)->sin6_port));
|
||||
snprintk(addr_remote, sizeof(addr_remote), "[%s]:%u",
|
||||
net_sprint_ipv6_addr(
|
||||
&net_sin6(&context->remote)->sin6_addr));
|
||||
&net_sin6(&context->remote)->sin6_addr),
|
||||
ntohs(net_sin6(&context->remote)->sin6_port));
|
||||
} else
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
if (context->local.family == AF_INET) {
|
||||
snprintk(addr_local, ADDR_LEN, "%s",
|
||||
snprintk(addr_local, sizeof(addr_local), "%s:%d",
|
||||
net_sprint_ipv4_addr(
|
||||
net_sin_ptr(&context->local)->sin_addr));
|
||||
snprintk(addr_remote, ADDR_LEN, "%s",
|
||||
net_sin_ptr(&context->local)->sin_addr),
|
||||
ntohs(net_sin_ptr(&context->local)->sin_port));
|
||||
snprintk(addr_remote, sizeof(addr_remote), "%s:%d",
|
||||
net_sprint_ipv4_addr(
|
||||
&net_sin(&context->remote)->sin_addr));
|
||||
&net_sin(&context->remote)->sin_addr),
|
||||
ntohs(net_sin(&context->remote)->sin_port));
|
||||
} else
|
||||
#endif
|
||||
if (context->local.family == AF_UNSPEC) {
|
||||
printk("Network address family not set for context %p\n",
|
||||
context);
|
||||
return;
|
||||
snprintk(addr_local, sizeof(addr_local), "AF_UNSPEC");
|
||||
} else {
|
||||
printk("Invalid address family (%d) for context %p\n",
|
||||
context->local.family, context);
|
||||
return;
|
||||
snprintk(addr_local, sizeof(addr_local), "AF_UNK(%d)",
|
||||
context->local.family);
|
||||
}
|
||||
|
||||
printk("[%2d] %p\t%p %c%c%c %16s\t%16s\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue