Skip to content

Commit 9c48a8d

Browse files
zhhyu7xiaoxiang781216
authored andcommitted
iperf: add parameters to support dynamic device bind
In addition to the CONFIG_NETUTILS_IPERFTEST_DEVNAME configuration, you can specify network cards by parameter to support devices with multiple network interface Signed-off-by: zhanghongyu <[email protected]>
1 parent e4e43a1 commit 9c48a8d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

netutils/iperf/iperf_main.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct wifi_iperf_t
5858
FAR struct arg_lit *udp;
5959
FAR struct arg_str *local;
6060
FAR struct arg_str *rpmsg;
61+
FAR struct arg_str *bind;
6162
FAR struct arg_int *port;
6263
FAR struct arg_int *interval;
6364
FAR struct arg_int *time;
@@ -148,6 +149,7 @@ int main(int argc, FAR char *argv[])
148149
iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP");
149150
iperf_args.local = arg_str0(NULL, "local", "<path>", "use local socket");
150151
iperf_args.rpmsg = arg_str0(NULL, "rpmsg", "<name>", "use RPMsg socket");
152+
iperf_args.bind = arg_str0("B", "bind", "<ip>", "ip to bind");
151153
iperf_args.port = arg_int0("p", "port", "<port>",
152154
"server port to listen on/connect to");
153155
iperf_args.interval = arg_int0("i", "interval", "<interval>",
@@ -222,11 +224,23 @@ int main(int argc, FAR char *argv[])
222224
}
223225
else
224226
{
225-
netlib_get_ipv4addr(DEVNAME, &addr);
226-
if (addr.s_addr == 0)
227+
if (iperf_args.bind->count > 0)
227228
{
228-
printf("ERROR: access IP is 0x00\n");
229-
goto out;
229+
addr.s_addr = inet_addr(iperf_args.bind->sval[0]);
230+
if (addr.s_addr == INADDR_NONE)
231+
{
232+
printf("ERROR: access IP is 0xffffffff\n");
233+
goto out;
234+
}
235+
}
236+
else
237+
{
238+
netlib_get_ipv4addr(DEVNAME, &addr);
239+
if (addr.s_addr == 0)
240+
{
241+
printf("ERROR: access IP is 0x00\n");
242+
goto out;
243+
}
230244
}
231245

232246
printf(" IP: %s\n", inet_ntoa_r(addr, inetaddr, sizeof(inetaddr)));

0 commit comments

Comments
 (0)