@@ -143,61 +143,41 @@ udp_find_raddr_device(FAR struct udp_conn_s *conn,
143
143
{
144
144
in_addr_t raddr ;
145
145
146
- if (remote )
147
- {
148
- FAR const struct sockaddr_in * inaddr =
149
- (FAR const struct sockaddr_in * )remote ;
150
- net_ipv4addr_copy (raddr , inaddr -> sin_addr .s_addr );
151
- }
152
- else
146
+ if (conn -> u .ipv4 .laddr != INADDR_ANY )
153
147
{
154
- net_ipv4addr_copy (raddr , conn -> u .ipv4 .raddr );
155
- }
148
+ /* If the socket is bound to some non-zero, local address.
149
+ * Normal lookup using the verified local address.
150
+ */
156
151
157
- /* Check if the remote, destination address is the broadcast
158
- * or multicast address. If this is the case, select the device
159
- * using the locally bound address (assuming that there is one).
160
- */
152
+ return netdev_findby_lipv4addr (conn -> u .ipv4 .laddr );
153
+ }
161
154
162
- if (raddr == INADDR_BROADCAST || IN_MULTICAST (NTOHL (raddr )))
155
+ #ifdef CONFIG_NET_BINDTODEVICE
156
+ if (conn -> sconn .s_boundto != 0 )
163
157
{
164
- /* Make sure that the socket is bound to some non-zero, local
165
- * address. Zero is used as an indication that the laddr is
166
- * uninitialized and that the socket is, hence, not bound .
158
+ /* If the socket is bound to a local network device.
159
+ * Select the network device that has been bound.
160
+ * If the index is invalid, return NULL .
167
161
*/
168
162
169
- if (conn -> u .ipv4 .laddr == 0 ) /* INADDR_ANY */
170
- {
171
- /* Return the device bound to this UDP socket, if any */
172
-
173
- return net_bound_device (& conn -> sconn );
174
- }
175
- else
176
- {
177
- return netdev_findby_ripv4addr (conn -> u .ipv4 .laddr ,
178
- conn -> u .ipv4 .laddr );
179
- }
163
+ return netdev_findbyindex (conn -> sconn .s_boundto );
180
164
}
165
+ #endif
181
166
182
- /* There is no unique device associated with the unspecified
183
- * address.
184
- */
185
-
186
- else if (raddr != INADDR_ANY )
167
+ if (remote )
187
168
{
188
- /* Normal lookup using the verified remote address */
189
-
190
- return netdev_findby_ripv4addr (conn -> u .ipv4 .laddr ,
191
- raddr );
169
+ FAR const struct sockaddr_in * inaddr =
170
+ (FAR const struct sockaddr_in * )remote ;
171
+ net_ipv4addr_copy (raddr , inaddr -> sin_addr .s_addr );
192
172
}
193
173
else
194
174
{
195
- /* Not a suitable IPv4 unicast address for device lookup.
196
- * Return the device bound to this UDP socket, if any.
197
- */
198
-
199
- return net_bound_device (& conn -> sconn );
175
+ net_ipv4addr_copy (raddr , conn -> u .ipv4 .raddr );
200
176
}
177
+
178
+ /* Normal lookup using the verified remote address */
179
+
180
+ return netdev_findby_ripv4addr (conn -> u .ipv4 .laddr , raddr );
201
181
}
202
182
#endif
203
183
@@ -208,62 +188,41 @@ udp_find_raddr_device(FAR struct udp_conn_s *conn,
208
188
{
209
189
net_ipv6addr_t raddr ;
210
190
211
- if (remote )
212
- {
213
- FAR const struct sockaddr_in6 * inaddr =
214
- (FAR const struct sockaddr_in6 * )remote ;
215
- net_ipv6addr_copy (raddr , inaddr -> sin6_addr .s6_addr16 );
216
- }
217
- else
191
+ if (!net_ipv6addr_cmp (conn -> u .ipv6 .laddr , g_ipv6_unspecaddr ))
218
192
{
219
- net_ipv6addr_copy (raddr , conn -> u .ipv6 .raddr );
220
- }
193
+ /* If the socket is bound to some non-zero, local address.
194
+ * Normal lookup using the verified local address.
195
+ */
221
196
222
- /* Check if the remote, destination address is a multicast
223
- * address. If this is the case, select the device
224
- * using the locally bound address (assuming that there is one).
225
- */
197
+ return netdev_findby_lipv6addr (conn -> u .ipv6 .laddr );
198
+ }
226
199
227
- if (net_is_addr_mcast (raddr ))
200
+ #ifdef CONFIG_NET_BINDTODEVICE
201
+ if (conn -> sconn .s_boundto != 0 )
228
202
{
229
- /* Make sure that the socket is bound to some non-zero, local
230
- * address. The IPv6 unspecified address is used as an
231
- * indication that the laddr is uninitialized and that the
232
- * socket is, hence, not bound.
203
+ /* If the socket is bound to a local network device.
204
+ * Select the network device that has been bound.
205
+ * If the index is invalid, return NULL.
233
206
*/
234
207
235
- if (net_ipv6addr_cmp (conn -> u .ipv6 .laddr , g_ipv6_unspecaddr ))
236
- {
237
- /* Return the device bound to this UDP socket, if any */
238
-
239
- return net_bound_device (& conn -> sconn );
240
- }
241
- else
242
- {
243
- return netdev_findby_ripv6addr (conn -> u .ipv6 .laddr ,
244
- conn -> u .ipv6 .laddr );
245
- }
208
+ return netdev_findbyindex (conn -> sconn .s_boundto );
246
209
}
210
+ #endif
247
211
248
- /* There is no unique device associated with the unspecified
249
- * address.
250
- */
251
-
252
- else if (!net_ipv6addr_cmp (raddr , g_ipv6_unspecaddr ))
212
+ if (remote )
253
213
{
254
- /* Normal lookup using the verified remote address */
255
-
256
- return netdev_findby_ripv6addr (conn -> u .ipv6 .laddr ,
257
- raddr );
214
+ FAR const struct sockaddr_in6 * inaddr =
215
+ (FAR const struct sockaddr_in6 * )remote ;
216
+ net_ipv6addr_copy (raddr , inaddr -> sin6_addr .s6_addr16 );
258
217
}
259
218
else
260
219
{
261
- /* Not a suitable IPv6 unicast address for device lookup.
262
- * Return the device bound to this UDP socket, if any.
263
- */
264
-
265
- return net_bound_device (& conn -> sconn );
220
+ net_ipv6addr_copy (raddr , conn -> u .ipv6 .raddr );
266
221
}
222
+
223
+ /* Normal lookup using the verified remote address */
224
+
225
+ return netdev_findby_ripv6addr (conn -> u .ipv6 .laddr , raddr );
267
226
}
268
227
#endif
269
228
}
0 commit comments