Skip to content

Commit 80a8930

Browse files
committed
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 <[email protected]>
1 parent 52c9785 commit 80a8930

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

samples/net/zperf/src/zperf_tcp_receiver.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ void zperf_tcp_receiver_init(const struct shell *shell, int port)
178178
if (ret < 0) {
179179
shell_fprintf(shell, SHELL_WARNING,
180180
"Unable to set IPv4\n");
181-
return;
181+
goto use_existing_ipv4;
182182
}
183183
} else {
184+
use_existing_ipv4:
184185
/* Use existing IP */
185186
in4_addr = zperf_get_default_if_in4_addr();
186187
if (!in4_addr) {
@@ -215,9 +216,10 @@ void zperf_tcp_receiver_init(const struct shell *shell, int port)
215216
if (ret < 0) {
216217
shell_fprintf(shell, SHELL_WARNING,
217218
"Unable to set IPv6\n");
218-
return;
219+
goto use_existing_ipv6;
219220
}
220221
} else {
222+
use_existing_ipv6:
221223
/* Use existing IP */
222224
in6_addr = zperf_get_default_if_in6_addr();
223225
if (!in6_addr) {

samples/net/zperf/src/zperf_udp_receiver.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,10 @@ void zperf_udp_receiver_init(const struct shell *shell, int port)
319319
if (ret < 0) {
320320
shell_fprintf(shell, SHELL_WARNING,
321321
"Unable to set IPv4\n");
322-
return;
322+
goto use_existing_ipv4;
323323
}
324324
} else {
325+
use_existing_ipv4:
325326
/* Use existing IP */
326327
in4_addr = zperf_get_default_if_in4_addr();
327328
if (!in4_addr) {
@@ -369,9 +370,10 @@ void zperf_udp_receiver_init(const struct shell *shell, int port)
369370
if (ret < 0) {
370371
shell_fprintf(shell, SHELL_WARNING,
371372
"Unable to set IPv6\n");
372-
return;
373+
goto use_existing_ipv6;
373374
}
374375
} else {
376+
use_existing_ipv6:
375377
/* Use existing IP */
376378
in6_addr = zperf_get_default_if_in6_addr();
377379
if (!in6_addr) {

0 commit comments

Comments
 (0)