samples: net: zperf: Allow DHCPv4 or manually set addresses
If user has enabled DHCPv4, then allow to use its address instead of giving error if static address cannot be set. Similar fix for IPv6, so allow user to manually set an IPv6 address. Because DHCPv4 has already set the IPv4 address to the network interface, then zperf might not be able to add the pre-configured address to it. So instead of returning immediately, try to use the IP address that is already in the network interface. This way we avoid this error print. uart:~$ zperf udp download 5001 Setting IP address 2001:db8::1 Setting destination IP address 2001:db8::2 Cannot set IPv4 address 192.0.2.1 Unable to set IP Setting destination IP address 192.0.2.2 Cannot set IPv4 address 192.0.2.1 Unable to set IPv4 Binding to 192.0.2.1 Cannot bind IPv4 UDP port 5001 (-2) In this example, the network interface already had a proper and working IPv4 address 192.168.0.2 in it. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
77a74414d1
commit
9028ecbc56
2 changed files with 8 additions and 4 deletions
|
@ -178,9 +178,10 @@ void zperf_tcp_receiver_init(const struct shell *shell, int port)
|
|||
if (ret < 0) {
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Unable to set IPv4\n");
|
||||
return;
|
||||
goto use_existing_ipv4;
|
||||
}
|
||||
} else {
|
||||
use_existing_ipv4:
|
||||
/* Use existing IP */
|
||||
in4_addr = zperf_get_default_if_in4_addr();
|
||||
if (!in4_addr) {
|
||||
|
@ -215,9 +216,10 @@ void zperf_tcp_receiver_init(const struct shell *shell, int port)
|
|||
if (ret < 0) {
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Unable to set IPv6\n");
|
||||
return;
|
||||
goto use_existing_ipv6;
|
||||
}
|
||||
} else {
|
||||
use_existing_ipv6:
|
||||
/* Use existing IP */
|
||||
in6_addr = zperf_get_default_if_in6_addr();
|
||||
if (!in6_addr) {
|
||||
|
|
|
@ -319,9 +319,10 @@ void zperf_udp_receiver_init(const struct shell *shell, int port)
|
|||
if (ret < 0) {
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Unable to set IPv4\n");
|
||||
return;
|
||||
goto use_existing_ipv4;
|
||||
}
|
||||
} else {
|
||||
use_existing_ipv4:
|
||||
/* Use existing IP */
|
||||
in4_addr = zperf_get_default_if_in4_addr();
|
||||
if (!in4_addr) {
|
||||
|
@ -369,9 +370,10 @@ void zperf_udp_receiver_init(const struct shell *shell, int port)
|
|||
if (ret < 0) {
|
||||
shell_fprintf(shell, SHELL_WARNING,
|
||||
"Unable to set IPv6\n");
|
||||
return;
|
||||
goto use_existing_ipv6;
|
||||
}
|
||||
} else {
|
||||
use_existing_ipv6:
|
||||
/* Use existing IP */
|
||||
in6_addr = zperf_get_default_if_in6_addr();
|
||||
if (!in6_addr) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue