@@ -23,9 +23,6 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
23
23
#define NET_LOG_ENABLED 1
24
24
#include "net_private.h"
25
25
26
- static struct sockaddr_in6 * in6_addr_my ;
27
- static struct sockaddr_in * in4_addr_my ;
28
-
29
26
#if defined(CONFIG_NET_TC_THREAD_COOPERATIVE )
30
27
#define TCP_RECEIVER_THREAD_PRIORITY K_PRIO_COOP(8)
31
28
#else
@@ -114,9 +111,7 @@ static void tcp_server_session(void)
114
111
}
115
112
116
113
if (IS_ENABLED (CONFIG_NET_IPV4 )) {
117
- const struct in_addr * in4_addr = NULL ;
118
-
119
- in4_addr_my = zperf_get_sin ();
114
+ struct sockaddr_in * in4_addr = zperf_get_sin ();
120
115
121
116
fds [SOCK_ID_IPV4_LISTEN ].fd = zsock_socket (AF_INET , SOCK_STREAM ,
122
117
IPPROTO_TCP );
@@ -128,34 +123,35 @@ static void tcp_server_session(void)
128
123
if (MY_IP4ADDR && strlen (MY_IP4ADDR )) {
129
124
/* Use Setting IP */
130
125
ret = zperf_get_ipv4_addr (MY_IP4ADDR ,
131
- & in4_addr_my -> sin_addr );
126
+ & in4_addr -> sin_addr );
132
127
if (ret < 0 ) {
133
128
NET_WARN ("Unable to set IPv4" );
134
129
goto use_existing_ipv4 ;
135
130
}
136
131
} else {
137
132
use_existing_ipv4 :
138
133
/* Use existing IP */
139
- in4_addr = zperf_get_default_if_in4_addr ();
140
- if (!in4_addr ) {
141
- NET_ERR ("Unable to get IPv4 by default" );
134
+ const struct in_addr * addr =
135
+ zperf_get_default_if_in4_addr ();
136
+ if (!addr ) {
137
+ NET_ERR ("Unable to get IPv4 by default\n" );
142
138
goto error ;
143
139
}
144
- memcpy (& in4_addr_my -> sin_addr , in4_addr ,
140
+ memcpy (& in4_addr -> sin_addr , addr ,
145
141
sizeof (struct in_addr ));
146
142
}
147
143
148
- in4_addr_my -> sin_port = htons (tcp_server_port );
144
+ in4_addr -> sin_port = htons (tcp_server_port );
149
145
150
146
NET_INFO ("Binding to %s" ,
151
- net_sprint_ipv4_addr (& in4_addr_my -> sin_addr ));
147
+ net_sprint_ipv4_addr (& in4_addr -> sin_addr ));
152
148
153
149
ret = zsock_bind (fds [SOCK_ID_IPV4_LISTEN ].fd ,
154
- (struct sockaddr * )in4_addr_my ,
150
+ (struct sockaddr * )in4_addr ,
155
151
sizeof (struct sockaddr_in ));
156
152
if (ret < 0 ) {
157
153
NET_ERR ("Cannot bind IPv4 TCP port %d (%d)" ,
158
- ntohs (in4_addr_my -> sin_port ), errno );
154
+ ntohs (in4_addr -> sin_port ), errno );
159
155
goto error ;
160
156
}
161
157
@@ -169,9 +165,7 @@ static void tcp_server_session(void)
169
165
}
170
166
171
167
if (IS_ENABLED (CONFIG_NET_IPV6 )) {
172
- const struct in6_addr * in6_addr = NULL ;
173
-
174
- in6_addr_my = zperf_get_sin6 ();
168
+ struct sockaddr_in6 * in6_addr = zperf_get_sin6 ();
175
169
176
170
fds [SOCK_ID_IPV6_LISTEN ].fd = zsock_socket (AF_INET6 , SOCK_STREAM ,
177
171
IPPROTO_TCP );
@@ -184,34 +178,35 @@ static void tcp_server_session(void)
184
178
/* Use Setting IP */
185
179
ret = zperf_get_ipv6_addr (MY_IP6ADDR ,
186
180
MY_PREFIX_LEN_STR ,
187
- & in6_addr_my -> sin6_addr );
181
+ & in6_addr -> sin6_addr );
188
182
if (ret < 0 ) {
189
183
NET_WARN ("Unable to set IPv6" );
190
184
goto use_existing_ipv6 ;
191
185
}
192
186
} else {
193
187
use_existing_ipv6 :
194
188
/* Use existing IP */
195
- in6_addr = zperf_get_default_if_in6_addr ();
196
- if (!in6_addr ) {
197
- NET_ERR ("Unable to get IPv4 by default" );
189
+ const struct in6_addr * addr =
190
+ zperf_get_default_if_in6_addr ();
191
+ if (!addr ) {
192
+ NET_ERR ("Unable to get IPv6 by default\n" );
198
193
goto error ;
199
194
}
200
- memcpy (& in6_addr_my -> sin6_addr , in6_addr ,
195
+ memcpy (& in6_addr -> sin6_addr , addr ,
201
196
sizeof (struct in6_addr ));
202
197
}
203
198
204
- in6_addr_my -> sin6_port = htons (tcp_server_port );
199
+ in6_addr -> sin6_port = htons (tcp_server_port );
205
200
206
201
NET_INFO ("Binding to %s" ,
207
- net_sprint_ipv6_addr (& in6_addr_my -> sin6_addr ));
202
+ net_sprint_ipv6_addr (& in6_addr -> sin6_addr ));
208
203
209
204
ret = zsock_bind (fds [SOCK_ID_IPV6_LISTEN ].fd ,
210
- (struct sockaddr * )in6_addr_my ,
205
+ (struct sockaddr * )in6_addr ,
211
206
sizeof (struct sockaddr_in6 ));
212
207
if (ret < 0 ) {
213
208
NET_ERR ("Cannot bind IPv6 TCP port %d (%d)" ,
214
- ntohs (in6_addr_my -> sin6_port ), errno );
209
+ ntohs (in6_addr -> sin6_port ), errno );
215
210
goto error ;
216
211
}
217
212
0 commit comments